eslint-plugin-folders
raw JSON → 1.0.4 verified Sat Apr 25 auth: no javascript
An ESLint plugin that enforces consistent folder naming conventions for JavaScript/JSX files using regular expressions. Current stable version is 1.0.4. The plugin provides a single rule `match-regex` that can be configured with a regex pattern and a root directory. It only lints folders containing `.js` or `.jsx` files processed by ESLint. Alternatives like `eslint-plugin-import` or `eslint-plugin-filenames` focus on filenames, not folder names. The plugin requires ESLint >=1.0.0 as a peer dependency.
Common errors
error Error: .eslintrc: Configuration for rule "folders/match-regex" is invalid ↓
cause The rule configuration format is wrong; typically the regex is not a string.
fix
Use an array: [severity, patternString, rootPath]. E.g., [2, "^[a-z]+$", "."].
error Error: Cannot find module 'eslint-plugin-folders' ↓
cause Plugin not installed as a dev dependency.
fix
Run: npm install eslint-plugin-folders --save-dev
error Parsing error: The keyword 'const' is reserved ↓
cause ESLint is not configured for ES6 syntax.
fix
Set parserOptions: { ecmaVersion: 6 } in .eslintrc or use a parser like babel-eslint.
Warnings
gotcha The plugin only lints folders of .js and .jsx files. Folders without JS/JSX files are ignored. ↓
fix Ensure each folder you want to lint contains at least one .js or .jsx file that ESLint processes.
gotcha The regex pattern is provided as a string without delimiters. E.g., '^[a-z_]+$' not '/^[a-z_]+$/'. ↓
fix Use plain regex string without surrounding slashes.
breaking ESLint >=1.0.0 required. Older versions may not load the plugin correctly. ↓
fix Upgrade ESLint to version 1.0.0 or later.
Install
npm install eslint-plugin-folders yarn add eslint-plugin-folders pnpm add eslint-plugin-folders Imports
- default wrong
import folders from 'eslint-plugin-folders'correctmodule.exports = { plugins: ['folders'], rules: { 'folders/match-regex': [2, '^[a-z_]+$', '/root/'] } }; - match-regex wrong
"folders/match-regex": [2, "/^[a-z_]+$/", "/root/"]correct"folders/match-regex": [2, "^[a-z_]+$", "/root/"] - RULES wrong
const { matchRegex } = require('eslint-plugin-folders');correctconst rules = require('eslint-plugin-folders').rules; console.log(Object.keys(rules));
Quickstart
// .eslintrc.json
{
"plugins": ["folders"],
"rules": {
"folders/match-regex": [2, "^[a-z_]+$", "."]
}
}
// This config enforces snake_case folder names in all folders below the root.
// To test, create a folder with a wrong name (e.g., 'MyFolder') containing a JS file.
// Run ESLint: npx eslint .
// You'll see an error like:
// error Folder 'MyFolder' doesn't match the pattern ^[a-z_]+$ folders/match-regex