Skip to content

Commit 8ae8f92

Browse files
committed
Sync with ember-template-lint
1 parent 6e89179 commit 8ae8f92

3 files changed

Lines changed: 17 additions & 62 deletions

File tree

docs/rules/template-no-scope-outside-table-headings.md

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,27 @@
22

33
<!-- end auto-generated rule header -->
44

5-
Disallow the `scope` attribute on elements other than `<th>`.
5+
The scope attribute is used on `<th>` elements to clarify the relationship between a table's header cells and data cells for screen readers. Scope is set to "row" or "col" for header cells that refer to a given row or column. For header cells that reference multiple rows or columns, set the scope attribute to "rowgroup" and "colgroup" and define the range for the rows or columns.
66

7-
## Rule Details
8-
9-
The `scope` attribute is only valid on `<th>` elements within tables. Using it on other elements (including `<td>`) is invalid HTML and should be avoided.
7+
This rule disallows the use of the scope attribute on HTML elements other than the `<th>` element.
108

119
## Examples
1210

13-
Examples of **incorrect** code for this rule:
14-
15-
```gjs
16-
<template>
17-
<div scope="col">Not a table cell</div>
18-
</template>
19-
```
20-
21-
```gjs
22-
<template>
23-
<span scope="row">Wrong element</span>
24-
</template>
25-
```
11+
This rule **forbids** the following:
2612

27-
```gjs
28-
<template>
29-
<p scope="col">Paragraph</p>
30-
</template>
13+
```hbs
14+
<a scope='col'></a>
15+
<table scope='rowgroup'></table>
3116
```
3217

33-
Examples of **correct** code for this rule:
34-
35-
```gjs
36-
<template>
37-
<th scope="col">Header</th>
38-
</template>
39-
```
40-
41-
```gjs
42-
<template>
43-
<th scope="row">Row header</th>
44-
</template>
45-
```
18+
This rule **allows** the following:
4619

47-
```gjs
48-
<template>
49-
<div>Content without scope</div>
50-
</template>
20+
```hbs
21+
<th scope='row'>A header cell</th>
22+
<CustomHeader scope={{foo}} />
5123
```
5224

5325
## References
5426

55-
- [eslint-plugin-ember template-no-scope-outside-table-headings](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/template-no-scope-outside-table-headings.md)
56-
- [MDN: scope attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th#attr-scope)
27+
- [HTML \<th\> scope Attribute](https://www.w3schools.com/tags/att_th_scope.asp)
28+
- [scope - eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/scope.md)

lib/rules/template-no-scope-outside-table-headings.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
const htmlTags = require('html-tags');
2+
3+
const HTML_ELEMENTS = new Set(htmlTags);
4+
15
/** @type {import('eslint').Rule.RuleModule} */
26
module.exports = {
37
meta: {
@@ -25,8 +29,7 @@ module.exports = {
2529
GlimmerElementNode(node) {
2630
const tagName = node.tag;
2731

28-
// Skip custom components (non-HTML elements)
29-
if (!tagName || /^[A-Z]/.test(tagName) || tagName.includes('.')) {
32+
if (!tagName || !HTML_ELEMENTS.has(tagName)) {
3033
return;
3134
}
3235

tests/lib/rules/template-no-scope-outside-table-headings.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ const ruleTester = new RuleTester({
1212

1313
ruleTester.run('template-no-scope-outside-table-headings', rule, {
1414
valid: [
15-
'<template><th scope="col">Header</th></template>',
16-
'<template><th scope="row">Header</th></template>',
17-
'<template><div>Content</div></template>',
18-
1915
'<template><th scope="row">Some table heading></th></template>',
2016
`<template>
2117
<table>
@@ -29,22 +25,6 @@ ruleTester.run('template-no-scope-outside-table-headings', rule, {
2925
'<template>{{foo-component scope="row"}}</template>',
3026
],
3127
invalid: [
32-
{
33-
code: '<template><div scope="col">Not a table cell</div></template>',
34-
output: null,
35-
errors: [{ messageId: 'noScopeOutsideTableHeadings' }],
36-
},
37-
{
38-
code: '<template><span scope="row">Wrong element</span></template>',
39-
output: null,
40-
errors: [{ messageId: 'noScopeOutsideTableHeadings' }],
41-
},
42-
{
43-
code: '<template><p scope="col">Paragraph</p></template>',
44-
output: null,
45-
errors: [{ messageId: 'noScopeOutsideTableHeadings' }],
46-
},
47-
4828
{
4929
code: '<template><td scope="row"></td></template>',
5030
output: null,

0 commit comments

Comments
 (0)