Versions

no-dupe-args

Disallow duplicate arguments in function definitions

Recommended

The "extends": "eslint:recommended" property in a configuration file enables this rule

如果在一个函数定义中,有一个以上的参数有相同的名称,那么最后出现的参数会“影射”前面的参数。重复的名称可能是笔误。

规则细节

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

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

使用此规则的错误示例:

Open in Playground
/*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);
};

使用此规则的正确示例:

Open in Playground
/*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);
};

Handled by TypeScript

It is safe to disable this rule when using TypeScript because TypeScript's compiler enforces this check.

Version

This rule was introduced in ESLint v0.16.0.

Resources

更改语言