Skip to content
← Back to rules

eslint/id-match Style

What it does ​

Enforces a naming convention for identifiers by requiring each checked name to match a configured regular expression.

Why is this bad? ​

Inconsistent identifier names make code harder to read and maintain.

This rule is most commonly used to enforce a project-wide convention such as camelCase, snake_case, or names without underscores.

The configured pattern is compiled with Rust regex syntax. Most common naming patterns work the same way as JavaScript regular expressions, but JavaScript-specific features such as lookaround assertions and backreferences are not supported. Unicode escapes also use Rust syntax, so \uXXXX should be written as \u{XXXX}.

Known differences from ESLint ​

  • Computed destructuring keys are checked in both binding and assignment patterns, for example const { [bad_name]: x } = obj and ({ [bad_name]: x } = obj). This still applies when ignoreDestructuring is enabled because the computed key is a normal reference expression, not a binding introduced by destructuring.
  • With properties enabled, ordinary top-level keys in dynamic import options are checked, for example import("x", { bad_option: true }). Import attributes inside with { ... } are still ignored.

These cases are intentionally stricter than ESLint because they still contain user-controlled identifier names that participate in normal code.

TypeScript syntax is supported on a best-effort basis for identifiers that flow through the same visited AST node kinds and transparent wrappers. This rule intentionally does not try to cover the full TypeScript naming surface.

Examples ​

Examples of incorrect code for this rule:

js
/* id-match: ["error", "^[^_]+$"] */
var first_name = "John";

/* id-match: ["error", "^[^_]+$", { "properties": true }] */
obj.first_name = "John";

Examples of correct code for this rule:

js
/* id-match: ["error", "^[^_]+$"] */
var firstName = "John";

/* id-match: ["error", "^[^_]+$", { "ignoreDestructuring": true }] */
const { first_name } = user;

Configuration ​

The 1st option ​

type: string

The 2nd option ​

This option is an object with the following properties:

classFields ​

type: boolean

default: false

Whether class field names are checked, including public fields, accessor properties, and private field names.

ignoreDestructuring ​

type: boolean

default: false

Whether to ignore shorthand and aliased bindings introduced by object destructuring, such as foo in const { foo } = obj and alias in const { foo: alias } = obj. This does not suppress computed key references such as const { [key]: value } = obj.

onlyDeclarations ​

type: boolean

default: false

Whether to check only variable and function declaration names. References, member names, labels, class names, TypeScript declarations, and function or arrow parameters are skipped.

properties ​

type: boolean

default: false

Whether object literal property names, class method names, and assigned member names such as obj.prop = value are checked.

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "id-match": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "id-match": "error",
  },
});
bash
oxlint --deny id-match

Version ​

This rule was added in v1.66.0.

References ​