eslint-plugin-unicorn icon indicating copy to clipboard operation
eslint-plugin-unicorn copied to clipboard

Show exact solutions to incorrect code in the documentation

Open fregante opened this issue 2 years ago • 5 comments

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)) {

fregante avatar Mar 19 '22 05:03 fregante

We just borrowed ESLint's docs style, but I agree, it's been sometimes bothering me too.

sindresorhus avatar Mar 19 '22 08:03 sindresorhus

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

fregante avatar Mar 19 '22 08:03 fregante

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 = ''; // ✅

sindresorhus avatar Sep 22 '22 11:09 sindresorhus

What do you think about live lint result like this? https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-contradiction-with-assertion.html

fisker avatar Sep 22 '22 12:09 fisker

I think that's unrelated. Live rules or not, even with autofix you'd want to see what's the suggested solution.

fregante avatar Sep 22 '22 13:09 fregante