sindresorhus/eslint-plugin-unicorn

Rule proposal: `no-return-prototype-method`

Geschlossen

#1.098 geöffnet am 11.02.2021

 (8 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)JavaScript (468 Forks)user submission
help wantednew rule

Repository-Metriken

Stars
 (5.022 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 1T 16h) (399 gemergte PRs in 30 T)

Beschreibung

It's easy to forget actually calling a prototype method which leads to possibly hard-to-debug errors.

Since e.g. many array methods accept a callback or only an optional parameter, this could be handled with an allowlist per global object, e.g. Array.prototype.map wouldnt need to be checked for.

Fail

function foo(myString) {
  return string.slice(3).toLowerCase
}

function foo(myArr) {
  return myArr.map(val => val ** 2).reverse
}

Pass

function foo(myString) {
  return string.slice(3).toLowerCase()
}

function foo(myArr) {
  return myArr.map(val => val ** 2).reverse()
}

Contributor Guide