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.

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.
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.
npm install eslint-plugin-folders
yarn add eslint-plugin-folders
pnpm add eslint-plugin-folders

Shows how to configure the match-regex rule in .eslintrc.json to enforce snake_case folder names.

// .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