Skip to content

Commit fd9bc03

Browse files
blindsoupkoba04
andauthored
fix!: enable some jsx-a11y rules (#540)
BREAKING CHANGE: we have enabled some rules of `jsx-a11y` * fix a11y rules * formatted Co-authored-by: Toru Kobayashi <[email protected]>
1 parent 5dd5077 commit fd9bc03

File tree

3 files changed

+72
-8
lines changed

3 files changed

+72
-8
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
extends: ["./lib/base.js"]
2+
extends: ["./lib/base.js"],
33
};

lib/react.js

+69-5
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,83 @@ module.exports = {
161161
"jsx-a11y/no-autofocus": "error",
162162
"jsx-a11y/no-distracting-elements": "error",
163163
"jsx-a11y/no-interactive-element-to-noninteractive-role": "error",
164-
"jsx-a11y/no-noninteractive-element-to-interactive-role": "error",
164+
"jsx-a11y/no-noninteractive-element-to-interactive-role": [
165+
"error",
166+
/** Overwrite prohibited.
167+
* Add the following whitelist to address W3C best practices. For example, the dropdown sample used <ul role="listbox">, <li role="option">.
168+
* See: https://www.w3.org/TR/wai-aria-practices/examples/listbox/listbox-collapsible.html
169+
*/
170+
{
171+
ul: [
172+
"listbox",
173+
"menu",
174+
"menubar",
175+
"radiogroup",
176+
"tablist",
177+
"tree",
178+
"treegrid",
179+
],
180+
ol: [
181+
"listbox",
182+
"menu",
183+
"menubar",
184+
"radiogroup",
185+
"tablist",
186+
"tree",
187+
"treegrid",
188+
],
189+
li: ["option", "menuitem", "row", "tab", "treeitem"],
190+
table: ["grid"],
191+
td: ["gridcell"],
192+
},
193+
],
194+
"jsx-a11y/no-noninteractive-element-interactions": [
195+
"error",
196+
/** We must not assign the following events to non-interactive elements (eg img, h1, li ...) because avoid creating parts that cannot be handled with keyboards and mobile terminals. */
197+
{
198+
handlers: [
199+
"onClick",
200+
"onMouseDown",
201+
"onMouseUp",
202+
"onKeyPress",
203+
"onKeyDown",
204+
"onKeyUp",
205+
],
206+
},
207+
],
208+
"jsx-a11y/no-static-element-interactions": [
209+
"error",
210+
/** We must not assign the following events to static elements because avoid creating parts that cannot be handled with keyboards and mobile terminals. */
211+
{
212+
handlers: [
213+
"onClick",
214+
"onMouseDown",
215+
"onMouseUp",
216+
"onKeyPress",
217+
"onKeyDown",
218+
"onKeyUp",
219+
],
220+
},
221+
],
165222
"jsx-a11y/anchor-has-content": "error",
166223
"jsx-a11y/anchor-is-valid": "error",
224+
"jsx-a11y/role-supports-aria-props": "error",
167225
"jsx-a11y/role-has-required-aria-props": "error",
168226
"jsx-a11y/autocomplete-valid": "error",
169-
"jsx-a11y/img-redundant-alt": [
227+
"jsx-a11y/scope": "error",
228+
"jsx-a11y/tabindex-no-positive": "error",
229+
"jsx-a11y/img-redundant-alt": "error",
230+
"jsx-a11y/no-noninteractive-tabindex": [
170231
"error",
232+
/** Overwrite prohibited.
233+
* We add a whitelist to allow focus on tab panels and dialogs.
234+
* See: https://www.w3.org/TR/wai-aria-practices/examples/tabs/tabs-1/tabs.html
235+
*/
171236
{
172-
components: ["Icon", "Image"],
173-
words: ["Image", "image", "Icon", "icon", "アイコン", "画像"],
237+
tags: [],
238+
roles: ["dialog", "tabpanel"],
174239
},
175240
],
176-
"jsx-a11y/no-noninteractive-tabindex": ["error"],
177241
/** We disable this rule because this cannot detect patterns like <main role=“main” />. */
178242
"jsx-a11y/no-redundant-roles": "off",
179243
/** There are unnecessary patterns such as dialog overlays.*/

test/lib/runLintWithFixtures.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const runLintWithFixtures = async (type, configFile = `lib/${type}.js`) => {
1313
overrideConfigFile: path.resolve(process.cwd(), configFile),
1414
ignore: false,
1515
useEslintrc: false,
16-
extensions: [".js", ".jsx", ".ts", ".tsx"]
16+
extensions: [".js", ".jsx", ".ts", ".tsx"],
1717
});
1818
const targetDir = path.resolve(__dirname, "..", "fixtures", type);
1919
const lintResult = await eslint.lintFiles([targetDir]);
@@ -43,7 +43,7 @@ const runLintWithFixtures = async (type, configFile = `lib/${type}.js`) => {
4343
throw new Error(`Got an unknown severity: ${severity}(${ruleId})`);
4444
}
4545
return resultPerFile;
46-
}, {})
46+
}, {}),
4747
});
4848
}, {});
4949
};

0 commit comments

Comments
 (0)