Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add default .gitattributes #828

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

scscgit
Copy link
Contributor

@scscgit scscgit commented Jul 17, 2021

I'd like to discuss feasibility of adding a default .gitattributes file that enforces a more consistent behavior with EOL=LF including the scenario of checking out the project. I haven't fully tested this, so please share your experience. To share any consequences and observe the expected impact on existing projects, I suggest making the same change to the file in a project root, which is already here (unlike many other projects) but lacks eol=lf.

If there is some reason against using .gitattributes in most Nuxt projects, it'll be beneficial to at least provide this information to the developers who would otherwise try to configure it on their own.

Git context

Git provides a global configuration of core.autocrlf, which is by default "false" if not defined, but in Windows installer it's pre-selected as true by default. Value of "false" means no processing on line endings, "true" means checking in as LF and checking out according to system (CRLF on Windows and LF on Unix) [StackOverflow]. (Other related configuration is core.safecrlf.)

In practice this means that with a value of "true", developers may experience their project being checked out as CRLF, which will naturally conflict with prettier and they'll have to reformat everything. This increases the learning curve of any onboarding, and especially they are new to Nuxt, this means they'll first have to extensively research the theory behind EOL, Git, and also prettier along with its lintfix script before they can even safely make a first commit.

.gitattributes values

Using text=auto is supposed to make a detection of supported text files automatic, so that any binary files (like .jpg, .png) are excluded from the conversion of line endings to LF, otherwise there can be file corruptions (which have been reported). The alternative would be to explicitly list the extensions of all source files, which is another viable solution where create-nuxt-app could maintain an extensive list of usual types used by any front-end developers; but we'd have to specify whether the "default type" will be binary or text.

https://stackoverflow.com/questions/29435156/what-will-text-auto-eol-lf-in-gitattributes-do

The suggested * text=auto eol=lf value requires Git 2.10+ to function correctly.

The choice of enforcing LF by default for all Vue-related source files is supposed to be opinionated and thus agreed upon by Nuxt to keep it sane, yet anyone will be free to remove the file from their repository.

I assume that this configuration will make it easier to remove workarounds where we replace \r\n by \n in code, for example like:


which may include files like shell/batch scripts that are run by Docker, etc.

@clarkdo clarkdo requested review from a team and clarkdo and removed request for a team and clarkdo July 17, 2021 19:15
@clarkdo clarkdo requested review from a team and pi0 and removed request for a team July 17, 2021 20:03
@scscgit
Copy link
Contributor Author

scscgit commented Jul 28, 2021

I also just found out that prettier's documentation https://prettier.io/docs/en/options.html#end-of-line explicitly recommends the same setup: "Add * text=auto eol=lf to the repo’s .gitattributes file."

+ for example, Vuetify uses it: https://github.com/vuetifyjs/vuetify/blob/master/.gitattributes

@scscgit
Copy link
Contributor Author

scscgit commented Apr 3, 2023

Note that .gitattributes is also missing in case of Nuxt 3's nuxi init (#1023), where the same reasoning applies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants