Skip to content

Commit ea16854

Browse files
author
Callie Callaway
committed
Add has package and update hasOwnProperty usages to use it
1 parent 4d7f14b commit ea16854

5 files changed

+9
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"axobject-query": "^1.0.1",
6767
"damerau-levenshtein": "^1.0.0",
6868
"emoji-regex": "^6.1.0",
69+
"has": "^1.0.1",
6970
"jsx-ast-utils": "^2.0.0"
7071
},
7172
"peerDependencies": {

src/rules/no-interactive-element-to-noninteractive-role.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from 'jsx-ast-utils';
2121
import type { JSXIdentifier } from 'ast-types-flow';
2222
import includes from 'array-includes';
23+
import has from 'has';
2324
import type { ESLintContext } from '../../flow/eslint';
2425
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
2526
import isInteractiveElement from '../util/isInteractiveElement';
@@ -69,10 +70,7 @@ module.exports = {
6970
// Allow overrides from rule configuration for specific elements and
7071
// roles.
7172
const allowedRoles = (options[0] || {});
72-
if (
73-
Object.prototype.hasOwnProperty.call(allowedRoles, type)
74-
&& includes(allowedRoles[type], role)
75-
) {
73+
if (has(allowedRoles, type) && includes(allowedRoles[type], role)) {
7674
return;
7775
}
7876
if (

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from 'jsx-ast-utils';
2121
import type { JSXOpeningElement } from 'ast-types-flow';
2222
import includes from 'array-includes';
23+
import has from 'has';
2324
import type { ESLintContext } from '../../flow/eslint';
2425
import { arraySchema, generateObjSchema } from '../util/schemas';
2526
import isAbstractRole from '../util/isAbstractRole';
@@ -61,7 +62,7 @@ module.exports = {
6162
const config = (options[0] || {});
6263
const interactiveProps = config.handlers || defaultInteractiveProps;
6364
// Allow overrides from rule configuration for specific elements and roles.
64-
if (Object.prototype.hasOwnProperty.call(config, type)) {
65+
if (has(config, type)) {
6566
attributes = attributes.filter(attr => !includes(config[type], propName(attr)));
6667
}
6768

src/rules/no-noninteractive-element-to-interactive-role.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020
JSXIdentifier,
2121
} from 'ast-types-flow';
2222
import includes from 'array-includes';
23+
import has from 'has';
2324
import type { ESLintContext } from '../../flow/eslint';
2425
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
2526
import getExplicitRole from '../util/getExplicitRole';
@@ -69,10 +70,7 @@ module.exports = {
6970
// Allow overrides from rule configuration for specific elements and
7071
// roles.
7172
const allowedRoles = (options[0] || {});
72-
if (
73-
Object.prototype.hasOwnProperty.call(allowedRoles, type)
74-
&& includes(allowedRoles[type], role)
75-
) {
73+
if (has(allowedRoles, type) && includes(allowedRoles[type], role)) {
7674
return;
7775
}
7876
if (

src/rules/no-redundant-roles.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import { elementType } from 'jsx-ast-utils';
1313
import includes from 'array-includes';
14+
import has from 'has';
1415
import type { JSXOpeningElement } from 'ast-types-flow';
1516
import type { ESLintContext } from '../../flow/eslint';
1617
import { generateObjSchema } from '../util/schemas';
@@ -44,10 +45,7 @@ module.exports = {
4445

4546
if (implicitRole === explicitRole) {
4647
const allowedRoles = (options[0] || {});
47-
if (
48-
Object.prototype.hasOwnProperty.call(allowedRoles, type) &&
49-
includes(allowedRoles[type], implicitRole)
50-
) {
48+
if (has(allowedRoles, type) && includes(allowedRoles[type], implicitRole)) {
5149
return;
5250
}
5351

0 commit comments

Comments
 (0)