Skip to content

naming-convention

SuggestionAST-only

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 "@pobammer-ts/eslint-cease-nonsense-rules";
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",
},
],
},
},
];
Option Type What it does
selector string or string[] Picks which identifiers this config entry applies to
format string[] or null Allowed formats, such as camelCase, PascalCase, strictCamelCase, StrictPascalCase, snake_case, or UPPER_CASE
filter string or { regex, match } Limits which names the entry applies to
custom { regex, match } Adds an extra regex rule after format checks
prefix / suffix string[] Requires one of the listed prefixes or suffixes
leadingUnderscore / trailingUnderscore string Controls underscore usage with allow, allowDouble, allowSingleOrDouble, forbid, require, or requireDouble
modifiers string[] Narrows by modifiers such as const, async, readonly, exported, unused, namespace, or requiresQuotes
types string[] 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]" },
},
]