jsx_no_comment_textnodes

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT, MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JsxNoCommentTextnodesRule = rule.Rule{
	Name: "react/jsx-no-comment-textnodes",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		return rule.RuleListeners{

			ast.KindJsxText: func(node *ast.Node) {
				parent := node.Parent

				if parent == nil || (!ast.IsJsxElement(parent) && !ast.IsJsxFragment(parent)) {
					return
				}

				jsxText := node.AsJsxText()
				if jsxText == nil || jsxText.ContainsOnlyTriviaWhiteSpaces {
					return
				}

				source := ctx.SourceFile.Text()
				startPos, endPos := node.Pos(), node.End()
				if startPos < 0 || endPos > len(source) || startPos >= endPos {
					return
				}
				raw := source[startPos:endPos]
				if !hasCommentLikeLine(raw) {
					return
				}

				ctx.ReportRange(core.NewTextRange(startPos, endPos), rule.RuleMessage{
					Id:          "putCommentInBraces",
					Description: "Comments inside children section of tag should be placed inside braces",
				})
			},
		}
	},
}

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