sindresorhus/eslint-plugin-unicorn

Rule proposal: fix trailing underscore

Chiusa

#599 aperta il 12 mar 2020

 (3 commenti) (0 reazioni) (0 assegnatari)JavaScript (468 fork)user submission
help wantednew rule

Metriche repository

Star
 (5022 stelle)
Metriche merge PR
 (Merge medio 4h 30m) (26 PR mergiate in 30 g)

Descrizione

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.

Guida contributor