diff --git a/lib/rules/max-params.js b/lib/rules/max-params.js index 902391b74ff..4089e8ae899 100644 --- a/lib/rules/max-params.js +++ b/lib/rules/max-params.js @@ -53,7 +53,7 @@ module.exports = { }, create(context) { - + const sourceCode = context.getSourceCode(); const option = context.options[0]; let numParams = 3; @@ -76,6 +76,7 @@ module.exports = { function checkFunction(node) { if (node.params.length > numParams) { context.report({ + loc: astUtils.getFunctionHeadLoc(node, sourceCode), node, message: "{{name}} has too many parameters ({{count}}). Maximum allowed is {{max}}.", data: { diff --git a/tests/lib/rules/max-params.js b/tests/lib/rules/max-params.js index 3cb47044f97..959f5d7b8e2 100644 --- a/tests/lib/rules/max-params.js +++ b/tests/lib/rules/max-params.js @@ -86,6 +86,20 @@ ruleTester.run("max-params", rule, { message: "Function 'test' has too many parameters (3). Maximum allowed is 2.", type: "FunctionDeclaration" }] + }, + + // Error location should not cover the entire function; just the name. + { + code: `function test(a, b, c) { + // Just to make it longer + }`, + options: [{ max: 2 }], + errors: [{ + line: 1, + column: 1, + endLine: 1, + endColumn: 14 + }] } ] });