π Require identifiers to match a specified regular expression.
π« Disabled by default.
This rule is the same as the built-in ESLint id-match rule, but with an additional checkNamedSpecifiers option.
Enforcing an identifier pattern prevents names from drifting from a project's naming convention while keeping that convention configurable.
This rule replaces ESLint's built-in id-match rule, which Unicorn presets disable when this rule is enabled.
/* eslint unicorn/id-match: ["error", "^[a-z]+$"] */
// β
const foo$ = 1;
// β
const foo = 1;In CSS, the rule checks class and ID selectors, custom properties, keyframes, animation names, layers, containers, and custom media. Dotted layer segments are checked separately. CSS escapes are decoded, and leading -- is excluded when matching custom-property and custom-media names. Built-in value keywords and animation shorthand values are skipped.
In HTML, it checks id and individual class names after decoding character references, retaining any leading --. Empty or templated values are skipped. Character references make diagnostics span the whole attribute value. JavaScript-only options do not apply to CSS or HTML. Names have no autofix because references elsewhere may need updating.
This rule supports the same options as ESLint id-match.
Set properties to true to check object and member property names.
Set classFields to true to check class field names.
Set onlyDeclarations to true to only check declared identifiers.
Set ignoreDestructuring to true to ignore identifiers in destructuring patterns.
Set checkNamedSpecifiers to false to ignore named import specifiers and external named export specifiers:
/* eslint unicorn/id-match: ["error", "^[a-z]+$", {"checkNamedSpecifiers": false}] */
// β
import {foo$} from 'module';
// β
export {foo$} from 'module';Only named import specifiers and external named export specifiers are ignored. Default imports, namespace imports, namespace re-exports, local export specifiers, and later references to imported bindings are still checked:
/* eslint unicorn/id-match: ["error", "^[a-z]+$", {"checkNamedSpecifiers": false}] */
// β
import foo$ from 'module';
// β
import * as foo$ from 'module';
// β
export * as foo$ from 'module';
// β
const foo = 1;
export {foo as bar$};
// β
import {bar$} from 'module';
// β
const foo = bar$;