sindresorhus/eslint-plugin-unicorn

Rule proposal: Require extension for relative imports and re-exports

クローズ

#1,194 opened on 2021/04/20

 (9 件のコメント) (12 件のリアクション) (0 人の担当者)JavaScript (468 件のフォーク)user submission
help wantednew rule

Repository metrics

Stars
 (5,022 個のスター)
PR merge metrics
 (平均マージ 1d 16h) (30d で 399 merged PRs)

説明

It would enforce using a .js extension for relative imports if it doesn't already have an extension.

We cannot auto-fix as we cannot know whether import foo from './foo'; refers to a file or directory.

This even applies to TypeScript, where you still need the .js extension even if you import other .ts files.

There's already the import/extensions rule, but that project is not very actively maintained, very buggy, and also it doesn't let us use .js extension for TypeScript files. I think it's worth adding this simple rule here.

This rule will not do anything about require() statements.

Fail

import foo from './foo';
export foo from './foo';
await import('./foo');

Pass

import foo from './foo.js';
export foo from './foo.js';
await import('./foo.js');
import foo from './foo.vue';

コントリビューターガイド