Skip to content

Commit 5bebdec

Browse files
committed
Sync with ember-template-lint
1 parent ae24d4c commit 5bebdec

3 files changed

Lines changed: 54 additions & 32 deletions

File tree

docs/rules/template-no-redundant-role.md

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
<!-- end auto-generated rule header -->
66

7-
Disallows redundant role attributes on semantic HTML elements.
8-
97
The rule checks for redundancy between any semantic HTML element with a default/implicit ARIA role and the role provided.
108

119
For example, if a landmark element is used, any role provided will either be redundant or incorrect. This rule ensures that no role attribute is placed on any of the landmark elements, with the following exceptions:
@@ -18,56 +16,51 @@ For example, if a landmark element is used, any role provided will either be red
1816

1917
This rule **forbids** the following:
2018

21-
```gjs
22-
<template><header role='banner'></header></template>
19+
```hbs
20+
<header role='banner'></header>
2321
```
2422

25-
```gjs
26-
<template><main role='main'></main></template>
23+
```hbs
24+
<main role='main'></main>
2725
```
2826

29-
```gjs
30-
<template><aside role='complementary'></aside></template>
27+
```hbs
28+
<aside role='complementary'></aside>
3129
```
3230

33-
```gjs
34-
<template><footer role='contentinfo'></footer></template>
31+
```hbs
32+
<footer role='contentinfo'></footer>
3533
```
3634

37-
```gjs
38-
<template><form role='form'></form></template>
35+
```hbs
36+
<form role='form'></form>
3937
```
4038

4139
This rule **allows** the following:
4240

43-
```gjs
44-
<template><form role='search'></form></template>
41+
```hbs
42+
<form role='search'></form>
4543
```
4644

47-
```gjs
48-
<template><nav role='navigation'></nav></template>
45+
```hbs
46+
<nav role='navigation'></nav>
4947
```
5048

51-
```gjs
52-
<template><input role='combobox' /></template>
49+
```hbs
50+
<input role='combobox' />
5351
```
5452

5553
## Configuration
5654

57-
This rule accepts an options object with the following properties:
58-
59-
- `checkAllHTMLElements` (default: `true`) - When set to `true`, checks all HTML elements for redundant roles. When `false`, only checks landmark elements.
55+
- boolean -- if `true`, default configuration is applied
6056

61-
```js
62-
// .eslintrc.js
63-
module.exports = {
64-
rules: {
65-
'ember/template-no-redundant-role': ['error', { checkAllHTMLElements: false }],
66-
},
67-
};
68-
```
57+
- object -- containing the following property:
58+
- boolean -- `checkAllHTMLElements` -- if `true`, the rule checks for redundancy between any semantic HTML element with a default/implicit ARIA role and the role provided, instead of just landmark roles (default: `true`)
6959

7060
## References
7161

72-
- [ARIA Roles](https://www.w3.org/TR/wai-aria-1.2/#role_definitions)
73-
- [HTML ARIA](https://www.w3.org/TR/html-aria/)
62+
- [Landmark Roles (WAI-ARIA spec)](https://www.w3.org/WAI/PF/aria/roles#landmark_roles)
63+
- [Using ARIA landmarks to identify regions of a page](https://www.w3.org/WAI/WCAG21/Techniques/aria/ARIA11)
64+
- [Document conformance requirements for use of ARIA attributes in HTML](https://www.w3.org/TR/html-aria/#docconformance)
65+
- [ARIA Spec, ARIA Adds Nothing to Default Semantics of Most HTML Elements](https://www.w3.org/TR/using-aria/#aria-does-nothing)
66+
- [Disabling a link](https://www.scottohara.me/blog/2021/05/28/disabled-links.html)

lib/rules/template-no-redundant-role.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ module.exports = {
8888
docs: {
8989
description: 'disallow redundant role attributes',
9090
category: 'Accessibility',
91-
recommended: false,
9291
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-redundant-role.md',
9392
templateMode: 'both',
9493
},

tests/lib/rules/template-no-redundant-role.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ hbsRuleTester.run('template-no-redundant-role', rule, {
146146
'<button role="link"></button>',
147147
'<input type="checkbox" value="yes" checked />',
148148
'<input type="range" />',
149+
{
150+
code: '<body role="document"></body>',
151+
options: [{ checkAllHTMLElements: false }],
152+
},
153+
{
154+
code: '<dialog role="dialog" />',
155+
options: [{ checkAllHTMLElements: false }],
156+
},
149157
'<ul class="list" role="combobox"></ul>',
150158
],
151159
invalid: [
@@ -235,5 +243,27 @@ hbsRuleTester.run('template-no-redundant-role', rule, {
235243
'<select name="color" id="color" multiple><option value="default-color">black</option></select>',
236244
errors: [{ message: 'Use of redundant or invalid role: listbox on <select> detected.' }],
237245
},
246+
{
247+
code: '<main role="main"></main>',
248+
output: '<main></main>',
249+
options: [{ checkAllHTMLElements: false }],
250+
errors: [
251+
{
252+
message:
253+
'Use of redundant or invalid role: main on <main> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
254+
},
255+
],
256+
},
257+
{
258+
code: '<aside role="complementary"></aside>',
259+
output: '<aside></aside>',
260+
options: [{ checkAllHTMLElements: false }],
261+
errors: [
262+
{
263+
message:
264+
'Use of redundant or invalid role: complementary on <aside> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
265+
},
266+
],
267+
},
238268
],
239269
});

0 commit comments

Comments
 (0)