Skip to content

Commit 71299a0

Browse files
committed
Convert options to object from array
1 parent ed0074d commit 71299a0

File tree

5 files changed

+40
-24
lines changed

5 files changed

+40
-24
lines changed

__tests__/src/rules/no-noninteractive-element-interactions-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ const neverValid = [
291291
{ code: '<div role="tooltip" onClick={() => {}} />;', errors: [expectedError] },
292292
];
293293

294-
const recommendedOptions = [configs.recommended.rules[`jsx-a11y/${ruleName}`][1]];
294+
const recommendedOptions =
295+
(configs.recommended.rules[`jsx-a11y/${ruleName}`][1] || {});
295296
ruleTester.run(`${ruleName}:recommended`, rule, {
296297
valid: [
297298
...alwaysValid,

__tests__/src/rules/no-static-element-interactions-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ const neverValid = [
291291
{ code: '<xmp onClick={() => {}} />;', errors: [expectedError] },
292292
];
293293

294-
const recommendedOptions = [configs.recommended.rules[`jsx-a11y/${ruleName}`][1]];
294+
const recommendedOptions =
295+
(configs.recommended.rules[`jsx-a11y/${ruleName}`][1] || {});
295296
ruleTester.run(`${ruleName}:recommended`, rule, {
296297
valid: [
297298
...alwaysValid,

src/index.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ module.exports = {
7474
],
7575
'jsx-a11y/no-noninteractive-element-interactions': [
7676
'error',
77-
[
78-
'onClick',
79-
'onMouseDown',
80-
'onMouseUp',
81-
'onKeyPress',
82-
'onKeyDown',
83-
'onKeyUp',
84-
],
77+
{
78+
handlers: [
79+
'onClick',
80+
'onMouseDown',
81+
'onMouseUp',
82+
'onKeyPress',
83+
'onKeyDown',
84+
'onKeyUp',
85+
],
86+
},
8587
],
8688
'jsx-a11y/no-noninteractive-element-to-interactive-role': [
8789
'error',
@@ -120,14 +122,16 @@ module.exports = {
120122
'jsx-a11y/no-redundant-roles': 'error',
121123
'jsx-a11y/no-static-element-interactions': [
122124
'error',
123-
[
124-
'onClick',
125-
'onMouseDown',
126-
'onMouseUp',
127-
'onKeyPress',
128-
'onKeyDown',
129-
'onKeyUp',
130-
],
125+
{
126+
handlers: [
127+
'onClick',
128+
'onMouseDown',
129+
'onMouseUp',
130+
'onKeyPress',
131+
'onKeyDown',
132+
'onKeyUp',
133+
],
134+
},
131135
],
132136
'jsx-a11y/role-has-required-aria-props': 'error',
133137
'jsx-a11y/role-supports-aria-props': 'error',

src/rules/no-noninteractive-element-interactions.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
hasProp,
1919
} from 'jsx-ast-utils';
2020
import type { JSXOpeningElement } from 'ast-types-flow';
21-
import { arraySchema } from '../util/schemas';
21+
import { arraySchema, generateObjSchema } from '../util/schemas';
2222
import isAbstractRole from '../util/isAbstractRole';
2323
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
2424
import isInteractiveElement from '../util/isInteractiveElement';
@@ -32,11 +32,14 @@ const errorMessage =
3232

3333
const domElements = [...dom.keys()];
3434
const defaultInteractiveProps = eventHandlers;
35+
const schema = generateObjSchema({
36+
handlers: arraySchema,
37+
});
3538

3639
module.exports = {
3740
meta: {
3841
docs: {},
39-
schema: [arraySchema],
42+
schema: [schema],
4043
},
4144

4245
create: (context: ESLintContext) => {
@@ -47,7 +50,9 @@ module.exports = {
4750
) => {
4851
const attributes = node.attributes;
4952
const type = elementType(node);
50-
const interactiveProps = options[0] || defaultInteractiveProps;
53+
const interactiveProps = options[0]
54+
? options[0].handlers
55+
: defaultInteractiveProps;
5156

5257
const hasInteractiveProps = interactiveProps
5358
.some(prop => (

src/rules/no-static-element-interactions.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
hasProp,
2020
} from 'jsx-ast-utils';
2121
import type { JSXOpeningElement } from 'ast-types-flow';
22-
import { arraySchema } from '../util/schemas';
22+
import { arraySchema, generateObjSchema } from '../util/schemas';
2323
import isAbstractRole from '../util/isAbstractRole';
2424
import isHiddenFromScreenReader from '../util/isHiddenFromScreenReader';
2525
import isInteractiveElement from '../util/isInteractiveElement';
@@ -33,11 +33,14 @@ const errorMessage =
3333

3434
const domElements = [...dom.keys()];
3535
const defaultInteractiveProps = eventHandlers;
36+
const schema = generateObjSchema({
37+
handlers: arraySchema,
38+
});
3639

3740
module.exports = {
3841
meta: {
3942
docs: {},
40-
schema: [arraySchema],
43+
schema: [schema],
4144
},
4245

4346
create: (context: ESLintContext) => {
@@ -48,7 +51,9 @@ module.exports = {
4851
) => {
4952
const attributes = node.attributes;
5053
const type = elementType(node);
51-
const interactiveProps = options[0] || defaultInteractiveProps;
54+
const interactiveProps = options[0]
55+
? options[0].handlers
56+
: defaultInteractiveProps;
5257

5358
const hasInteractiveProps = interactiveProps
5459
.some(prop => (

0 commit comments

Comments
 (0)