sindresorhus/eslint-plugin-unicorn

Rule proposal: `better-boolean-var-name`

Chiusa

#2441 aperta il 1 set 2024

 (7 commenti) (1 reazione) (0 assegnatari)JavaScript (468 fork)user submission
help wantednew ruletypes

Metriche repository

Star
 (5022 stelle)
Metriche merge PR
 (Merge medio 1g 16h) (399 PR mergiate in 30 g)

Descrizione

Description

There are many irregular variable declarations in some Boolean variable declarations.

For example

const showingModal = false

This value is obviously a Boolean value, but it cannot be seen from the variable.

A better variable name can improve code readability

Boolean variables should start with 'is', 'was', 'has', 'can', 'should', etc.

Fail

const showingModal = false

const greatThen = a > b

const completed = progress === 100

const setProperty = key in object

const stringType = typeof input === 'string'

// ...

Pass

const isShowingModal = false

const isGreatThen = a > b

const isCompleted = progress === 100

const hasSetProperty = key in object

const isStringType = typeof input === 'string'

Proposed rule name

better-boolean-var-declaration

Additional Info

This rule has been implemented in my company project, it can't autofix, but it can provide suggestions. I think it is useful

If this is acceptable, I'd be happy to PR

https://github.com/user-attachments/assets/c6bbccea-5efc-4fc5-8beb-3fb2fb0e1bd9

Guida contributor