no-dupe-args
禁止 function 定义中的重复参数
在 配置文件 中使用来自 @eslint/js 的 recommended 配置可以启用此规则
如果在函数定义中有多个参数具有相同的名称,最后出现的那个会“遮蔽”之前的出现。重复的名称可能是打字错误。
🌐 If more than one parameter has the same name in a function definition, the last occurrence “shadows” the preceding occurrences. A duplicated name might be a typing error.
规则详情
🌐 Rule Details
此规则不允许在函数声明或表达式中使用重复的参数名称。它不适用于箭头函数或类方法,因为解析器会报告错误。
🌐 This rule disallows duplicate parameter names in function declarations or expressions. It does not apply to arrow functions or class methods, because the parser reports the error.
如果 ESLint 在严格模式下解析代码,解析器(而不是这个规则)会报告错误。
🌐 If ESLint parses code in strict mode, the parser (instead of this rule) reports the error.
此规则的错误代码示例:
🌐 Examples of incorrect code for this rule:
/*eslint no-dupe-args: "error"*/
function foo(a, b, a) {
console.log("value of the second a:", a);
}
const bar = function (a, b, a) {
console.log("value of the second a:", a);
};
符合此规则的正确代码示例:
🌐 Examples of correct code for this rule:
/*eslint no-dupe-args: "error"*/
function foo(a, b, c) {
console.log(a, b, c);
}
const bar = function (a, b, c) {
console.log(a, b, c);
};
选项
🌐 Options
此规则没有选项。
🌐 This rule has no options.
由 TypeScript 处理
使用 TypeScript 时禁用此规则是安全的,因为 TypeScript 的编译器强制执行此检查。
版本
此规则是在 ESLint v0.16.0 中引入。