feat(no-useless-path-segments): report useless index in aliased imports #596
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 328 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.347
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #596"
general
weight: 0.35
thekhegay
Fixes #589
With
noUselessIndex: true,import foo from '@/test/index.js'was never reported, while./test/index.jswas. The rule returns early for every specifier that doesn't start with., so aliased paths never reach the index check.Upstream (import-js/eslint-plugin-import#2939) this was turned down because a bare specifier usually maps to a package, and a package's
exportsmay not allow the shorter path. So this change only handles that narrow case and stays out of packages:internalaccording toimportType, meaning it resolves to a file inside the project and not undernode_modules(or another external module folder).a/indexand an alias that points intonode_modulesare left alone.@/test, or@/test/as a second try) if the resolver maps it to the same file as the original import. If neither does (for example@/barresolves tobar.jsinstead ofbar/index.js), nothing is reported, so the autofix can't change which file is imported.Relative imports go through the same code as before. The docs mention the alias case, and there's a changeset.
Tests: valid and invalid cases for an aliased
indexandindex.js, an ambiguous@/bar/index.js, an unresolved alias, an external package and an alias intonode_modules, usingcreateNodeResolver({ alias })on the existing fixtures.How I verified: I couldn't run the jest suite locally, so CI is the first run of the spec. I ran the same cases through ESLint's
Linterwith the published 4.18.0 build, once as released and once with this change ported into its compiled rule, against this repo'stest/fixturesand the same alias config. 4.18.0 reports nothing for@/importType/indexand@/importType/index.js. With the change, both are reported and fixed to@/importType, and every valid case above stays clean. Relative imports like./importType/indexgive the same result as before.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
When
noUselessIndexis enabled,no-useless-path-segmentscan flag unnecessary/indexsegments in aliased imports of local files when shortening the path resolves to the same file. Alias roots, external packages, unresolved paths, and Node subpath imports are excluded.Documentation
Clarified which aliased imports are checked, how resolution is determined, and how differing resolver settings may affect paths.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->