-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[naming-convention] Add the ability to lint imports #2106
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
Comments
This definitely seems reasonable to check all imports. I think the following would be good as a new selector: |
I don't think it's a good idea to check default imports, because it is most likely that there will be no single rule for all default imports. In some cases, you will need PascalCase (classes) and in some cases you will need camelCase (functions). |
I would say the same about namespace imports. I think for the most part, the name of the thing depends on the name of the module you're importing. For example, a lot of our modules names are strictCamelCase, so we import namespaces as such, but at FB it's a react codebase, so you have a lot of PascalCase files (and import namespace as such). We can always use the Also worth noting that you can apply multiple format options to a selector if you want to allow either. This mostly just means you can ban unnderscores or consecutive capitals. |
If it will be possible to distinguish between default imports and namespaces, then no problem. Thanks! |
For default import there's already a PR to eslint-plugin-import for the rule which enforces naming the import the same as export. I could also imagine somebody could want to name the default import after the filename, but that's also a better fit for eslint-plugin-import. I don't see any other reason for linting names of default imports, unless you actually want to always rename them, which is weird. |
Revisiting this - I'm not sure if it 100% makes sense for this to exist in the On the one hand - it's trivial to add this to the rule, and you can validate that the name adheres to a format. On the other hand - IMO the name of an import should be directly related to the thing being imported. I.e. it should be the filename ( Is there enough value in just ensuring the import name matches a format? |
Fixes #2106 This is a work in progress.
I think yes, because this
is very opinionated (although I support this viewpoint) and in some teams the naming style may differ. |
Hello!
It's not a bug report, it's a feature request.
Repro
Expected Result
The error.
Actual Result
No error.
Additional Info
N/A.
Versions
@typescript-eslint/eslint-plugin
3.0.0
@typescript-eslint/parser
3.0.0
TypeScript
3.9.3
ESLint
7.1.0
node
X.Y.Z
npm
X.Y.Z
The text was updated successfully, but these errors were encountered: