Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Latest commit

 

History

History
45 lines (26 loc) · 1.69 KB

File metadata and controls

45 lines (26 loc) · 1.69 KB

Omit extensions consistently with import, export and require (import-extensions)

This rule enforces that import/export statements and require calls — henceforth referred to as just "imports" — use (or omit) file extensions consistently.

Rule Details

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

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';

See also