Skip to content

kebab-case-filenames

Enforce consistent file naming conventions across source directories.

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.

src/
helpers/
pathUtils.ts ← camelCase
Git_Helper.ts ← PascalCase + snake_case
ADRWriter.ts ← PascalCase
src/
helpers/
path-utils.ts
git-helper.ts
adr-writer.ts
/// <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 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)$/;
// camelCase
const 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 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.