-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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(eslint-plugin): [naming-convention] add support for default and namespace imports #7269
feat(eslint-plugin): [naming-convention] add support for default and namespace imports #7269
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 on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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 guess variableLike
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 decided import { 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.ts
Show resolved
Hide resolved
2e8df6e
to
bc92533
Compare
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!
Just upgraded to
With this code: import React from 'react'; This is using the default rule configuration mentioned in the docs: // the default config is similar to ESLint's camelcase rule but more strict
const defaultOptions: 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 strict
const 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.