eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

import/extensions: Reverse logic of `ignorePackages` with `never`

Open Drafter500 opened this issue 3 years ago • 4 comments

ignorePackages flag always works in one direction, it only allows skipping extensions in packages in always mode (default), but it is impossible to make it reverse: allow having extensions for packages in never mode. Currently in combination with never, it does nothing. By the name of the flag, I expected it to stop complaining about package imports in any situation.

For example, with this config: ['error', 'never', {ignorePackages: true} ]

It should forbid extensions except for packages:

import Component from './Component'; // OK
import Component from './Component.jsx'; // Not OK
import baz from 'package/module-one'; // OK
import bizz from 'package/module-two.js'; // Should be also OK!!! 

Drafter500 avatar Sep 20 '21 15:09 Drafter500

Why should that be ok?? Packages without “exports” don’t need extensions, and packages with it should be defining their paths without them as well. Can you provide an example where both forms are valid, and you want the extension on third-party code?

ljharb avatar Sep 20 '21 15:09 ljharb

Why should that be ok?? Packages without “exports” don’t need extensions, and packages with it should be defining their paths without them as well. Can you provide an example where both forms are valid, and you want the extension on third-party code?

With the new version of lit some parts require extensions when importing them: https://github.com/lit/lit/issues/1986#issuecomment-870084329

The export paths are defined with extensions: https://github.com/lit/lit/blob/main/packages/lit/package.json#L18

Drafter500 avatar Sep 20 '21 15:09 Drafter500

Codecov Report

Merging #2231 (a65c60e) into main (fd85369) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2231   +/-   ##
=======================================
  Coverage   95.23%   95.23%           
=======================================
  Files          65       65           
  Lines        2687     2687           
  Branches      889      890    +1     
=======================================
  Hits         2559     2559           
  Misses        128      128           
Impacted Files Coverage Δ
src/rules/extensions.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fd85369...a65c60e. Read the comment docs.

codecov[bot] avatar Sep 20 '21 20:09 codecov[bot]

@Drafter500 in that case, the solution is for the resolve package to add "exports" support, and then for this plugin to not try to check extensions on any package with "exports" - it'd only be if a package provides two "exports" entries that point to the same file, and one had an extension and one didn't, and you also preferred the one WITH an extension, that this PR would come into play - and I'm not sure why anyone would prefer using the extension when it's possible to omit it.

ljharb avatar Sep 20 '21 23:09 ljharb