sindresorhus/eslint-plugin-unicorn

Rule proposal: `no-improper-camelcase`

クローズ

#427 opened on 2019/10/29

 (3 件のコメント) (4 件のリアクション) (0 人の担当者)JavaScript (468 件のフォーク)user submission
help wantednew rule

Repository metrics

Stars
 (5,022 個のスター)
PR merge metrics
 (平均マージ 4h 30m) (30d で 26 merged PRs)

説明

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.

コントリビューターガイド