Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin): [naming-convention] add support for default and namespace imports#7269
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
feat(eslint-plugin): [naming-convention] add support for default and namespace imports#7269
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for the PR,@binoche9! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently onhttps://opencollective.com/typescript-eslint. |
netlifybot commentedJul 19, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify site configuration. |
nx-cloudbot commentedJul 19, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
Let me know if there's any other place I should be making changes.
I'm also not sure if this counts as a breaking change since for people who have a default style it may break for them since imports that previously weren't matched will start getting the default style enforced.
// other | ||
import = 1 << 18, |
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 decided it didn't belong to any selector group (I guessvariableLike
comes closest) but feel free to disagree
modifiers.add(Modifiers.namespace); | ||
break; | ||
case AST_NODE_TYPES.ImportSpecifier: | ||
// Handle `import { default as Foo }` |
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 decidedimport { default as Foo }
counts as a default import, but feel free to disagree
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.
Generally looks great to me, thanks for sending in! 🙌
Just requesting changes on splitting the tests up. It all strikes me as reasonable otherwise though.
cc@bradzacher / will defer to you since you'd interacted with the feature request in#2106.
packages/eslint-plugin/tests/rules/naming-convention/naming-convention.test.tsShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
2e8df6e
tobc92533
Comparecodecovbot commentedAug 8, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@## main #7269 +/- ##==========================================+ Coverage 87.41% 87.42% +0.01%========================================== Files 381 381 Lines 13321 13332 +11 Branches 3938 3940 +2 ==========================================+ Hits 11645 11656 +11 Misses 1298 1298 Partials 378 378
Flags with carried forward coverage won't be shown.Click here to find out more.
|
I split up the tests as requested 👍 |
Friendly bump 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.
Sorry for the delay! I just re-reviewed and it looks great. Thanks again for sending!
karlhorky commentedOct 24, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Just upgraded to
With this code: importReactfrom'react'; This is usingthe default rule configuration mentioned in the docs: // the default config is similar to ESLint's camelcase rule but more strictconstdefaultOptions:Options=[{selector:'default',format:['camelCase'],leadingUnderscore:'allow',trailingUnderscore:'allow',},{selector:'variable',format:['camelCase','UPPER_CASE'],leadingUnderscore:'allow',trailingUnderscore:'allow',},{selector:'typeLike',format:['PascalCase'],},]; I guess this is going to be a pretty common pattern that gets rejected now. 😬 Maybe the default configuration should accept every format as an import? ( Alternative: expect all users with default // the default config is similar to ESLint's camelcase rule but more strictconst defaultOptions: Options = [ // ...+ // Disable @typescript-eslint/naming-convention format for imports+ // https://github.com/typescript-eslint/typescript-eslint/pull/7269#issuecomment-1777628591+ {+ selector: 'import',+ format: null,+ },]; |
Hm good point@binoche9. Could I ask you to file a new issue for this please, for tracking and attribution? |
PR Checklist
Overview
Currently the
naming-convention
rule cannot be used to enforce conventions on default and namespace imports. This PR introduces that capability by introducing animport
selector anddefault
andnamespace
modifiers.Named imports are not checked since they have to match the name from the imported file.