-
-
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
import/no-cycle does not detect some cycles with side-effect imports #3147
Comments
It’s not a cycle; it’s just a global variable (which you never want to be using). |
Well, |
Oh, fair point. Yes, that is a cycle. What's your config set to, and what version of the plugin are you using? |
I’m using the latest version (2.31.0) with the latest version of ESLint (9.18.0) and the following config (taken mostly from the docs of import importPlugin from "eslint-plugin-import";
import js from "@eslint/js";
export default [
js.configs.recommended,
importPlugin.flatConfigs.recommended,
{
files: ["**/*.{js,mjs,cjs}"],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
rules: {
"import/no-cycle": "warn",
"import/default": "off",
},
},
{
ignores: ["dist"],
},
]; |
ok, then it should be using scc. cc @soryy708 |
Ok we're talking about a false-negative. |
It makes no difference to add |
Hmm, not sure, I simply took some default codesandbox and added ESLint and |
Cool. In
is treated as a type-import,
|
Why would that be a type import? |
I don't know. Probably shouldn't? Perhaps because |
It definitely shouldn’t - if something with no exports is imported, it’s for side effects, and that means it’s critical and must always be considered. |
Looks like this also ignores imports of the form |
We do look at tsconfig for a flag already; I'm sure we could look up verbatimModuleSyntax. |
So we have at least 3 false-negatives here:
Would you like to contribute test cases? |
On another topic, On one hand fixing a false-negative would technically be a bugfix (so perhaps "patch" in semver?), How will we want to handle these edge cases? |
semver in eslint plugins is a bit tricky; producing more warnings can be a patch because it was a bug to miss them. |
apropos |
Here is the setup (https://codesandbox.io/p/devbox/my57j6):
This seems like a cycle to me (
a.js
expectsglobalThis.x
to be set given that it importsb.js
which importsc.js
which sets it, butc.js
uses an import froma.js
in order to setglobalThis.x
).Yet this is not detected as a cycle by
eslint-plugin-import
. Note that changinga.js
to import./c
instead of./b
is detected as a cycle, so it seems to be the indirection introduced byb.js
which confusesno-cycle
.The text was updated successfully, but these errors were encountered: