Documentation
¶
Overview ¶
Package scope ports eslint-plugin-jsx-a11y's `scope` rule. The `scope` HTML attribute is only valid on `<th>` elements (per the HTML spec / WCAG 1.3.1 / axe-core's `scope-attr-valid` check); using it on any other element is a no-op for assistive technology and signals a structural mistake.
Upstream signature: no options.
Trigger: a JsxAttribute whose name is "scope" (case-insensitive per upstream's `name.toUpperCase() !== 'SCOPE'`) on a parent element whose resolved tag name is in aria-query's `dom` map AND is not "th" (case-insensitive). The two case-sensitivity asymmetries are intentional and inherited from upstream:
- The DOM-set membership check (`dom.has(tagName)`) is case-sensitive against aria-query's lowercase keys, so `<TH scope />` is silently skipped (resolved tag "TH" is NOT in the map). Mirror exactly via IsDOMElement, which also uses case-sensitive lookup.
- The "is th" exemption is case-insensitive (`.toUpperCase() === 'TH'`), so once we're past the dom-set gate, both `<th>` and any case-variant that somehow survived would be exempt.
`getElementType` honors `polymorphicPropName` and the `components` map from `settings['jsx-a11y']`, so `<TableHeader scope="row" />` with `components: { TableHeader: 'th' }` resolves to "th" and skips the report, while `<Foo scope="bar" />` with `components: { Foo: 'div' }` resolves to "div" and reports.
Namespaced attribute names like `<th xml:scope />` are NOT matched — upstream's `propName` returns the composite "xml:scope" string, which uppercases to "XML:SCOPE" ≠ "SCOPE". `reactutil.GetJsxPropName` mirrors this composite shape.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ScopeRule = rule.Rule{ Name: "jsx-a11y/scope", Run: func(ctx rule.RuleContext, _ any) rule.RuleListeners { return rule.RuleListeners{ ast.KindJsxAttribute: func(attr *ast.Node) { name := reactutil.GetJsxPropName(attr) if name != "" && !strings.EqualFold(name, "scope") { return } parent := reactutil.GetJsxParentElement(attr) if parent == nil { return } tagName := jsxa11yutil.GetElementType(parent, ctx.Settings) if !jsxa11yutil.IsDOMElement(tagName) { return } if strings.EqualFold(tagName, "th") { return } ctx.ReportNode(attr, rule.RuleMessage{ Id: "scopeOnTh", Description: errorMessage, }) }, } }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.