Skip to content

chore: remove duplicate prettier.config.js settings from .eslintrc.json #5087

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

Conversation

DoctorDerek
Copy link
Contributor

✅ chore: remove duplicate prettier.config.js settings from .eslintrc.json
✅ manually tested with visual inspection in VS Code and by running npx eslint --fix . as a way of fixing Prettier errors

Good news everyone!

image

Turns out you can ask ESLint to read Prettier's configuration file, and the eslint-prettier plugin will process it correctly.

Unfortunately, it doesn't work right the other way -- VSCode's Prettier extension won't pull the settings out of the ESLint config.

The .editorconfig file is still needed for fixing line endings to LF on save on Windows and for specifying utf-8.

Still, "prettier/prettier": ["error"] is a lot cleaner in .eslintrc.json than the copy-paste that was in there before! 😁

@sachinraja
Copy link
Contributor

sachinraja commented Jul 27, 2021

Why not switch to only prettier (no eslint-plugin-prettier)? eslint-config-prettier will handle conflicting rules and you don't have to see red lines every time you type in your editor. This would require running prettier outside eslint though, which is easily done with lint-staged and/or the prettier extension for your editor. I believe this would also allow for the removal of .editorconfig.

@DoctorDerek
Copy link
Contributor Author

Hey @sachinraja thanks for your comment. Do you happen to develop on Windows? I'm not sure exactly what you mean, as this is the .eslintrc.json file that I see:

{
"env": {
"jest": true
},
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"extends": ["prettier"],
"plugins": ["prettier"],
"rules": {
"camelcase": ["error", { "allow": ["^unstable_"] }],
"no-unused-vars": [2, { "args": "all", "argsIgnorePattern": "^_" }],
"no-warning-comments": 0,
"prettier/prettier": "error"
}
}

The error I think you may be referring to -- Windows developers seeing errors on every line because of CRLF line endings -- happens because ESLint forces "LF" line endings according to the Prettier rule set, even on Windows, so there's no workaround. At least there isn't as long as the ESLint config file is set to "error" (or "warn") on "prettier/prettier."

Anyway, that conversation is pretty much completely off-topic for this PR (#5087); see PR #3760 for a discussion of the line-ending problems and rationale for a .gitattributes file. This PR #5087 is a simple chore: refactor that does not change any behaviors, it just removes the unnecessarily-duplicated code that I added in PR #3713.

Regarding EditorConfig

tl;dr .editorconfig seems redundant but it differs from Prettier in that:

  • EditorConfig specifies utf-8 (which is the VS Code default, but not the default for some other applications)
  • EditorConfig forces LF line endings on save of a CRLF file, while the Prettier extension for VS Code does not

You're right that .editorconfig specifies LF line endings (though Prettier does as well). It also specifies utf-8, which I believe is the one. As best as I can tell, people include .editorconfig because while using it, you can have Prettier-like behavior by using EditorConfig without actually using Prettier.

In my experience the only difference is that the Prettier VS Code extension will not force-save CRLF line ending files (pulled down from GitHub) using the specified LF line ending, but the EditorConfig VS Code extension will do so.

That means that when I'm working on Windows in a repository with both .editorconfig and prettier.config.js specifying LF endings, but without a .gitattributes file that requires LF endings locally, I can hit Save in VS Code and flip the line endings to the correct one.

Otherwise, the only way to fix the line endings in the file is to manually toggle them in VS Code or run npx eslint --fix . from the command line (or probably npx prettier --write ., though I've never tried that specifically for line endings).

@sachinraja
Copy link
Contributor

Sorry, I don't think I was clear in what I was suggesting. You can use prettier by itself (outside of eslint). I suggested doing this and automatically running prettier before commits. Since it would automatically run before commits, a .editorconfig file (or at least most of its options) would not be needed.

@DoctorDerek
Copy link
Contributor Author

DoctorDerek commented Jul 28, 2021 via email

@sachinraja
Copy link
Contributor

Are you suggesting to simply remove
the prettier/prettier rule from .eslintrc.json and then remove
.editorrconfig as well instead of accepting this PR?

Yes, that is exactly what I'm suggesting. I realize that it isn't the point of this PR, but it seems the most fitting place to have this discussion. Thanks for taking the time to work on proper formatting!

@DoctorDerek
Copy link
Contributor Author

DoctorDerek commented Jul 28, 2021 via email

@RobinMalfait RobinMalfait merged commit 36a02ed into tailwindlabs:master Sep 1, 2021
@RobinMalfait
Copy link
Member

Hey! Thank you for your PR!
Much appreciated! 🙏

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.

3 participants