eslint-plugin-naming-vocabulary
v1.1.0
Published
ESLint plugin to enforce consistent identifier vocabulary — boolean prefixes, synonym canonicalization, and domain-scoped naming
Maintainers
Readme
eslint-plugin-naming-vocabulary
한국어 | English
ESLint plugin that enforces consistent identifier vocabulary across your codebase — boolean prefixes, synonym canonicalization, and mixed-synonym detection.
Rules
| Rule | Description | Default |
|------|-------------|---------|
| boolean-prefix | Enforce is/has/can/… prefixes on boolean identifiers | warn |
| synonym-canonical | Flag forbidden synonym tokens and suggest the canonical term | off* |
| mixed-synonym-usage | Warn when a file uses multiple synonyms from the same group | off* |
*Requires user-defined vocabulary groups.
Installation
npm install --save-dev eslint-plugin-naming-vocabulary
# or
pnpm add -D eslint-plugin-naming-vocabulary
# or
yarn add --dev eslint-plugin-naming-vocabularyQuick start
Define your vocabulary groups once in settings — the synonym rules pick them up automatically:
// eslint.config.mjs
import namingVocabulary from 'eslint-plugin-naming-vocabulary';
export default [
{
plugins: { 'naming-vocabulary': namingVocabulary },
settings: {
'naming-vocabulary': {
groups: [
{ name: 'get', canonical: 'get', forbidden: ['fetch', 'load', 'retrieve'] },
],
},
},
rules: {
'naming-vocabulary/boolean-prefix': 'warn',
'naming-vocabulary/synonym-canonical': 'warn',
'naming-vocabulary/mixed-synonym-usage': 'warn',
},
},
];Groups can also be passed per rule via the groups option (inline array or { $ref: 'group-name' }) — see Shared vocabulary groups.
Or use the recommended config (enables boolean-prefix only):
import namingVocabulary from 'eslint-plugin-naming-vocabulary';
export default [namingVocabulary.configs.recommended];Note:
configs.recommendedis provided in flat config format only (eslint.config.js/.mjs). On legacy.eslintrc,extends: 'plugin:naming-vocabulary/recommended'is not supported — register the plugin and enable rules individually instead.
Rule details
boolean-prefix
Flags identifiers that hold boolean values without an allowed prefix.
// ✗ bad
const active = true;
const enabled = false;
// ✓ good
const isActive = true;
const hasPermission = false;Default allowed prefixes: is has can should will did needs may. Customize with allowedPrefixes.
synonym-canonical
Flags forbidden synonym tokens in identifier names and suggests the canonical replacement.
// ✗ bad — 'fetch' is forbidden, canonical is 'get'
const fetchUser = () => {};
// ✓ good
const getUser = () => {};Suggestions rename the declaration only (never auto-applied). Use a language-server rename refactor to update all references.
mixed-synonym-usage
Warns when the same file uses multiple synonyms from the same vocabulary group.
// ✗ bad — same file uses both 'fetch' and 'load' from the 'get' group
const fetchUser = () => {};
const loadSettings = () => {};Shared vocabulary groups
Define groups once and share them across rules via ESLint settings:
settings: {
'naming-vocabulary': {
groups: [
{ name: 'get', canonical: 'get', forbidden: ['fetch', 'load', 'retrieve'] },
{ name: 'create', canonical: 'create', forbidden: ['make', 'build', 'generate'] },
{ name: 'delete', canonical: 'delete', forbidden: ['remove', 'destroy', 'erase'] },
],
},
},Requirements
- Node.js ≥ 20
- ESLint ≥ 8.57.0
License
MIT
