sindresorhus/eslint-plugin-unicorn

Rule proposal: fix trailing underscore

クローズ

#599 opened on 2020/03/12

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

Repository metrics

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

説明

Currently catch-error-name and prevent-abbreviations auto-fix may add _ to variables, like error_ to avoid syntax error. Main purpose of this rule is to remove unnessassary trailing underscore.

Run prevent-abbreviations against this code

const cur = 1;
const curr = 2;
const current = 3;

will fix to

const current_ = 1;
const current__ = 2;
const current = 3;

Someday, we decide not to use current anymore, so the tailing underscore of current_ and current__ become weird, we can have a rule to reorganize them.

Fail

const foo_ = 1;
const foo = 1;
const foo__ = 1;

Pass

const foo = 1;
const foo = 1;
const foo_ = 1;

Additionally maybe we can also fix trailing numbers, like

const array2 = [];
const array4 = [];

Should be

const array = [];
const array2 = [];

I don't have any idea about name of this rule, if it only work on _, we can have a funny name, because this rule should not disabled by anyone.

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