Repository: eslint/eslint
File: lib/rules/complexity.js (JavaScript)

Code before:

			onCodePathEnd(codePath, node) {
				const complexity = complexities.pop();

				/*
				 * This rule only evaluates complexity of functions, so "program" is excluded.
				 * Class field initializers and class static blocks are implicit functions. Therefore,
				 * they shouldn't contribute to the enclosing function's complexity, but their
				 * own complexity should be evaluated.
				 */
				if (
					codePath.origin !== "function" &&
					codePath.origin !== "class-field-initializer" &&
					codePath.origin !== "class-static-block"
				) {
					return;
				}

				if (complexity > threshold) {
					let name;
					let loc = node.loc;

					if (codePath.origin === "class-field-initializer") {
						name = "class field initializer";
					} else if (codePath.origin === "class-static-block") {
						const openingBrace = sourceCode.getFirstToken(node, {
							skip: 1,
						});

						name = "class static block";
						loc = {
							start: node.loc.start,
							end: openingBrace.loc.start,
						};
					} else {
						name = astUtils.getFunctionNameWithKind(node);
						loc = astUtils.getFunctionHeadLoc(node, sourceCode);
					}

					context.report({
						node,
						loc,
						messageId: "complex",
						data: {
							name: upperCaseFirst(name),
							complexity,
							max: threshold,
						},
					});
				}
			},

Review comment (suggestion):
Thanks for finding a inconsistency with the report location.
I suggest using only the `static` keyword without the opening curly braces because:
1. consistent with the functions/methods which use the name/key (some [examples](https://eslint.org/play/#eyJ0ZXh0IjoiY2xhc3MgQyB7XG4gIHN0YXRpYyB7XG4gICAgYSAmJiBiXG4gIH1cblxuICBhKCkge1xuICAgIGEgJiYgYjtcbiAgfVxuXG4gIHN0YXRpYyBiKCkge1xuICAgIGEgJiYgYjtcbiAgfVxuXG4gIGdldCBjKCkge1xuICAgIGEgJiYgYjtcbiAgfVxuICBcbiAgc2V0IGQodmFsdWUpIHtcbiAgICBhICYmIGI7XG4gIH1cbn1cbiIsIm9wdGlvbnMiOnsicnVsZXMiOnsiY29tcGxleGl0eSI6WyJlcnJvciIseyJtYXgiOjF9XX0sImxhbmd1YWdlT3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFGZWF0dXJlcyI6e319fX19))
2. Keep the reported location a single line for developers using braces on the next line

Code after:

			onCodePathEnd(codePath, node) {
				const complexity = complexities.pop();

				/*
				 * This rule only evaluates complexity of functions, so "program" is excluded.
				 * Class field initializers and class static blocks are implicit functions. Therefore,
				 * they shouldn't contribute to the enclosing function's complexity, but their
				 * own complexity should be evaluated.
				 */
				if (
					codePath.origin !== "function" &&
					codePath.origin !== "class-field-initializer" &&
					codePath.origin !== "class-static-block"
				) {
					return;
				}

				if (complexity > threshold) {
					let name;
					let loc = node.loc;

					if (codePath.origin === "class-field-initializer") {
						name = "class field initializer";
					} else if (codePath.origin === "class-static-block") {
						name = "class static block";
						loc = sourceCode.getFirstToken(node).loc;
					} else {
						name = astUtils.getFunctionNameWithKind(node);
						loc = astUtils.getFunctionHeadLoc(node, sourceCode);
					}

					context.report({
						node,
						loc,
						messageId: "complex",
						data: {
							name: upperCaseFirst(name),
							complexity,
							max: threshold,
						},
					});
				}
			},
		};
	},
};