eslint-plugin-local-rules
raw JSON → 3.0.2 verified Sat Apr 25 auth: no javascript
An ESLint plugin that enables project-specific rules from a local eslint-local-rules.js file, similar to the deprecated --rulesdir CLI option. Current stable version is 3.0.2, with releases about every 6-12 months. Supports npm/yarn/pnpm workspaces, TypeScript via ts-node, and provides all/all-warn configs. Key differentiators: minimal setup, automatic discovery of local rules, and workspace-aware rule resolution. Minimum Node 12.
Common errors
error Error: Failed to load plugin 'local-rules' declared in '.eslintrc': Cannot find module 'eslint-plugin-local-rules' ↓
cause eslint-plugin-local-rules not installed or not in node_modules.
fix
Run
npm install eslint-plugin-local-rules --save-dev in your project. error Error: Cannot find module 'eslint-local-rules' ↓
cause eslint-local-rules.js or eslint-local-rules/index.js not found in the expected directory.
fix
Create an eslint-local-rules.js file in your project root (or in the workspace directory when using workspaces).
error TypeError: Invalid rule definition: rule 'my-rule' must be an object with 'create' function ↓
cause The rule exported in eslint-local-rules.js is not a valid rule object (missing create or meta).
fix
Ensure each rule has both a
meta object and a create function: { meta: { ... }, create(context) { return { ... } } }. Warnings
breaking v2.0.0: Workspace support changed rule resolution: check CWD for eslint-local-rules.js before plugin install location. ↓
fix If using workspaces, ensure you run ESLint from the workspace subdirectory, not the project root, especially when a workspace-level rules file exists.
gotcha If an eslint-local-rules.js file exists in both a workspace subdirectory and the project root, the workspace one takes precedence only when running ESLint from that workspace directory. ↓
fix Run ESLint from the workspace directory (e.g., cd src/app && npx eslint index.js) to pick up workspace-specific rules.
gotcha When using ts-node for TypeScript rules, you must set module to 'commonjs' in ts-node options, otherwise imports may fail. ↓
fix Add `compilerOptions: { module: 'commonjs' }` to ts-node.register() call in eslint-local-rules/index.js.
breaking Minimum Node.js version increased to 12 in v3.0.1. ↓
fix Use Node.js 12 or higher.
Install
npm install eslint-plugin-local-rules yarn add eslint-plugin-local-rules pnpm add eslint-plugin-local-rules Imports
- plugin wrong
require('eslint-plugin-local-rules')correctmodule.exports = { plugins: ['local-rules'] } - local-rules config wrong
extends: ['eslint-plugin-local-rules/all']correctextends: ['plugin:local-rules/all'] - rules file wrong
module.exports = { rules: { 'rule-name': { ... } } }correctmodule.exports = { 'rule-name': { ... } }
Quickstart
// Create eslint-local-rules.js in project root
module.exports = {
'no-console-log': {
meta: { docs: { description: 'disallow console.log', category: 'Best Practices' }, schema: [] },
create: function (context) {
return {
CallExpression: function (node) {
if (node.callee.type === 'MemberExpression' && node.callee.object.name === 'console' && node.callee.property.name === 'log') {
context.report({ node, message: 'Unexpected console.log' });
}
}
};
}
}
};
// In .eslintrc.json
{
"plugins": ["local-rules"],
"rules": { "local-rules/no-console-log": "error" }
}