eslint-plugin-folder-name-convention
Version:
ESLint plugin to enforce folder naming conventions (kebab-case, camelCase, etc.)
109 lines (78 loc) โข 2.54 kB
Markdown
# ๐ 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