sindresorhus/eslint-plugin-unicorn

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

已關閉

#1,098 建立於 2021年2月11日

 (8 則留言) (2 個反應) (0 位負責人)JavaScript (468 個分叉)user submission
help wantednew rule

倉庫指標

星標
 (5,022 顆星)
PR 合併指標
 (平均合併 1天 16小時) (30 天內合併 399 個 PR)

描述

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()
}

貢獻者指南