autocomplete_valid

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AutocompleteValidRule = rule.Rule{
	Name: "jsx-a11y/autocomplete-valid",
	Run: func(ctx rule.RuleContext, rawOptions any) rule.RuleListeners {
		opts := parseOptions(rawOptions)

		inputTypes := map[string]struct{}{"input": {}}
		for _, c := range opts.inputComponents {
			inputTypes[c] = struct{}{}
		}

		check := func(node *ast.Node) {
			elType := jsxa11yutil.GetElementType(node, ctx.Settings)
			if _, ok := inputTypes[elType]; !ok {
				return
			}

			attrs := reactutil.GetJsxElementAttributes(node)
			autocompleteAttr := jsxa11yutil.FindAttributeByName(attrs, "autocomplete")
			if autocompleteAttr == nil {
				return
			}

			autocompleteValue, ok := jsxa11yutil.LiteralPropStringValue(autocompleteAttr)
			if !ok {
				return
			}

			if typeAttr := jsxa11yutil.FindAttributeByName(attrs, "type"); typeAttr != nil {
				if typeValue, ok := jsxa11yutil.LiteralPropStringValue(typeAttr); ok {
					if _, excluded := excludedInputTypes[strings.ToLower(typeValue)]; excluded {
						return
					}
				}
			}

			if isValidAutocomplete(autocompleteValue) {
				return
			}
			ctx.ReportNode(node, rule.RuleMessage{
				Id:          "autocompleteValid",
				Description: failMessage,
			})
		}

		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