gtap-dev / javascript

JavaScript Style Guide
MIT License
0 stars 0 forks source link

15.7 and 22.6 - disallow hacky boolean conversion? #10

Closed mjomble closed 3 years ago

mjomble commented 3 years ago

15.7 lists this as a good example:

const bar = !!c;

and 22.6 considers the !! syntax better than the more explicit alternative:

// good
const hasAge = Boolean(age);

// best
const hasAge = !!age;

In my opinion, this syntax falls into a hacky category with other examples listen in the doc of ESLint's no-implicit-coercion rule.

I propose using this ESLint rule and disallowing the !! syntax.

Vladisls commented 3 years ago

I would suggest to continue using !! as Boolean would not introduce any benefits.

mihkeleidast commented 3 years ago

I generally feel that the double bang syntax is pretty explicit (in comparison to the ESLint naming of "no-implicit-coercion" rule). It's also shorter, so easier to write.

mjomble commented 3 years ago

Fair enough 🙂