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

Linebreak errors on Windows #154

Open
dennisvang opened this issue Oct 30, 2024 · 0 comments · May be fixed by #156
Open

Linebreak errors on Windows #154

dennisvang opened this issue Oct 30, 2024 · 0 comments · May be fixed by #156

Comments

@dennisvang
Copy link

dennisvang commented Oct 30, 2024

problem

On a Windows dev machine with a default git-for-windows setup (autocrlf true), running e.g. npm run serve will show lots of linting errors like the following:

...
125:10  error  Expected linebreaks to be 'LF' but found 'CRLF'  linebreak-style

possible solutions

The ESLint docs suggest adding a rule to .gitattributes to enforce LF linebreaks:

For example, the default behavior of git on Windows systems is to convert LF linebreaks to CRLF when checking out files, but to store the linebreaks as LF when committing a change. This will cause the linebreak-style rule to report errors if configured with the "unix" setting, because the files that ESLint sees will have CRLF linebreaks. If you use git, you may want to add a line to your .gitattributes file to prevent git from converting linebreaks in .js files:

*.js text eol=lf

In our case we would also need to add *.ts and *.vue files, at least.

Instead of committing a .gitattributes file to the repo, this setting could also be specified in a .git/info/attributes file, so it only affects the local system.

In an existing clone of the repository, modifications to autocrlf or text will require a reset, as described e.g. here (make sure working dir is clean):

git rm -rf --cached .
git reset --hard HEAD

where -rf stands for recursive and forced

An alternative would be to add a rule to .eslintrc.js that sets the linebreak-style :

  • either based on platform:
    'linebreak-style': ['error', process.platform === 'win32' ? 'windows' : 'unix']
    Note this may "break" existing configurations where users have already configured git to checkout LF.
  • or based on an environment variable:
    'linebreak-style': ['error', process.env.ESLINT_LINEBREAK_WINDOWS ? 'windows' : 'unix']

Note that the eslint linebreak-style rule has been deprecated in favor of eslint stylistic:

This rule was deprecated in ESLint v8.53.0. Please use the corresponding rule in @stylistic/eslint-plugin-js.

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