sindresorhus/eslint-plugin-unicorn
Rule proposal: `no-return-array-push`
Fechada
#1.487 aberto em 16 de ago. de 2021
help wantednew rule
Métricas do repositório
- Stars
- (5.022 estrelas)
- Métricas de merge de PR
- (Mesclagem média 4h 30m) (26 fundiu PRs em 30d)
Description
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);
}