eslint-plugin-index
raw JSON → 1.1.7 verified Sat Apr 25 auth: no javascript
An ESLint plugin (v1.1.7) providing rules to enforce proper usage of index.js files in Node.js projects. Includes two rules: `only-import-export` (allows only import/export statements in index files) and `forbid` (disallows files named index). Supports ESLint 7 or 8. Recommended for projects wanting to enforce index file conventions. Niche, simple, minimal overhead. Not updated frequently.
Common errors
error ESLint couldn't find the plugin "eslint-plugin-index". ↓
cause Plugin not installed or not in node_modules.
fix
Run
npm install -D eslint-plugin-index. error Configuration for rule "index/only-import-export" is invalid: Value "error" must be an object or string. ↓
cause Incorrect rule configuration syntax in ESLint config.
fix
Use string severity: "index/only-import-export": "error"
Warnings
gotcha Plugin is designed to lint index.js files; does not work on other file names. ↓
fix Focus only on index.js files.
gotcha Rules only apply to .js files; does not handle .ts or .jsx by default. ↓
fix Configure ESLint to lint .ts/.jsx and ensure plugin settings apply.
gotcha The 'forbid' rule forbids any file named index; may conflict with legitimate index files. ↓
fix Use at your own discretion; consider disabling if you need index files.
gotcha The 'only-import-export' rule allows only import and export statements; other statements cause errors. ↓
fix Ensure index files contain only imports/exports or disable rule.
Install
npm install eslint-plugin-index yarn add eslint-plugin-index pnpm add eslint-plugin-index Imports
- plugin wrong
{ "plugins": ["eslint-plugin-index"] } // also works but unnecessary prefixcorrect// in .eslintrc: { "plugins": ["index"] } - recommended config wrong
{ "extends": ["index/recommended"] } // missing plugin: prefixcorrect// in .eslintrc: { "extends": ["plugin:index/recommended"] } - only-import-export rule wrong
// no common wrong patterncorrect// in .eslintrc rules: { "index/only-import-export": "error" } - forbid rule wrong
// no common wrong patterncorrect// in .eslintrc rules: { "index/forbid": "error" }
Quickstart
npm install -D eslint eslint-plugin-index
// .eslintrc.json
{
"plugins": ["index"],
"extends": ["plugin:index/recommended"],
"rules": {
"index/forbid": "error"
}
}