Eslint
规则 | Rules

no-dupe-args

在function定义中不允许重复的参数(no-dupe-args)

配置文件中的"extends": "eslint:recommended"属性启用此规则。

如果在一个函数定义中有多个参数具有相同的名称,则最后一个匹配项会“遮蔽”前面的匹配项。重复的名称可能是打字错误。

规则细节

此规则不允许在函数声明或表达式中使用重复的参数名称。它不适用于箭头函数或类方法,因为解析器报告错误。

如果 ESLint 在严格模式下解析代码,解析器(而不是此规则)会报告错误。

此规则的错误代码示例:

/*eslint no-dupe-args: "error"*/ function foo(a, b, a) { console.log("value of the second a:", a } var bar = function (a, b, a) { console.log("value of the second a:", a };

此规则的正确代码示例:

/*eslint no-dupe-args: "error"*/ function foo(a, b, c) { console.log(a, b, c } var bar = function (a, b, c) { console.log(a, b, c };

版本

该规则在 ESLint 0.16.0中引入。

资源