oxc icon indicating copy to clipboard operation
oxc copied to clipboard

☂️ eslint-plugin-import

Open Boshen opened this issue 1 year ago • 19 comments

[!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.

  • 0/8 recommended rules are remaining as TODO
    • All done! 🎉
  • 29/36 not recommended rules are remaining as TODO

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.31.0/docs/rules/no-unresolved.md
import/named https://github.com/import-js/eslint-plugin-import/blob/v2.31.0/docs/rules/named.md
import/default https://github.com/import-js/eslint-plugin-import/blob/v2.31.0/docs/rules/default.md
import/namespace https://github.com/import-js/eslint-plugin-import/blob/v2.31.0/docs/rules/namespace.md
import/export https://github.com/import-js/eslint-plugin-import/blob/v2.31.0/docs/rules/export.md
import/no-named-as-default https://github.com/import-js/eslint-plugin-import/blob/v2.31.0/docs/rules/no-named-as-default.md
import/no-named-as-default-member https://github.com/import-js/eslint-plugin-import/blob/v2.31.0/docs/rules/no-named-as-default-member.md
import/no-duplicates https://github.com/import-js/eslint-plugin-import/blob/v2.31.0/docs/rules/no-duplicates.md

✨ = Implemented, 🚫 = No need to implement

Not recommended rules

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

✨ = Implemented, 🚫 = No need to implement

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, 🚫 = No need to implement

Boshen avatar Oct 30 '23 17:10 Boshen

Sponsorship link is broken

XantreDev avatar Jan 08 '24 12:01 XantreDev

I think it kind of trivial to implement export rule

XantreDev avatar Jan 08 '24 12:01 XantreDev

It's already implemented, checkboxes are obsolete

XantreDev avatar Jan 08 '24 12:01 XantreDev

Sponsorship link is broken

fixed

It's already implemented, checkboxes are obsolete

updated

camc314 avatar Jan 08 '24 12:01 camc314

@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?

XantreDev avatar Jan 18 '24 17:01 XantreDev

@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.

Boshen avatar Jan 19 '24 03:01 Boshen

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

yordis avatar Jan 24 '24 00:01 yordis

@yordis Is it separate rule?

XantreDev avatar Jan 25 '24 21:01 XantreDev

There is no new-import-rule

XantreDev avatar Feb 17 '24 23:02 XantreDev

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 :-(

Boshen avatar Feb 18 '24 03:02 Boshen

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

lachieh avatar Feb 20 '24 16:02 lachieh

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

  • default (recommended)
  • export
  • named (recommended)
  • namespace (recommended)
  • no-cycle
  • no-deprecated
  • no-named-as-default (recommended)
  • no-named-as-default-member (recommended)
  • no-unused-modules

Wish me luck.

Boshen avatar Feb 22 '24 08:02 Boshen

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') + "];")

Boshen avatar Feb 22 '24 09:02 Boshen

Great news)

XantreDev avatar Feb 22 '24 09:02 XantreDev

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 avatar Feb 24 '24 16:02 Boshen

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

Boshen avatar Feb 26 '24 03:02 Boshen

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%

steelbrain avatar Mar 08 '24 19:03 steelbrain

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

Boshen avatar Jun 17 '24 17:06 Boshen

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/

voxpelli avatar Jul 01 '24 15:07 voxpelli