eslint-plugin-unicorn
eslint-plugin-unicorn copied to clipboard
Show exact solutions to incorrect code in the documentation
The documentation shows good and bad examples in two large blocks, but this means that finding the right way to do things takes longer than necessary. I'd suggest this format:
❌ if (Object.is(foo, NaN)) {}
✅if (Object.is(foo, Number.NaN)) {}
❌ isNan(1)
✅ Number.isNaN(1)
⚠️ These are not equivalent, you might want this instead:
✅ if (typeof numberOrIdk !== number || Number.isNaN(numberOrIdk)) {
We just borrowed ESLint's docs style, but I agree, it's been sometimes bothering me too.
Oh yeah I mentioned that in the other issue and forgot it here.
This is not Unicorn’s fault as ESLint’s docs are equally lacking
I think the code should be valid though.
How about this?
Blocks
// ❌
if (Object.is(foo, NaN)) {}
// ✅
if (Object.is(foo, Number.NaN)) {}
Single-line
var foo = ''; // ❌
const foo = ''; // ✅
What do you think about live lint result like this? https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-contradiction-with-assertion.html
I think that's unrelated. Live rules or not, even with autofix you'd want to see what's the suggested solution.