ESLint InterlaceESLint Interlace
Plugin: conventionsRules

filename-case

ESLint rule documentation for filename-case

๐Ÿ“ก Live from GitHub โ€” This documentation is fetched directly from filename-case.md and cached for 6 hours.

Keywords: filename, naming convention, case style, kebab-case, camelCase, PascalCase, snake_case, ESLint rule, code consistency, LLM-optimized

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

AspectDetails
SeverityWarning (code quality)
Auto-Fix๐Ÿ’ก Suggests fixes (requires manual file rename)
CategoryQuality
ESLint MCPโœ… Optimized for ESLint MCP integration
Best ForTeams wanting consistent filename conventions across the codebase

Rule Details

Why This Matters

IssueImpactSolution
๐ŸŽจ ConsistencyMixed naming styles in codebaseEnforce single convention
๐Ÿ“ DiscoverabilityHard to find filesPredictable naming
๐Ÿ”„ Cross-platformCase sensitivity issuesUse lowercase conventions
๐Ÿค Team AlignmentDisagreements on styleAutomated enforcement

Configuration

OptionTypeDefaultDescription
casestring'kebabCase'Case convention: camelCase, kebabCase, pascalCase, snakeCase
ignorearray[]Patterns to ignore completely
allowedUppercaseFilesstring[]['README', 'LICENSE', 'CHANGELOG', ...]Uppercase filenames allowed without extension
allowedKebabCasestring[][]Specific files allowed to use kebab-case
allowedSnakeCasestring[][]Specific files allowed to use snake_case
allowedCamelCasestring[][]Specific files allowed to use camelCase
allowedPascalCasestring[][]Specific files allowed to use PascalCase

Case Style Reference

Case StylePatternExample
kebabCaselowercase-wordsuser-service.ts
camelCasecamelCaseWordsuserService.ts
PascalCasePascalCaseWordsUserService.ts
snake_caselowercase_wordsuser_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       โœ…
  my-component.tsx      โœ…
  api-handler.ts        โœ…
  README.md             โœ… (allowed uppercase)
  LICENSE               โœ… (allowed uppercase)

Configuration Examples

Basic Usage (Default kebab-case)

{
  rules: {
    'architecture/filename-case': 'error'
  }
}

PascalCase for React Components

{
  rules: {
    'architecture/filename-case': ['error', {
      case: 'pascalCase',
      allowedKebabCase: ['index', 'main']
    }]
  }
}

Mixed Convention with Overrides

{
  rules: {
    'architecture/filename-case': ['error', {
      case: 'kebabCase',
      allowedPascalCase: ['App', 'Button', 'Modal'],  // React components
      allowedSnakeCase: ['db_migrations'],            // Legacy
      ignore: [/\.config\./]                          // Config files
    }]
  }
}

Disable Default Uppercase Files

{
  rules: {
    'architecture/filename-case': ['error', {
      case: 'kebabCase',
      allowedUppercaseFiles: []  // Disable all uppercase exceptions
    }]
  }
}

When Not To Use

ScenarioRecommendation
๐Ÿ›๏ธ Legacy codebaseUse ignore for existing files
โš›๏ธ React componentsConsider pascalCase or add to allowedPascalCase
๐Ÿงช Test filesUsually follows source file convention
๐Ÿ“ฆ Generated filesAdd to ignore patterns

Comparison with Alternatives

Featurefilename-caseeslint-plugin-unicornManual enforcement
Multiple casesโœ… 4 optionsโœ… YesโŒ No
Per-file overrideโœ… Flexibleโš ๏ธ LimitedโŒ No
LLM-Optimizedโœ… YesโŒ NoโŒ No
ESLint MCPโœ… OptimizedโŒ NoโŒ No

Further Reading

Known False Negatives

The following patterns are not detected due to static analysis limitations:

Dynamic Variable References

Why: Static analysis cannot trace values stored in variables or passed through function parameters.

// โŒ NOT DETECTED - Value from variable
const value = externalSource();
processValue(value); // Variable origin not tracked

Mitigation: Implement runtime validation and review code manually. Consider using TypeScript branded types for validated inputs.

Imported Values

Why: When values come from imports, the rule cannot analyze their origin or construction.

// โŒ NOT DETECTED - Value from import
import { getValue } from './helpers';
processValue(getValue()); // Cross-file not tracked

Mitigation: Ensure imported values follow the same constraints. Use TypeScript for type safety.

On this page

No Headings