import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.57k stars 1.57k forks source link

feat(import/extensions): allow enforcement decision overrides based on specifier #3105

Open Xunnamius opened 3 days ago

Xunnamius commented 3 days ago

I already use import/order with custom pathGroups. This allows me to control the grouping of certain paths, such as custom aliases from tsconfig.json's paths. This in turn ensures all imports are sorted properly, even when the project is using syntactically sound but otherwise bespoke custom aliases like my-project:api.js (in lieu of ../../../../src/api.js).

Unfortunately, if I mistype my-project:api (i.e. I forgot the extension), the import/extensions rule will still pass; the enforcement decision is "ignore" when it should have been "enforce". This is because, like import/order, the grouping strategy employed by this rule is quite coarse-grained, but unlike import/order, this rule is missing a pathGroups-like setting for finer-grained sorting. The goal of this PR is to fill that gap.

This PR allows developers to override the decision to enforce or ignore extensions for imports with matching specifiers. This is implemented via pathGroupOverrides.

The documentation updates associated with the changes in this PR are part of a separate PR and can be previewed here (towards the bottom of the section). This PR also includes tests.

codecov[bot] commented 3 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.23%. Comparing base (a20d843) to head (1c127b7).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #3105 +/- ## ========================================== - Coverage 95.28% 95.23% -0.05% ========================================== Files 83 83 Lines 3584 3592 +8 Branches 1252 1257 +5 ========================================== + Hits 3415 3421 +6 - Misses 169 171 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features: