jsx_pascal_case

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT, MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JsxPascalCaseRule = rule.Rule{
	Name: "react/jsx-pascal-case",
	Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
		cfg := parseOptions(options)

		check := func(element *ast.Node) {
			if reactutil.IsDOMComponent(element) {
				return
			}
			name := reactutil.GetJsxElementTypeString(element)
			if name == "" {
				return
			}

			// Upstream splits on `:` first, else on `.` — never on both.
			var checkNames []string
			if strings.LastIndex(name, ":") > -1 {
				checkNames = strings.Split(name, ":")
			} else if strings.LastIndex(name, ".") > -1 {
				checkNames = strings.Split(name, ".")
			} else {
				checkNames = []string{name}
			}

			for index := range checkNames {
				splitName := checkNames[index]

				if len([]rune(splitName)) == 1 {
					return
				}
				isIgnored := ignoreCheck(cfg.ignore, splitName)

				checkName := splitName
				if cfg.allowLeadingUnderscore && strings.HasPrefix(splitName, "_") {
					checkName = splitName[1:]
				}
				isPascal := testPascalCase(checkName)
				isAllowedAllCaps := cfg.allowAllCaps && testAllCaps(checkName)

				if !isPascal && !isAllowedAllCaps && !isIgnored {
					msgId := "usePascalCase"
					msg := msgUsePascalCase
					if cfg.allowAllCaps {
						msgId = "usePascalOrSnakeCase"
						msg = msgUsePascalOrSnakeCase
					}
					ctx.ReportNode(element, rule.RuleMessage{
						Id:          msgId,
						Description: strings.ReplaceAll(msg, "{{name}}", splitName),
					})
					break
				}

				if cfg.allowNamespace {
					break
				}
			}
		}

		return rule.RuleListeners{
			ast.KindJsxOpeningElement:     check,
			ast.KindJsxSelfClosingElement: 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