-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[no-extraneous-dependencies] relative path that refers to file outside package.json should error #3067
Comments
The rule treats them differently because they are written differently in the source code - this is a linter, that should be expected. |
Sorry, I don't follow. Are you saying the rule is currently operating as intended for relative paths that refer to parent files outside of its package.json context?
I understand how the two cases are handled differently in code. I created this issue to ask if that is intended or a bug. |
It seems intended to me. There's another rule that you can use to prevent relative paths reaching outside of the project dir. |
Hmm, I don't see it the same way. I believe both examples should error. From the source code, Example 1 considers it an From the rule's description:
I think that falls perfectly in line with the rule, no? Put another way, why does a relative path not fall into this rule's domain, but a typescript path alias does? 🤔 |
Relative paths are always just local files; anything that's not a relative or absolute path is a "bare specifier", which qualifies to maybe be "external". |
Yes, but how does that preclude this rule from handling relative paths? Reiterating the rule description again:
By all definitions, Example 2 is importing an |
|
I think I understand a little better now.
Perhaps you're referring to the following definition of
By that definition, I see what you mean by However, by that same definition, my Example 1 using typescript path alias should not error. The path alias resolved to a file that is not in |
From my reading of the code, this means "external" isn't defined as "outside the project". It sounds like |
Haha, yes! Now that I understand the definition of "external" used in this plugin, I believe we've made a complete 180 from my OP. |
Hi, I'm not sure if the current behavior is intended or not, so I want to start a discussion.
Simple setup
Directory
tsconfig
eslint
Example 1 with TS Path Alias: Errors as expected
However, the below uses the typescript path alias, which does error. In this case, the plugin resolves it as an
external
import. https://github.com/import-js/eslint-plugin-import/blob/main/src/core/importType.js#L100Example 2 with relative import: No error (Bug?)
When doing the following, there is no error from the rule. This is because the plugin considers it a
parent
import. https://github.com/import-js/eslint-plugin-import/blob/main/src/core/importType.js#L97Discussion
I'm not sure I agree with the discrepancy in the above behavior. It doesn't really make sense to me that both methods resolve to the same file, but the rule treats them differently. I think using a relative path to refer to a file outside the enclosing
package.json
context should causeno-extraneous-dependencies
to error.Next Steps / Solution (?)
The core of the issue seems to be that the
typeTest()
function is overloaded. In this case, it actually seems like it's a bug when used for this rule. In Example 2,typeTest
returns"parent"
, causing the rule to fail to report the error. The correct behavior was actually fortypeTest
to return"external"
.(aside: I think the above bug makes
isExternalModule()
andisExternalModuleMain()
bugged as well)@ljharb Is the above assessment accurate?
The text was updated successfully, but these errors were encountered: