eslint-plugin-naming-vocabulary
v1.0.0
Published
ESLint plugin to enforce consistent identifier vocabulary — boolean prefixes, synonym canonicalization, and domain-scoped naming
Maintainers
Readme
eslint-plugin-naming-vocabulary
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
// eslint.config.mjs
import namingVocabulary from 'eslint-plugin-naming-vocabulary';
const GROUPS = [
{ name: 'get', canonical: 'get', forbidden: ['fetch', 'load', 'retrieve'] },
];
export default [
{
plugins: { 'naming-vocabulary': namingVocabulary },
settings: { 'naming-vocabulary': { groups: GROUPS } },
rules: {
'naming-vocabulary/boolean-prefix': 'warn',
'naming-vocabulary/synonym-canonical': ['warn', { groups: GROUPS }],
'naming-vocabulary/mixed-synonym-usage': ['warn', { groups: GROUPS }],
},
},
];Or use the recommended config (enables boolean-prefix only):
import namingVocabulary from 'eslint-plugin-naming-vocabulary';
export default [namingVocabulary.configs.recommended];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 are safe (never auto-applied): use your editor's Quick Fix menu.
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 ≥ 18
- ESLint ≥ 8.0.0
License
MIT
