sindresorhus/eslint-plugin-unicorn

Rule proposal: `no-improper-camelcase`

Closed

#427 opened on Oct 29, 2019

 (3 comments) (4 reactions) (0 assignees)JavaScript (468 forks)user submission
help wantednew rule

Repository metrics

Stars
 (5,022 stars)
PR merge metrics
 (Avg merge 1d 16h) (399 merged PRs in 30d)

Description

This rule would fail when the constituent part of closed-form compound words are capitalised.

Fail

function unSubscribe() {}
let passWord;
let isInViewPort;

Pass

function unsubscribe() {}
let password;
let isInViewport;

Problem statement

Compound words are formed by joining together two or more other words. Closed-form compound words do that without a hyphen/space. They are words in their own right, and should be treated as such when applying programming casing conventions.

Time and again I see these words incorrectly treated as separate words for the purpose of camelCase. This causes the following problems:

  • confusion and bugs when code using one form interacts with code using the other form
  • spread of incorrect form throughout codebase in the name of consistency
  • personal aggrevation

Examples

Standalone: callBack, dataBase, fileName, lookUp, offLine, onLine, overRide, passWord, payLoad, placeHolder, preView, setUp, unSubscribe, userName, viewPort, weekEnd

Combined: isInViewPort, showPreView, isOnLine

Some of these are arguably OK, others are definitely not.

Existing solutions

The ESLint rule id-blacklist can be configured to disallow a list of identifiers. It has some limitations (by design) which make it less than ideal for this problem:

  1. Only works on complete names, i.e. would not detect isInViewPort
  2. ESLint rule options configured in a shareable config cannot be extended/merged by an extending config; the entire options object must be copied into the extending config.

Contributor guide