-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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: update eslint config in React templates #13550
Conversation
Run & review this pull request in StackBlitz Codeflow. |
@nickmccurdy would you help us with a review here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the new ESLint config and existing TS config still work in monorepos?
'react-refresh/only-export-components': 'warn', | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs mention that Vite supports this option, but what if inside this Vite project are files run by another HMR implementation that doesn't support it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this complex setup is out of scope of a Vite template. I don't consider this config to be perfect for every use cases, just a good starting for people using Vite in place of CRA.
(Idem for monorepo stuff, we people have already their linting configure they can delete the file.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not saying this template should set up other tools, I'm saying it should avoid breaking other tools when we can't make assumptions about what they are. I think this is actually more important with a minimal template, as we don't include common tools like doc generators or test frameworks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nickmccurdy do you have a common example of vite + a tool that will break after adding this config? I agree with the idea you're pushing here, but I don't know if it would apply to this particular option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not aware of any specific counterexamples, sorry. Hopefully the docs for allowConstantExport
help:
Don't warn when a constant (string, number, boolean, templateLiteral) is exported aside one or more components.
This should be enabled if the fast refresh implementation correctly handles this case (HMR when the constant doesn't change, propagate update to importers when the constant changes.). Vite supports it, PR welcome if you notice other integrations works well.
Let's move forward to get more feedback from users. We can keep the discusion open. |
Sounds good! 👍 I'll still check these notifications. |
I just scaffolded a project and was a bit confused, by only two rules being overwritten, one of them turning of My opinion would be that a starter template should rely on the tools its using (i.e. |
We are in the process of upgrading our quickstart to the latest version of Vite and found that the addition of
I'd leave the addition of this ruleset to users who are TypeScript experts who want the additional type safety. |
@essenmitsosse I don't understand, the only rule turn off is |
@xixixao Thanks for the feedback, that's true that the cache issues with types in ESLint can be annoying. I wanted to promote a bit this kind of more advanced rules, but the usage of Vite templates is more wide than the start of a new app. I will revisit this to see how we can keep an eslint config for hooks without giving the impression that this is the right config for a team building a production application (I've seen to many teams sticking with the default rules of CRA that are lacking support for TS) |
@ArnaudBarre I am not arguing for cast TLDR; I was confused by this single rule being overwritten. Had to spend time figuring out why this (from my perspective) reasonable rule was turned off (and assumed it was because of some problem with React). Went ahead and turned it back on. |
@xixixao I see your point, but I was happy all the setup for ESLint with types was already done. Turning the rules off seems a lot simpler, in this case, than turning them on. It would be a pity to have it removed. |
@essenmitsosse good news v6 was just so I will update the template and remove this line while keeping the Yeah this is not trivial to setup, but the question is should it be the role of the default template to do so. I will discuss this with the team |
Closes #10772
I wanted to improve a bit the ling rules for the TS template, adding more type aware rules. The strict set is too strict for a starter, but I added manually my preferred one:
@typescript-eslint/no-unnecessary-condition
(catches so much dead branch when refactoring). Also added one to remove thisas
I wanted to remove since way to long (see #10772)Also discovered that
no-non-null-assertion
is enabled by default, which is bad IMO. I don't agree with the opinion of the TS-ESLint team. TS will never be a sound type system (can't find the issue/discussion from the core team that says it's out of scope). This tool is a sharp knife, but a useful one, we use ourself quite a lot in the Vite codebase. And the diff in the TS template clearly shows that this is a better assertion than aas
.