no_this_before_super

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoThisBeforeSuperRule = rule.Rule{
	Name: "no-this-before-super",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		return rule.RuleListeners{
			ast.KindConstructor: func(node *ast.Node) {
				classNode := ast.GetContainingClass(node)
				if classNode == nil {
					return
				}

				extendsElem := ast.GetClassExtendsHeritageElement(classNode)
				if extendsElem == nil {
					return
				}
				exprWithType := extendsElem.AsExpressionWithTypeArguments()
				if exprWithType == nil || exprWithType.Expression == nil ||
					exprWithType.Expression.Kind == ast.KindNullKeyword {
					return
				}

				body := node.Body()
				if body == nil || body.Kind != ast.KindBlock {
					return
				}

				for _, param := range node.Parameters() {
					if param == nil {
						continue
					}
					p := param.AsParameterDeclaration()
					if p != nil && p.Initializer != nil {
						checkViolations(p.Initializer, superNone, &ctx)
					}
				}

				checkStatements(body.Statements(), &ctx)
			},
		}
	},
}

NoThisBeforeSuperRule disallows this/super before calling super() in constructors. https://eslint.org/docs/latest/rules/no-this-before-super

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