This rule enforces that import
/export
statements and require
calls — henceforth referred to as just "imports" — use (or omit) file extensions consistently.
This rule complains if it finds an import with an unnecessary ".js" extension.
In its current form, it follows some simple heuristics and is not configurable (unlike more complex rules, such as the third-party imports/extensions rule):
- Imports should omit the unnecessary ".js" extension.
- NPM package names (which may end in ".js" are exempted).
Based on the current usages in liferay-portal (via git grep "import.+\\.js';" -- '*.js'
) and clay (via git grep "import.+\\.(js|ts|tsx)';" -- '*.ts' '*.tsx' '*.js'
) we believe this simpler approach should be sufficient, but we can add configurability in the future if that proves not to be the case.
Examples of incorrect code for this rule:
import templates from './Something.soy.js';
import {Util} from './Util.es.js';
import * as Billboard from './billboard.js';
export {thing} from './other.js';
Examples of correct code for this rule:
import templates from './Something.soy';
import {Util} from './Util.es';
// OK because "billboard.js" is the name of an NPM package:
import {Data} from 'billboard.js';
export {thing} from './other';