Skip to content

naming-convention

Checks identifier names against the selectors and formats you configure.

This rule covers classes, interfaces, types, enums, variables, imports, parameters, members, and more. It works from the AST, so it stays fast and does not need full type-aware linting.

If you do not pass options, the default setup is:

  • default: camelCase, leading and trailing underscores allowed
  • import: camelCase or PascalCase
  • variable: camelCase or UPPER_CASE, leading and trailing underscores allowed
  • typeLike: PascalCase

The rule skips .d.ts files.

eslint.config.ts
import ceaseNonsense from "eslint-plugin-cease-nonsense";
export default [
{
plugins: {
"cease-nonsense": ceaseNonsense,
},
rules: {
"cease-nonsense/naming-convention": ["error",
{
selector: "interface",
format: ["PascalCase"],
},
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
],
},
},
];
OptionTypeWhat it does
selectorstring or string[]Picks which identifiers this config entry applies to
formatstring[] or nullAllowed formats, such as camelCase, PascalCase, strictCamelCase, StrictPascalCase, snake_case, or UPPER_CASE
filterstring or { regex, match }Limits which names the entry applies to
custom{ regex, match }Adds an extra regex rule after format checks
prefix / suffixstring[]Requires one of the listed prefixes or suffixes
leadingUnderscore / trailingUnderscorestringControls underscore usage with allow, allowDouble, allowSingleOrDouble, forbid, require, or requireDouble
modifiersstring[]Narrows by modifiers such as const, async, readonly, exported, unused, namespace, or requiresQuotes
typesstring[]Narrows supported selectors by simple type groups such as array, boolean, function, number, or string

selector supports both individual selectors like interface, typeAlias, enum, classMethod, typeProperty, and import, and meta selectors like default, typeLike, variableLike, property, method, memberLike, and accessor.

Incorrect
interface IFoo {}
const foo_bar = 1;
class widgetFactory {}
Correct
interface User {}
const userName = getUserName();
const MAX_RETRIES = 3;
class WidgetFactory {}
rule options
[
{
selector: "typeLike",
format: ["PascalCase"],
},
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
{
selector: "interface",
format: ["PascalCase"],
custom: { match: false, regex: "^I[A-Z]" },
},
]