max_params

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT, MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxParamsRule = rule.Rule{
	Name: "max-params",
	Run: func(ctx rule.RuleContext, _options []any) rule.RuleListeners {
		options := rule.LegacyUnwrapOptions(_options)
		opts := parseOptions(options)

		check := func(node *ast.Node) {
			params := node.Parameters()
			effective := len(params)
			if thisParam := ast.GetThisParameter(node); thisParam != nil {
				switch opts.countThis {
				case countThisNever:
					effective--
				case countThisExceptVoid:
					if utils.IsThisVoidParameter(thisParam) {
						effective--
					}
				}
			}
			if effective <= opts.max {
				return
			}

			name := utils.UpperCaseFirstASCII(utils.GetFunctionNameWithKindCore(node))
			ctx.ReportRange(
				utils.GetFunctionHeadLoc(ctx.SourceFile, node),
				rule.RuleMessage{
					Id: "exceed",
					Description: fmt.Sprintf(
						"%s has too many parameters (%d). Maximum allowed is %d.",
						name, effective, opts.max,
					),
				},
			)
		}

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

MaxParamsRule enforces a maximum number of parameters in function definitions. https://eslint.org/docs/latest/rules/max-params

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