// Requirements
//------------------------------------------------------------------------------
-const lodash = require("lodash");
-
const astUtils = require("./utils/ast-utils");
+const { upperCaseFirst } = require("../shared/string-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
+/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "enforce a maximum number of statements allowed in function blocks",
- category: "Stylistic Issues",
recommended: false,
url: "https://eslint.org/docs/rules/max-statements"
},
*/
function reportIfTooManyStatements(node, count, max) {
if (count > max) {
- const name = lodash.upperFirst(astUtils.getFunctionNameWithKind(node));
+ const name = upperCaseFirst(astUtils.getFunctionNameWithKind(node));
context.report({
node,
function endFunction(node) {
const count = functionStack.pop();
+ /*
+ * This rule does not apply to class static blocks, but we have to track them so
+ * that stataments in them do not count as statements in the enclosing function.
+ */
+ if (node.type === "StaticBlock") {
+ return;
+ }
+
if (ignoreTopLevelFunctions && functionStack.length === 0) {
topLevelFunctions.push({ node, count });
} else {
FunctionDeclaration: startFunction,
FunctionExpression: startFunction,
ArrowFunctionExpression: startFunction,
+ StaticBlock: startFunction,
BlockStatement: countStatements,
"FunctionDeclaration:exit": endFunction,
"FunctionExpression:exit": endFunction,
"ArrowFunctionExpression:exit": endFunction,
+ "StaticBlock:exit": endFunction,
"Program:exit"() {
if (topLevelFunctions.length === 1) {