Skip to content

Commit

Permalink
Update: max-params to only highlight function header (#10815)
Browse files Browse the repository at this point in the history
Update the max-params rule to only report the location of the method header. Some tools, like Nuclide, will otherwise highlight the entire body of the method, which makes the rule visually noisy in practice.

Test plan:

npm test
  • Loading branch information
ianobermiller authored and ilyavolodin committed Aug 31, 2018
1 parent 2b2f11d commit b61d2cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/max-params.js
Expand Up @@ -53,7 +53,7 @@ module.exports = {
},

create(context) {

const sourceCode = context.getSourceCode();
const option = context.options[0];
let numParams = 3;

Expand All @@ -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: {
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/max-params.js
Expand Up @@ -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
}]
}
]
});

0 comments on commit b61d2cd

Please sign in to comment.