-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
import/no-unused-modules can't recognize loading rules with moduleSuffixes #2698
Comments
I'm not familiar with |
@ljharb, It can help to import platform-specific module not using conditions. as you can see, I import module without suffix import {myModule} from './my-module' Then, if I build my App with arg target='p2', myModule will be imported from './my-module.p2.ts', and if target='connect', myModule will be imported from './my-module.connect.ts' this way is also used in ReactNative by default to import system-specific code |
Interesting. How can the linter know that every potential suffix is used or not? or are you suggesting that every moduleSuffix should be considered "used" if it exists? |
I have no idea how to resolve it correctly, because import/resolver of .eslint has similar issue (it resolves only the first extension from the list, in my case it's '.p2.ts'), but I'd like to use ignore patterns to don't check this rule in suffixed files |
JFYI. my eslint settings: "settings": {
"react": {
"version": "17.0.2"
},
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"node": {
"extensions": [".p2.ts", ".connect.ts", ".js", ".jsx", ".ts", ".tsx"]
},
"typescript": {
"alwaysTryTypes": true,
"project": "ui/tsconfig.json"
}
},
"import/ignore": ["node_modules"]
} |
To be clear, |
It's interesting, because if I remove '.p2.ts' and '.connect.ts' from extensions, I will see next situation: |
yes, because by standard resolution rules, your file is the node resolver shouldn't support that. However, if you swap the node and typescript resolver ordering, so node is last, i would hope the TS resolver knows about moduleSuffixes. If not, then that's something we should look into. |
what do you mean? |
In your settings object, you specify "node" first, before "typescript" - but you want typescript to do resolution before node does, so you should swap them. |
It still doesn't work |
thanks for confirming. @bradzacher, any idea if the TS resolver knows about |
Doing some digging - it looks like it doesn't. I'd file an issue over at eslint-import-resolver-typescript so they can add support! |
Thank you. Let the link be here |
ah yes, thanks :-) |
This comment was marked as spam.
This comment was marked as spam.
I've made simple resolver package to solve that (and that) issue. |
@NikolayFrantsev - cool, thank you |
@NikolayFrantsev - I still see the issue |
Duplicate of import-js/eslint-import-resolver-typescript#211 |
I use this rule in my multiplatform app and I load specific parts of code by moduleSuffixes. And I get warnings in platform-specific modules.
my .tsconfig
my webpack config
then I import some specific module from shared code as
where module is defined as
./my-module.p2.ts
./my-module.connect.ts
I see that it's an unusual way of importing configured by webpack, but if the
import/no-unused-modules
rule had ignorePattern option, I would pass it as '*.connect.ts' and it would be enoughThe text was updated successfully, but these errors were encountered: