no_static_only_class

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: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoStaticOnlyClassRule = rule.Rule{
	Name: "unicorn/no-static-only-class",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		check := func(node *ast.Node) {

			if ast.GetExtendsHeritageClauseElement(node) != nil {
				return
			}

			if ast.HasDecorators(node) {
				return
			}

			hasMember := false
			for _, m := range node.Members() {
				if m == nil || ast.IsSemicolonClassElement(m) {
					continue
				}
				hasMember = true
				if !isStaticMember(m) {
					return
				}
			}
			if !hasMember {
				return
			}

			msg := rule.RuleMessage{
				Id:          "noStaticOnlyClass",
				Description: "Use an object instead of a class with only static members.",
			}
			headRange := classHeadRange(node, ctx.SourceFile)

			fixes := buildFix(node, ctx.SourceFile)
			if len(fixes) == 0 {
				ctx.ReportRange(headRange, msg)
				return
			}
			ctx.ReportRangeWithFixes(headRange, msg, fixes...)
		}

		return rule.RuleListeners{
			ast.KindClassDeclaration: check,
			ast.KindClassExpression:  check,
		}
	},
}

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