eslint-plugin-import-newlines
raw JSON → 2.0.0 verified Sat Apr 25 auth: no javascript
ESLint plugin that enforces newlines in ES6 import statements when the number of imported specifiers exceeds a configurable threshold. The current stable version is 2.0.0, which requires ESLint >=10 and Node >=20.19.0. It provides a single rule 'import-newlines/enforce' that automatically splits multi-item imports across multiple lines when they exceed the limit, and conversely collapses single-line imports that are under the limit. Key differentiators: built-in autofix, integration with max-len and semicolon settings, and simple object-based configuration. No dependencies other than ESLint peer dependency.
Common errors
error ESLint couldn't find the plugin "eslint-plugin-import-newlines". ↓
cause Plugin not installed or ESLint is not using the correct config file path.
fix
Run 'npm install eslint-plugin-import-newlines --save-dev' and ensure your ESLint config references the correct plugin name.
error Configuration for rule "import-newlines/enforce" is invalid: Value "[object Object]" must be an array or a string. ↓
cause Passed an object as the rule value without wrapping it in an array.
fix
Use an array format: ["error", {"items": 2}].
error Error: Cannot find module 'eslint-plugin-import-newlines' ↓
cause The package is not installed or node_modules is corrupted.
fix
Reinstall the plugin with 'npm install eslint-plugin-import-newlines --save-dev'.
Warnings
breaking Version 2.0.0 drops support for ESLint 9 and below. ↓
fix Upgrade to ESLint 10+ or stay on eslint-plugin-import-newlines v1.x.x.
breaking Version 2.0.0 requires Node.js >=20.19.0. ↓
fix Upgrade Node to 20.19.0 or later, or stay on v1.x.x.
gotcha The rule's autofix does not add indentation; final formatting relies on the 'indent' rule. ↓
fix Enable and configure ESLint's built-in 'indent' rule to handle indentation after autofix.
gotcha The 'semi' option must match your code style (semicolons at end of imports) to avoid false max-len calculations. ↓
fix Set 'semi' option to 'true' (default) if you use semicolons, 'false' if you don't.
Install
npm install eslint-plugin-import-newlines yarn add eslint-plugin-import-newlines pnpm add eslint-plugin-import-newlines Imports
- eslint-plugin-import-newlines wrong
adding 'eslint-plugin-import-newlines' to the plugins arraycorrectAdd 'import-newlines' to the plugins array in your ESLint config - import-newlines/enforce wrong
using 'enforce' without the 'import-newlines/' prefixcorrectConfigure rule in rules object as 'import-newlines/enforce': 'error' or ['error', options]
Quickstart
{
"plugins": ["import-newlines"],
"rules": {
"import-newlines/enforce": ["error", {
"items": 3,
"max-len": 100,
"semi": false
}]
}
}