sindresorhus / eslint-plugin-unicorn

More than 100 powerful ESLint rules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option proposal: `explicit-length-check`: provide option to invert to require implicit length check

abrahamguo opened this issue · comments

Description

In my own projects, I borrowed a lot of the logic from explicit-length-check to create an autofixable rule requiring the opposite — converting all styles of explicit length checks into implicit length checks (i.e. .length and !...length). I did this because I find the more concise checks to be more readable, and I do not feel there is any danger or downside of using this style.

Would you be interested in me porting my custom rule into explicit-length-check as an option — maybe { "style": "implicit" | "explicit" }? Or do you view this as a bad/minority practice that you wouldn't want to encourage?

Fail

const isEmpty = foo.length === 0;
const isFilled = foo.length > 0;
const isEmpty = foo.length == 0;
// ...and all the other styles already matched by explicit-length-check

Pass

const isEmpty = !foo.length;
const isFilled = foo.length;

Additional Info

No response

I appreciate the suggestion, but it's not something we would want to encourage.