Skip to content

feat: add hs-web-team/no-abbreviations rule - #66

Open
davidding wants to merge 2 commits into
mainfrom
feature/no-abbreviations-rule
Open

feat: add hs-web-team/no-abbreviations rule#66
davidding wants to merge 2 commits into
mainfrom
feature/no-abbreviations-rule

Conversation

@davidding

@davidding davidding commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🤖 AI-assisted draft — human review required

Summary

Adds a new hs-web-team/no-abbreviations ESLint rule to the custom plugin, enforcing the HubSpot JS coding standard to avoid abbreviations.

Motivated by const w = await lintRule(...) flagged in hs-components PR #1651.

What it flags

Any identifier shorter than minLength (default: 2) at a declaration site — variable declarators, function params, arrow params, array destructuring bindings, and function declaration names.

const w = [];            // ❌ too short
items.map(w => w.id);   // ❌ too short
function process(w) {}  // ❌ too short
const [w] = items;      // ❌ too short
function w() {}         // ❌ too short

Object destructuring shorthand (const { w } = response) is intentionally not flagged — w may be an external API property name the developer does not own. The idiomatic fix is const { w: warning } = response, which is correct but non-obvious enough to leave opt-in.

Exemptions (AST-aware, not a flat list)

Name Exempt where
e, _ Anywhere (event handler / intentionally unused — default exceptions)
a, b Params of .sort() / .toSorted() callbacks only
i Position 1 (index slot) in array iteration callbacks (.map, .forEach, .filter, .find, .some, .every, .flatMap, …)
for-loop vars Any variable declared in a for/for...of/for...in init
arr.sort((a, b) => a - b);           // ✅ sort comparator
items.map((item, i) => [item, i]);   // ✅ index param
for (let i = 0; i < n; i++) {}      // ✅ for-loop init

Note: a and b are only exempt inside inline .sort()/.toSorted() callbacks. Named comparator functions (function compare(a, b) {}) are flagged — prefer (left, right) or (prev, next).

Configuration

// options: { exceptions?: string[], minLength?: number }
'hs-web-team/no-abbreviations': ['warn', { minLength: 2, exceptions: ['cb'] }]

Roll-out

Added to configs.recommended at 'warn' — enabled by default for all consumers of this package. No action needed beyond bumping the version.

To override severity or add exceptions in a project:

import { hsWebTeamPlugin } from '@hs-web-team/eslint-config-node/plugin';

export default [
  ...wtConfig,
  {
    plugins: { 'hs-web-team': hsWebTeamPlugin },
    rules: { 'hs-web-team/no-abbreviations': ['error', { exceptions: ['cb'] }] },
  },
];

Changes

  • plugins/hs-web-team/rules/no-abbreviations.js — new rule (array destructuring + function declaration names covered; reduce/reduceRight excluded from iteration method exemption)
  • plugins/hs-web-team/index.js — registers rule in plugin and adds to configs.recommended at 'warn'
  • package.json — adds ./plugin export for direct plugin access
  • tests/plugins/hs-web-team/no-abbreviations.test.js — 27 passing tests (16 valid, 11 invalid cases)

🤖 Generated with Claude Code

- Add to configs.recommended at 'warn'
- Expand declaration sites: array destructuring, function declaration names
- Remove reduce/reduceRight from ARRAY_ITERATION_METHODS (false i exemption)
- Flip rule meta recommended: false -> true
- Add ./plugin export to package.json
- Add tests for new declaration sites; document object destructuring skip
- Add warn=minor / error=major versioning convention to CLAUDE.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant