Plugin: conventionsRules
filename-case
Enforce filename case conventions for consistency across your codebase
Enforce filename case conventions for consistency across your codebase. This rule is part of eslint-plugin-conventions and provides LLM-optimized error messages with fix suggestions.
Quick Summary
| Aspect | Details |
|---|---|
| Severity | Warning (code quality) |
| Auto-Fix | ๐ก Suggests fixes (requires manual file rename) |
| Category | Quality |
| ESLint MCP | โ Optimized for ESLint MCP integration |
| Best For | Teams wanting consistent filename conventions across the codebase |
Rule Details
Why This Matters
| Issue | Impact | Solution |
|---|---|---|
| ๐จ Consistency | Mixed naming styles in codebase | Enforce single convention |
| ๐ Discoverability | Hard to find files | Predictable naming |
| ๐ Cross-platform | Case sensitivity issues | Use lowercase conventions |
| ๐ค Team Alignment | Disagreements on style | Automated enforcement |
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
case | string | 'kebabCase' | Case convention: camelCase, kebabCase, pascalCase, snakeCase |
ignore | array | [] | Basenames (exact strings) or RegExps to ignore completely |
allowedUppercaseFiles | string[] | ['README', 'LICENSE', 'CHANGELOG', ...] | Uppercase filenames allowed without extension |
allowedKebabCase | string[] | [] | Specific files allowed to use kebab-case |
allowedSnakeCase | string[] | [] | Specific files allowed to use snake_case |
allowedCamelCase | string[] | [] | Specific files allowed to use camelCase |
allowedPascalCase | string[] | [] | Specific files allowed to use PascalCase |
Case Style Reference
| Case Style | Pattern | Example |
|---|---|---|
kebabCase | lowercase-words | user-service.ts |
camelCase | camelCaseWords | userService.ts |
PascalCase | PascalCaseWords | UserService.ts |
snake_case | lowercase_words | user_service.ts |
Examples
โ Incorrect (with kebabCase)
src/
UserService.ts โ Should be user-service.ts
myComponent.tsx โ Should be my-component.tsx
API_Handler.ts โ Should be api-handler.tsโ
Correct (with kebabCase)
src/
user-service.ts โ
kebab-case
user.ts โ
a single lowercase word conforms to kebab, camel and snake
user-service.test.ts โ
.test / .spec / .stories / .story / .e2e / .d suffixes are not part of the name
README.md โ
conventional uppercase file (allowedUppercaseFiles)
.eslintrc.js โ
dotfiles are not checkedConfiguration Examples
Basic Usage (Default kebab-case)
{
rules: {
'conventions/filename-case': 'error'
}
}PascalCase for React Components
{
rules: {
'conventions/filename-case': ['error', {
case: 'pascalCase',
allowedKebabCase: ['index', 'main']
}]
}
}Mixed Convention with Overrides
{
rules: {
'conventions/filename-case': ['error', {
case: 'kebabCase',
allowedPascalCase: ['App', 'Button', 'Modal'], // React components
allowedSnakeCase: ['db_migrations'], // Legacy
ignore: [/\.config\./] // Config files
}]
}
}Disable Default Uppercase Files
{
rules: {
'conventions/filename-case': ['error', {
case: 'kebabCase',
allowedUppercaseFiles: [] // Disable all uppercase exceptions
}]
}
}When Not To Use
| Scenario | Recommendation |
|---|---|
| ๐๏ธ Legacy codebase | Use ignore for existing files |
| โ๏ธ React components | Consider pascalCase or add to allowedPascalCase |
| ๐งช Test files | Usually follows source file convention |
| ๐ฆ Generated files | Add to ignore patterns |
Comparison with Alternatives
| Feature | filename-case | eslint-plugin-unicorn | Manual enforcement |
|---|---|---|---|
| Multiple cases | โ 4 options | โ Yes | โ No |
| Per-file override | โ Flexible | โ ๏ธ Limited | โ No |
| LLM-Optimized | โ Yes | โ No | โ No |
| ESLint MCP | โ Optimized | โ No | โ No |
Related Rules
enforce-naming- Enforces domain-specific naming conventionsno-internal-modules- Enforces module boundaries
Further Reading
- Naming Conventions - Google TypeScript Style Guide
- eslint-plugin-unicorn filename-case - Unicorn's implementation
- ESLint MCP Setup - Enable AI assistant integration
Known Limitations
- A name with several dot-separated parts (
user.controller.ts,vitest.config.ts) is checked as one name, dots included, so it conforms to no case; add such names toignore. - An
allowed<Case>Caseentry exempts a name only when the name is written in that case.
Use this rule
npm install -D oxlint-plugin-conventions{ "jsPlugins": ["oxlint-plugin-conventions"], "rules": { "conventions/filename-case": "error" }}import { defineConfig } from 'vite-plus';export default defineConfig({ lint: { jsPlugins: ['oxlint-plugin-conventions'], rules: { 'conventions/filename-case': 'error', }, },});oxlint-plugin-conventions re-exports eslint-plugin-conventions/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.
Did this rule catch something? Star the repo to get new CWE coverage as we ship it โ or follow the AI-code-security benchmarks behind these rules.