eslint-plugin-rulesdir

raw JSON →
0.2.2 verified Sat Apr 25 auth: no javascript maintenance

Allows a local ESLint rules directory to be used without the --rulesdir command-line flag. Version 0.2.2 is experimental and its API may change. It requires manual configuration by setting the RULES_DIR property on the plugin object before use. Unlike eslint-plugin-local-rules, which scans for a local directory automatically, rulesdir provides explicit control over which directories to load rules from. Works with Node >=4.0.0 and ESLint.

error ESLint couldn't find the plugin "eslint-plugin-rulesdir".
cause Plugin is not installed or is installed globally while ESLint is local.
fix
Run 'npm install eslint-plugin-rulesdir --save-dev' in your project directory.
error Cannot read property 'RULES_DIR' of undefined
cause require('eslint-plugin-rulesdir') returned undefined or the plugin was not properly loaded.
fix
Ensure the package is installed and the require path is correct: const rulesDirPlugin = require('eslint-plugin-rulesdir');
error Rule "rulesdir/my-rule" was not found.
cause The RULES_DIR path is incorrect or the rule file does not exist.
fix
Verify that the rule file exists at the specified path relative to cwd. Check RULES_DIR assignment.
error Configuration for rule "rulesdir/my-rule" is invalid: Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '"error"').
cause Severity strings like 'error' are not supported; must use numeric values or full severity strings in newer ESLint.
fix
Use 'error' as a string (ESLint >= 3.0.0 supports strings) or number 2. Check your ESLint version.
gotcha RULES_DIR must be set before the config is evaluated; it is a runtime property, not part of the config object.
fix Ensure the require() and assignment to RULES_DIR happens at the top level of your config file, before module.exports.
gotcha The plugin name in the plugins array is 'rulesdir', not the full package name.
fix Use 'rulesdir' in the plugins array.
breaking This plugin is experimental and its API may change. RULES_DIR property and behavior might not be stable.
fix Pin to a specific version and monitor the repository for breaking changes.
gotcha Path resolution is from the current working directory (cwd), not the config file's location. Running ESLint from a different directory may break rule loading.
fix Use absolute paths or ensure cwd consistency with process.chdir() or --cwd flag.
gotcha Multiple directories are supported via array, but only since version 0.2.0? (Check docs). Combining with single string may cause confusion.
fix If using an older version, only strings are accepted. Upgrade to 0.2.0+ for array support.
npm install eslint-plugin-rulesdir
yarn add eslint-plugin-rulesdir
pnpm add eslint-plugin-rulesdir

Shows how to set up eslint-plugin-rulesdir with a local rules directory and configure a custom rule.

// Install: npm install eslint --save-dev && npm install eslint-plugin-rulesdir --save-dev

// .eslintrc.js
const rulesDirPlugin = require('eslint-plugin-rulesdir');
rulesDirPlugin.RULES_DIR = './local-rules';

module.exports = {
  plugins: ['rulesdir'],
  rules: {
    'rulesdir/my-custom-rule': 'error',
  },
};