no-useless-path-segments
Added in v0.9.4Configuration
Rule Details
Disallow unnecessary path segments in relative imports, re-exports, and dynamic
imports. The rule can also check CommonJS require() calls.
Paths are normalized when the original and shorter spelling resolve to the same module, or when neither resolves. Resolved paths that leave and re-enter the current directory can also be shortened. Automatic fixes use double quotes.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
commonjs
Set commonjs to true to check require('./utils//value'). It is disabled by
default. Non-literal arguments, template literals, and require.resolve() are
not checked.
noUselessIndex
Set noUselessIndex to true to remove a trailing /index or /index with a
configured extension. It is disabled by default.
If utils.js exists alongside utils/index.js, the replacement is "./utils/"
to preserve the directory import. Extensions come from import/extensions
(default: .js, .mjs, .cjs) plus import/parsers, independently of resolver
extensions.
As upstream does, this option removes index even for unresolved paths and does
not check whether a directory's package.json selects a different entry point.
Differences from upstream
- Supported resolvers are
nodeandtypescript, also accepted aseslint-import-resolver-nodeandeslint-import-resolver-typescript. For example,settings['import/resolver'] = 'webpack'reports a resolver error. For bundler aliases, usetypescriptwith matchingpathsintsconfig.json. - The
typescriptresolver follows the TypeScript project selected by rslint. Itsproject,alwaysTryTypes, and other resolver-specific options have no effect. For example,{ typescript: { project: 'tsconfig.app.json' } }does not select that config; uselanguageOptions.parserOptions.projectinstead. - If an
import/resolverobject contains several resolver names, they are tried alphabetically. Use an array, such as['typescript', 'node'], to choose the order explicitly. - Babel's experimental
export value from './module'syntax is not supported. Useexport { default as value } from './module'instead.