sindresorhus/eslint-plugin-unicorn

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

Open

#1,098 创建于 2021年2月11日

在 GitHub 查看
 (8 评论) (2 反应) (0 负责人)JavaScript (5,022 star) (468 fork)user submission
help wantednew rule

描述

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

贡献者指南