Skip to content

Commit

Permalink
fix: revert changes to reported locations in max-lines-per-function (#…
Browse files Browse the repository at this point in the history
…15397)

Revert "feat: report only lines that exceed the limit in max-lines-per-function (#15140)"

This reverts commit 8f44cf5.
  • Loading branch information
mdjermanovic committed Dec 7, 2021
1 parent fa4d483 commit 234e3d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 227 deletions.
22 changes: 2 additions & 20 deletions lib/rules/max-lines-per-function.js
Expand Up @@ -80,7 +80,7 @@ module.exports = {
OPTIONS_OR_INTEGER_SCHEMA
],
messages: {
exceed: "{{name}} has exceeded the limit of lines allowed by {{linesExceed}}. Maximum allowed number of lines per function is {{maxLines}}."
exceed: "{{name}} has too many lines ({{lineCount}}). Maximum allowed is {{maxLines}}."
}
},

Expand Down Expand Up @@ -170,26 +170,18 @@ module.exports = {
return;
}
let lineCount = 0;
let comments = 0;
let blankLines = 0;

for (let i = node.loc.start.line - 1; i < node.loc.end.line; ++i) {
const line = lines[i];

if (skipComments) {
if (commentLineNumbers.has(i + 1) && isFullLineComment(line, i + 1, commentLineNumbers.get(i + 1))) {
if (lineCount <= maxLines) {
comments++;
}
continue;
}
}

if (skipBlankLines) {
if (line.match(/^\s*$/u)) {
if (lineCount <= maxLines) {
blankLines++;
}
continue;
}
}
Expand All @@ -199,21 +191,11 @@ module.exports = {

if (lineCount > maxLines) {
const name = upperCaseFirst(astUtils.getFunctionNameWithKind(funcNode));
const linesExceed = lineCount - maxLines;

const loc = {
start: {
line: node.loc.start.line + maxLines + (comments + blankLines),
column: 0
},
end: node.loc.end
};

context.report({
node,
loc,
messageId: "exceed",
data: { name, linesExceed, maxLines }
data: { name, lineCount, maxLines }
});
}
}
Expand Down

0 comments on commit 234e3d9

Please sign in to comment.