sindresorhus/eslint-plugin-unicorn
Rule proposal: `no-return-array-push`
Chiusa
#1487 aperta il 16 ago 2021
help wantednew rule
Metriche repository
- Star
- (5022 stelle)
- Metriche merge PR
- (Merge medio 4h 30m) (26 PR mergiate in 30 g)
Descrizione
Array#push() returns the new length of the array, most time return array.push(foo) is a mistake.
Fail
function foo() {
return array.push(bar);
}
Pass
// If mean to return the length
function foo() {
return array.length + bar.length;
}
// If mean to push and exit
function foo() {
if (true) {
array.push(bar);
return;
}
// ...
}
// Have to use `eslint-disable`
function foo() {
// eslint-disable-next-line unicorn/no-return-array-push
return array.push(bar);
}