Skip to content

Commit 5b9f10f

Browse files
authored
Merge pull request #606 from evcohen/589--make-expressions-pass-in-recommended-mode
[589] Allow expression statements for attribute values in no-noninteractive-tabindex
2 parents 7926d85 + 8d5abfd commit 5b9f10f

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

__tests__/src/rules/no-noninteractive-tabindex-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ ruleTester.run(`${ruleName}:recommended`, rule, {
5454
valid: [
5555
...alwaysValid,
5656
{ code: '<div role="tabpanel" tabIndex="0" />' },
57+
// Expressions should fail in strict mode
58+
{ code: '<div role={ROLE_BUTTON} onClick={() => {}} tabIndex="0" />;' },
5759
]
5860
.map(ruleOptionsMapperFactory(recommendedOptions))
5961
.map(parserOptionsMapper),
@@ -71,5 +73,7 @@ ruleTester.run(`${ruleName}:strict`, rule, {
7173
invalid: [
7274
...neverValid,
7375
{ code: '<div role="tabpanel" tabIndex="0" />', errors: [expectedError] },
76+
// Expressions should fail in strict mode
77+
{ code: '<div role={ROLE_BUTTON} onClick={() => {}} tabIndex="0" />;', errors: [expectedError] },
7478
].map(parserOptionsMapper),
7579
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"devDependencies": {
3333
"@babel/core": "^7.0.0",
3434
"@babel/plugin-transform-flow-strip-types": "^7.2.3",
35+
"@babel/runtime": "^7.4.5",
3536
"babel-eslint": "^10.0.1",
3637
"babel-jest": "^24.0.0",
3738
"babel-preset-airbnb": "^3.2.0",

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ module.exports = {
170170
{
171171
tags: [],
172172
roles: ['tabpanel'],
173+
allowExpressionValues: true,
173174
},
174175
],
175176
'jsx-a11y/no-onchange': 'error',

src/rules/no-noninteractive-tabindex.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import includes from 'array-includes';
1919
import type { ESLintContext } from '../../flow/eslint';
2020
import isInteractiveElement from '../util/isInteractiveElement';
2121
import isInteractiveRole from '../util/isInteractiveRole';
22+
import isNonLiteralProperty from '../util/isNonLiteralProperty';
2223
import { generateObjSchema, arraySchema } from '../util/schemas';
2324
import getTabIndex from '../util/getTabIndex';
2425

@@ -67,10 +68,17 @@ module.exports = {
6768
const {
6869
tags,
6970
roles,
71+
allowExpressionValues,
7072
} = (options[0] || {});
73+
if (tags && includes(tags, type)) {
74+
return;
75+
}
76+
if (roles && includes(roles, role)) {
77+
return;
78+
}
7179
if (
72-
(tags && includes(tags, type))
73-
|| (roles && includes(roles, role))
80+
allowExpressionValues === true
81+
&& isNonLiteralProperty(attributes, 'role')
7482
) {
7583
return;
7684
}

0 commit comments

Comments
 (0)