extensions
Added in v0.9.4Configuration
Rule Details
Enforce consistent file extensions in import paths, re-exports, dynamic imports,
and require() calls. The default mode is "never". Builtins and package roots,
including names such as decimal.js, are exempt by default.
Examples of incorrect code for this rule, when both paths resolve to the same file:
Examples of correct code for this rule:
If both value.js and value.json exist, ./value.json remains valid when
./value resolves to value.js. The rule only forbids extensions that can be
removed without changing the resolution result. Two unresolved paths also count
as the same result, matching upstream.
Query strings are excluded when resolving a path and included in diagnostics. The rule does not provide automatic fixes or suggestions.
Options
The first option selects the default mode:
"never"(default): forbid extensions that can be omitted."always": require extensions."ignorePackages": require extensions outside package imports.
An extension map overrides the default mode:
The object form also accepts:
Each path override has a pattern, optional patternOptions, and an action.
ignore skips the import; enforce applies the configured mode even to builtins
and packages. Glob options default to { nocomment: true } when omitted.
For example, require extensions for aliases that resemble packages:
As in upstream v2.32.0, include pattern, ignorePackages, or checkTypeImports
in an object containing pathGroupOverrides; otherwise its overrides have no
effect. The per-extension mode ignorePackages disables checking that extension.
Examples of incorrect code with "always":
Examples of correct code with "always":
Resolution settings
The default Node resolver tries .mjs, .js, .json, and .node. Configure
settings['import/resolver'] to use node with an extensions array, or
typescript to use the TypeScript project selected by rslint. The legacy
settings['import/resolve'] also accepts Node options.
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, or exclude those imports withpathGroupOverrides. - 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. - Multiple resolvers in an object run alphabetically. Use an array such as
['typescript', 'node']to specify their order. - On Windows, use
/separators in glob patterns, such asapp/**. Backslashes escape pattern characters rather than separating directories. - Extensions such as
constructorandtoStringfollow the configured mode. For example,import './file.constructor'reports with"never", while upstream implicitly ignores it. Set{ constructor: 'ignorePackages' }to retain that exemption. - If an import path contains a lone surrogate escape such as
\uD800, the diagnostic displays replacement characters for that escape. Regular Unicode paths, including emoji, retain their spelling.