Bug: no-extraneous-import
does not work correctly with tsconfig.json
paths that start with ~
or @
#379
Labels
no-extraneous-import
does not work correctly with tsconfig.json
paths that start with ~
or @
#379
Environment
It probably doesn't matter, but
Node version: 20.9.0
npm version: 10.1.0
ESLint version: 9.14.0
eslint-plugin-n version: 17.12.0
Operating System: Windows 11
What rule do you want to report?
n/no-extraneous-import
Link to Minimal Reproducible Example
https://github.com/MorevM/eslint-plugin-n-no-extraneous-import-problem
What did you expect to happen?
Check the repository - the rule warns about extraneous import, although according to the path defined in the
tsconfig.json
this is an internal import.This only happens for paths that contain the
~
or@
character at the beginning.E.g. alias
#configurations/*
is working as expected, but~configurations/*
is not.The reason (probably) is that such paths are interpreted as
npm
modules here, leading to the determination of the module name here, which in turn makes the report condition truthy here.Participation
Additional comments
I'm not sure the best way to solve this and would be happy if someone more familiar with the architecture of the project could suggest how to do it better - I can form a PR.
I'd probably do it this way:
ImportTarget
, move theresolverConfig
definition from thegetFilePath
method into a separate method (this is where the aliases are defined that need to be accounted for).getModuleType
, check the name againstresolverConfig.alias
(if any) before the RegExp that checks fornpm
modules.This will solve the problem.
If someone with the right permissions confirms that this is indeed the problem and that the solution is appropriate, I will make a PR with the fix.
The text was updated successfully, but these errors were encountered: