oxc-project / oxc

⚓ A collection of JavaScript tools written in Rust.
https://oxc.rs
MIT License
11.33k stars 409 forks source link

☂️ eslint-plugin-import #1117

Open Boshen opened 11 months ago

Boshen commented 11 months ago

[!WARNING] This comment is maintained by CI. Do not edit this comment directly. To update comment template, see https://github.com/oxc-project/oxc/tree/main/tasks/lint_rules

This is tracking issue for eslint-plugin-import.

There are 44(+ 1 deprecated) rules.

To get started, run the following command:

just new-import-rule <RULE_NAME>

Then register the rule in crates/oxc_linter/src/rules.rs and also declare_all_lint_rules at the bottom.

Recommended rules

✨: 7, 🚫: 1 / total: 8 | Status | Name | Docs | | :----: | :--- | :--- | | 🚫 | import/no-unresolved | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-unresolved.md | | ✨ | import/named | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/named.md | | ✨ | import/default | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/default.md | | ✨ | import/namespace | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/namespace.md | | ✨ | import/export | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/export.md | | ✨ | import/no-named-as-default | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-named-as-default.md | | ✨ | import/no-named-as-default-member | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-named-as-default-member.md | | ✨ | import/no-duplicates | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-duplicates.md | ✨ = Implemented, 🚫 = Not supported

Not recommended rules

✨: 7, 🚫: 0 / total: 36 | Status | Name | Docs | | :----: | :--- | :--- | | | import/no-namespace | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-namespace.md | | | import/no-mutable-exports | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-mutable-exports.md | | | import/extensions | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/extensions.md | | | import/no-restricted-paths | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-restricted-paths.md | | | import/no-internal-modules | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-internal-modules.md | | | import/group-exports | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/group-exports.md | | | import/no-relative-packages | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-relative-packages.md | | | import/no-relative-parent-imports | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-relative-parent-imports.md | | | import/consistent-type-specifier-style | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/consistent-type-specifier-style.md | | ✨ | import/no-self-import | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-self-import.md | | ✨ | import/no-cycle | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-cycle.md | | | import/no-named-default | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-named-default.md | | | import/no-anonymous-default-export | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-anonymous-default-export.md | | | import/no-unused-modules | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-unused-modules.md | | | import/no-commonjs | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-commonjs.md | | ✨ | import/no-amd | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-amd.md | | | import/first | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/first.md | | ✨ | import/max-dependencies | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/max-dependencies.md | | | import/no-extraneous-dependencies | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-extraneous-dependencies.md | | | import/no-absolute-path | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-absolute-path.md | | | import/no-nodejs-modules | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-nodejs-modules.md | | ✨ | import/no-webpack-loader-syntax | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-webpack-loader-syntax.md | | | import/order | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/order.md | | | import/newline-after-import | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/newline-after-import.md | | | import/prefer-default-export | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/prefer-default-export.md | | ✨ | import/no-default-export | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-default-export.md | | | import/no-named-export | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-named-export.md | | ✨ | import/no-dynamic-require | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-dynamic-require.md | | | import/unambiguous | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/unambiguous.md | | | import/no-unassigned-import | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-unassigned-import.md | | | import/no-useless-path-segments | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-useless-path-segments.md | | | import/dynamic-import-chunkname | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/dynamic-import-chunkname.md | | | import/no-import-module-exports | | | | import/no-empty-named-blocks | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-empty-named-blocks.md | | | import/exports-last | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/exports-last.md | | | import/no-deprecated | https://github.com/import-js/eslint-plugin-import/blob/v2.30.0/docs/rules/no-deprecated.md | ✨ = Implemented, 🚫 = Not supported

Deprecated rules

✨: 0, 🚫: 0 / total: 1 | Status | Name | Docs | | :----: | :--- | :--- | | | import/imports-first | https://github.com/import-js/eslint-plugin-import/blob/7b25c1cb95ee18acc1531002fd343e1e6031f9ed/docs/rules/imports-first.md | ✨ = Implemented, 🚫 = Not supported
XantreDev commented 9 months ago

Sponsorship link is broken

XantreDev commented 9 months ago

I think it kind of trivial to implement export rule

XantreDev commented 9 months ago

It's already implemented, checkboxes are obsolete

camc314 commented 9 months ago

Sponsorship link is broken

fixed

It's already implemented, checkboxes are obsolete

updated

XantreDev commented 8 months ago

@Boshen seems to be for implementing no-named-as-default we need to provide also Atom in ModuleRecord for export_default (to get export default identifier name). image

Can I try to add it? Maybe there are other way to do it?

Boshen commented 8 months ago

@XantreGodlike To be honest I don't really get this rule, and there's so many issues with it https://github.com/search?q=repo%3Aimport-js%2Feslint-plugin-import+no-named-as-default&type=issues

But for default exports, you may add a Option<Atom> because you can default export a function, which may not have a name.

yordis commented 8 months ago

yarn pnp support is huge for us 🙏🏻 🙏🏻 🙏🏻 🙏🏻 🙏🏻 🙏🏻 🙏🏻 🙏🏻 🙏🏻 🙏🏻 🙏🏻 🙏🏻 🙏🏻

XantreDev commented 8 months ago

@yordis Is it separate rule?

XantreDev commented 7 months ago

There is no new-import-rule

Boshen commented 7 months ago

There is not new-import-rule

The test cases eslint-plugin-import's aren't static enough for us to convert automatically, all the test cases are ported manually :-(

lachieh commented 7 months ago

Regarding yarn pnp support, it's a method of loading dependencies using a cache of zip files rather than the node_modules folder. It uses a custom loader resolution file that exports a generated list of packages and their zip counterparts. More information here: https://yarnpkg.com/features/pnp

Boshen commented 7 months ago

I want to tackle the list of super slow rules that use ExportMap in eslint-plugin-import:

Wish me luck.

Boshen commented 7 months ago

To port the tests, we'll need to clone eslint-plugin-import, add a console.log to copy the code over.

console.log("let pass = vec![" + valid.map((test) => `r#\"${test.code.trim()}\"#`).join(',\n') + "];\n")
console.log("let fail = vec![" + invalid.map((test) => `r#\"${test.code.trim()}\"#`).join(',\n') + "];")
XantreDev commented 7 months ago

Great news)

Boshen commented 7 months ago

After battling cjs / esm for 3 days ... I'm going to cut the scope and focus on ESM only. i.e. Only lint if the imported file is a ESM file.

Most of the rules are working as intended unless a CJS file is imported, which may contain any kind of bizarre export :-)


Performance wise, we should expect import-plugin + all the other rules finish within a second on a M2.

In a typical project with thousands of files:

AFFiNE canary ❯ ~/github/oxc/target/release/oxlint --import-plugin -D correctness -D no-cycle
Finished in 224ms on 1295 files with 88 rules using 8 threads.
Found 0 warnings and 0 errors.
Boshen commented 7 months ago

Maybe a good addition: https://github.com/thepassle/barrel-begone

steelbrain commented 7 months ago

Sharing some data on how much some ESLint rules take in the world. Would be nice to prioritise the slow ones

Rule                                          | Time (ms) | Relative
:---------------------------------------------|----------:|--------:
import/namespace                              | 27496.040 |    24.5%
@typescript-eslint/await-thenable             |  8834.873 |     7.9%
import/no-extraneous-dependencies             |  8648.620 |     7.7%
@typescript-eslint/no-floating-promises       |  7816.454 |     7.0%
react/destructuring-assignment                |  5010.386 |     4.5%
@typescript-eslint/strict-boolean-expressions |  4807.847 |     4.3%
import/extensions                             |  4265.243 |     3.8%
local/disallow-null-attributes                |  4235.864 |     3.8%
@typescript-eslint/no-unused-vars             |  4053.110 |     3.6%
react/no-this-in-sfc                          |  2530.419 |     2.3%
Boshen commented 3 months ago

import/no-unused-modules is useful and should be prioritized.

voxpelli commented 3 months ago

import/no-unused-modules is useful and should be prioritized.

Not sure if that rule even belongs in a linter or if a separate tool like knip is a better idea: https://knip.dev/