12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- "use strict";
- module.exports = {
- meta: {
- type: "problem",
- docs: {
- description: "Disallow duplicate arguments in `function` definitions",
- recommended: true,
- url: "https://eslint.org/docs/latest/rules/no-dupe-args"
- },
- schema: [],
- messages: {
- unexpected: "Duplicate param '{{name}}'."
- }
- },
- create(context) {
- const sourceCode = context.sourceCode;
-
-
-
-
- function isParameter(def) {
- return def.type === "Parameter";
- }
-
- function checkParams(node) {
- const variables = sourceCode.getDeclaredVariables(node);
- for (let i = 0; i < variables.length; ++i) {
- const variable = variables[i];
-
- const defs = variable.defs.filter(isParameter);
- if (defs.length >= 2) {
- context.report({
- node,
- messageId: "unexpected",
- data: { name: variable.name }
- });
- }
- }
- }
-
-
-
- return {
- FunctionDeclaration: checkParams,
- FunctionExpression: checkParams
- };
- }
- };
|