max_lines_per_function

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxLinesPerFunctionRule = rule.Rule{
	Name: "max-lines-per-function",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		opts := parseOptions(options)
		state := newLineState(ctx.SourceFile)

		process := func(node *ast.Node) {

			if node.Body() == nil {
				return
			}
			if !opts.iifes && isIIFE(node) {
				return
			}

			startLine, endLine := state.nodeLineRange(node)
			lineCount := 0
			for i := startLine; i <= endLine; i++ {
				if opts.skipComments && state.isFullLineCommentLine(i) {
					continue
				}
				if opts.skipBlankLines && utils.IsECMABlankLine(state.lineContent(i)) {
					continue
				}
				lineCount++
			}

			if lineCount > opts.max {
				name := upperCaseFirst(utils.GetFunctionNameWithKind(node))
				ctx.ReportNode(node, rule.RuleMessage{
					Id: "exceed",
					Description: fmt.Sprintf(
						"%s has too many lines (%d). Maximum allowed is %d.",
						name, lineCount, opts.max,
					),
				})
			}
		}

		return rule.RuleListeners{
			ast.KindFunctionDeclaration: process,
			ast.KindFunctionExpression:  process,
			ast.KindArrowFunction:       process,
			ast.KindMethodDeclaration:   process,
			ast.KindGetAccessor:         process,
			ast.KindSetAccessor:         process,
			ast.KindConstructor:         process,
		}
	},
}

MaxLinesPerFunctionRule enforces a maximum number of lines per function. https://eslint.org/docs/latest/rules/max-lines-per-function

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL