Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var SelfClosingCompRule = rule.Rule{ Name: "react/self-closing-comp", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { checkComponent := true checkHTML := true optsMap := utils.GetOptionsMap(options) if optsMap != nil { if v, ok := optsMap["component"]; ok { if b, ok := v.(bool); ok { checkComponent = b } } if v, ok := optsMap["html"]; ok { if b, ok := v.(bool); ok { checkHTML = b } } } return rule.RuleListeners{ ast.KindJsxOpeningElement: func(node *ast.Node) { parent := node.Parent if parent == nil || parent.Kind != ast.KindJsxElement { return } jsxElement := parent.AsJsxElement() if !isChildrenEmpty(jsxElement) { return } openingElement := node.AsJsxOpeningElement() tagName := openingElement.TagName isComp := isComponent(ctx.SourceFile, tagName) if isComp && !checkComponent { return } if !isComp && !checkHTML { return } openEnd := node.End() closeEnd := parent.End() fixRange := core.NewTextRange(openEnd-1, closeEnd) fix := rule.RuleFix{ Text: " />", Range: fixRange, } ctx.ReportNodeWithFixes(parent, rule.RuleMessage{ Id: "notSelfClosing", Description: "Empty components are self-closing", }, fix) }, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.