type: "suggestion",
docs: {
- description: "enforce a maximum number of lines of code in a function",
+ description: "Enforce a maximum number of lines of code in a function",
recommended: false,
url: "https://eslint.org/docs/rules/max-lines-per-function"
},
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}}."
}
},
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;
}
}
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 }
});
}
}