eslint-plugin-external-import-esm
v1.0.9
Published
ESLint plugin to enforce using .js file extensions for external imports in ESM projects
Maintainers
Readme
eslint-plugin-external-import-esm
ESLint plugin to detect external ESM imports of format
'lib/func','lib/func/subfunc', etc., excluding internal import like@/,./, or../.
Installation
npm install eslint-plugin-external-import-esm --save-devConfigs
| | Name |
| :- | :------------ |
| ✅ | recommended |
Rules
💼 Configurations enabled in.
✅ Set in the recommended configuration.
🔧 Automatically fixable by the --fix CLI option.
| Name | Description | 💼 | 🔧 | | :--------------------------------------------------------- | :--------------------------------------------- | :- | :- | | require-external-js-extension | Force .js extension on external module imports | ✅ | 🔧 |
Usage
import externalImportEsm from 'eslint-plugin-external-import-esm';
import js from '@eslint/js';
export default [
js.configs.recommended,
externalImportEsm.configs.recommended,
{
files: ['**/*.{js,ts}'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
// Or override the rule here:
rules: {
'external-import-esm/require-external-js-extension': 'warn',
},
},
];Examples
❌ Incorrect
import func from 'lib/func'; // Missing .js extension
import subfunc from 'lib/func/subfunc'; // Missing .js extension
import plugin from 'dayjs/plugin/something'; // Missing .js extension✅ Correct
import func from 'lib/func.js';
import subfunc from 'lib/func/subfunc.js';
import plugin from 'dayjs/plugin/something.js';
import myUtil from '@/utils'; // Alias import, no .js needed
import localModule from './local'; // Relative import, no .js neededDocumentation
See require-external-js-extension for full details and examples.
