You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a.length===0// vsa.length<1// not sure I've ever seen this one TBHa.length!==0// vsa.length>0// vsa.length>=1// + some I might have forgotten
It could be nice to be able to specify how you want your comparisons to be made, and make that consistent across your project.
I'm not sure what the options would look like. At the top of my head, I'm thinking:
{
"unicorn/explicit-length-check": ["error", {
"empty": ["eq", 0] | ["lt", 1], // one or the other"not-empty": ["ne", 0] | ["gt", 0] | ["gte", 1]
}]
}
Should one be omitted (empty for instance), then you'd simply get no errors reports on how that one gets checked (both a.length < 1a.length === 0 would be fine).
This sounds pretty complicated at the moment (especially if we want to support == too), so I'm not too fond of it at the moment, especially it would not make sense to have empty: ["equal", 1200] as the config. Maybe we could simplify it to
and then we have predefined values associated to each of those operators. We could also have longer names for the operators, but you'd then get greater-than-or-equal (which is okay, but pretty long).
I'm kind of proposing this system so that we could have the same system for a different rule checking the indexOf uses. It might be nice to think of a similar "API" for it.
Oh, and obviously, this should not report any check for specific indices: a.length === 2 and a.length == 2 should always be fine, whatever the settings may be.
The text was updated successfully, but these errors were encountered:
sindresorhus
changed the title
Add an option for how to check the length object
Enforce length check style in the explicit-length-check rule
Oct 19, 2016
explicit-length-check
checks thatlength
properties get compared to a value instead of checking the truthiness of the property.In avajs/eslint-plugin-ava#149 (review), we remembered that there are some opinions on how that value then gets compared 😅
For instance:
It could be nice to be able to specify how you want your comparisons to be made, and make that consistent across your project.
I'm not sure what the options would look like. At the top of my head, I'm thinking:
Should one be omitted (
empty
for instance), then you'd simply get no errors reports on how that one gets checked (botha.length < 1
a.length === 0
would be fine).This sounds pretty complicated at the moment (especially if we want to support
==
too), so I'm not too fond of it at the moment, especially it would not make sense to haveempty: ["equal", 1200]
as the config. Maybe we could simplify it toand then we have predefined values associated to each of those operators. We could also have longer names for the operators, but you'd then get
greater-than-or-equal
(which is okay, but pretty long).I'm kind of proposing this system so that we could have the same system for a different rule checking the
indexOf
uses. It might be nice to think of a similar "API" for it.Oh, and obviously, this should not report any check for specific indices:
a.length === 2
anda.length == 2
should always be fine, whatever the settings may be.The text was updated successfully, but these errors were encountered: