UNPKG

eslint-plugin-folder-name-convention

Version:

ESLint plugin to enforce folder naming conventions (kebab-case, camelCase, etc.)

109 lines (78 loc) โ€ข 2.54 kB
# ๐Ÿ“ eslint-plugin-folder-name-convention > ๐Ÿ” An ESLint plugin to enforce consistent folder naming conventions like `kebab-case`, `camelCase`, `PascalCase`, and more. --- ## ๐Ÿ“ฆ Installation ```bash npm install eslint-plugin-folder-name-convention --save-dev ``` --- ## โš™๏ธ Configuration Add the plugin and rule to your ESLint config: ```js // eslint.config.js const pluginFolderName = require('eslint-plugin-folder-name-convention'); const path = require('path'); /** @type {import("eslint").FlatConfig[]} */ module.exports = [ { files: ['**/*.js', '**/*.ts'], plugins: { 'folder-name-convention': pluginFolderName, }, rules: { 'folder-name-convention/enforce': [ 'error', { pattern: 'kebab-case', rootDir: path.resolve(__dirname), // Ensures project root only ignore: ['node_modules', '.git'], }, ], }, }, ]; npx eslint . --config eslint.config.js ``` --- ## ๐Ÿ”ง Rule Options | Option | Type | Default | Description | |------------|------------|---------------|-----------------------------------------------------------------------------| | `pattern` | `string` | `"kebab-case"`| Allowed values: `kebab-case`, `camelCase`, `PascalCase`, `snake_case`, or a custom RegExp | | `ignore` | `string[]` | `[]` | Folder names to ignore (supports RegExp if wrapped in `/.../`) | | `rootDir` | `string` | `"."` | Directory from which to begin folder checks | --- ## โœ… Supported Patterns | Pattern | Example | |---------------|-------------------| | `kebab-case` | `user-profile/` | | `camelCase` | `userProfile/` | | `PascalCase` | `UserProfile/` | | `snake_case` | `user_profile/` | | `/regex/` | `/^prefix-[a-z]+$/` | --- ## ๐Ÿงช Example Project Structure ```txt root/ โ”œโ”€โ”€ user-profile/ โœ… valid (kebab-case) โ”œโ”€โ”€ utils/ โœ… valid โ”œโ”€โ”€ BadFolderName/ โŒ invalid (PascalCase) ``` ### ๐Ÿ”ด ESLint Error ```bash โŒ Folder name "BadFolderName" does not match pattern "kebab-case". ``` --- ## ๐ŸŽฏ Why Use This? - ๐Ÿงน Enforces consistent folder naming - ๐Ÿ› Prevents case-sensitive import bugs on UNIX systems - ๐Ÿค Improves project readability and maintainability --- Run ESLint: ```bash npx eslint . --config eslint.config.js OR npx eslint . ``` --- ## ๐Ÿ“œ License MIT ยฉ Raza