kebab-case-filenames
Enforce consistent file naming conventions across source directories.
Rule details
Section titled “Rule details”Inconsistent file naming (mixing camelCase, PascalCase, snake_case, and kebab-case) makes files harder to find and causes case-sensitivity issues across operating systems. This rule validates every scoped file name against a regex pattern and suggests corrections.
Examples of incorrect code
Section titled “Examples of incorrect code”src/ helpers/ pathUtils.ts ← camelCase Git_Helper.ts ← PascalCase + snake_case ADRWriter.ts ← PascalCaseExamples of correct code
Section titled “Examples of correct code”src/ helpers/ path-utils.ts git-helper.ts adr-writer.tsRule implementation
Section titled “Rule implementation”/// <reference path="../rules.d.ts" />import { basename } from "node:path";
const KEBAB_CASE = /^[a-z][a-z0-9]*(-[a-z0-9]+)*\.(ts|tsx|js|jsx)$/;
export default { rules: { "kebab-case-filenames": { description: "Source files must use kebab-case naming", async check(ctx) { for (const file of ctx.scopedFiles) { const name = basename(file);
// Skip test files and type declaration files if (name.endsWith(".test.ts") || name.endsWith(".d.ts")) continue;
if (!KEBAB_CASE.test(name)) { ctx.report.violation({ message: `File "${name}" does not follow kebab-case naming convention`, file, fix: `Rename to ${name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()}`, }); } } }, }, },} satisfies RuleSet;When to use it
Section titled “When to use it”When your team has standardized on a naming convention and wants to enforce it automatically. Adapt the regex for your convention:
// PascalCase (React components)const PASCAL_CASE = /^[A-Z][a-zA-Z0-9]*\.(ts|tsx)$/;
// camelCaseconst CAMEL_CASE = /^[a-z][a-zA-Z0-9]*\.(ts|tsx|js|jsx)$/;
// snake_case (Python-style)const SNAKE_CASE = /^[a-z][a-z0-9]*(_[a-z0-9]+)*\.(ts|tsx|js|jsx)$/;When not to use it
Section titled “When not to use it”When your project intentionally mixes naming conventions (e.g., PascalCase for React components and kebab-case for utilities), or when migrating a legacy codebase where bulk renames are not feasible.