oxc icon indicating copy to clipboard operation
oxc copied to clipboard

linter: import/extensions rule should have mjs/mts/cjs/cts options

Open connorshea opened this issue 2 months ago • 2 comments

.mjs, .mts, .cjs, and .cts are valid, somewhat-common extensions for JavaScript/TypeScript code. Currently, import/extensions does not allow specifying anything of them. The original ESLint rule allows arbitrary values, so some projects migrating over will run into a potential incompatibility here.

Note that when implementing this, ensure that the way we check for extensions does not result in the rule for js overriding the rule for mjs (because if you just check for "does the filename end with 'js'?", mjs files would also be returned.

https://github.com/oxc-project/oxc/blob/25d577e274a680a785902eca6901d0ec38c801f0/crates/oxc_linter/src/rules/import/extensions.rs

connorshea avatar Nov 09 '25 07:11 connorshea

the airbnb config sets mjs as a default value as well, so this is probably very common: https://github.com/airbnb/javascript/blob/0e2ef178a26ba9ac3495402a182891ad8096d3a0/packages/eslint-config-airbnb-base/rules/imports.js#L142

connorshea avatar Nov 09 '25 07:11 connorshea

hmm, maybe .vue, .astro, .svelte, and .css as well?

And/or an escape hatch for "all other problematic cases? e.g. right now if you have this set to never allow extensions:

{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "plugins": ["import"],
  "rules": {
    "import/extensions": ["error", "never"]
  }
}

Then you can't use .css imports, even though you do need extensions for those in many cases. And there's no way to make this work as-is.

connorshea avatar Nov 09 '25 18:11 connorshea

This will be fixed by #14602

connorshea avatar Nov 16 '25 09:11 connorshea