no_this_in_sfc

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoThisInSfcRule = rule.Rule{
	Name: "react/no-this-in-sfc",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		pragma := reactutil.GetReactPragma(ctx.Settings)
		wrappers := reactutil.GetComponentWrapperFunctions(ctx.Settings, pragma)

		report := func(node *ast.Node) {
			ctx.ReportNode(node, rule.RuleMessage{
				Id:          "noThisInSFC",
				Description: "Stateless functional components should not use `this`",
			})
		}

		check := func(node, expr *ast.Node) {
			if ast.SkipParentheses(expr).Kind != ast.KindThisKeyword {
				return
			}
			component := reactutil.GetParentStatelessComponent(node, pragma, wrappers)
			if component == nil {
				return
			}
			if isPropertyOwnedSFC(component) {
				return
			}
			report(node)
		}

		return rule.RuleListeners{
			ast.KindPropertyAccessExpression: func(node *ast.Node) {
				check(node, node.AsPropertyAccessExpression().Expression)
			},
			ast.KindElementAccessExpression: func(node *ast.Node) {
				check(node, node.AsElementAccessExpression().Expression)
			},
		}
	},
}

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