Skip to content

Commit 9a8edde

Browse files
committedOct 21, 2023
[Refactor] use hasown instead of has
1 parent 46ffbc3 commit 9a8edde

6 files changed

+11
-11
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"axobject-query": "^3.2.1",
8484
"damerau-levenshtein": "^1.0.8",
8585
"emoji-regex": "^9.2.2",
86-
"has": "^1.0.3",
86+
"hasown": "^2.0.0",
8787
"jsx-ast-utils": "^3.3.5",
8888
"language-tags": "^1.0.9",
8989
"minimatch": "^3.1.2",

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from 'jsx-ast-utils';
1818
import type { JSXIdentifier } from 'ast-types-flow';
1919
import includes from 'array-includes';
20-
import has from 'has';
20+
import hasOwn from 'hasown';
2121
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2222
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
2323
import getElementType from '../util/getElementType';
@@ -70,7 +70,7 @@ export default ({
7070
// Allow overrides from rule configuration for specific elements and
7171
// roles.
7272
const allowedRoles = (options[0] || {});
73-
if (has(allowedRoles, type) && includes(allowedRoles[type], role)) {
73+
if (hasOwn(allowedRoles, type) && includes(allowedRoles[type], role)) {
7474
return;
7575
}
7676
if (

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from 'jsx-ast-utils';
1818
import type { JSXOpeningElement } from 'ast-types-flow';
1919
import includes from 'array-includes';
20-
import has from 'has';
20+
import hasOwn from 'hasown';
2121
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2222
import { arraySchema, generateObjSchema } from '../util/schemas';
2323
import getElementType from '../util/getElementType';
@@ -62,7 +62,7 @@ export default ({
6262
const config = (options[0] || {});
6363
const interactiveProps = config.handlers || defaultInteractiveProps;
6464
// Allow overrides from rule configuration for specific elements and roles.
65-
if (has(config, type)) {
65+
if (hasOwn(config, type)) {
6666
attributes = attributes.filter((attr) => attr.type !== 'JSXSpreadAttribute' && !includes(config[type], propName(attr)));
6767
}
6868

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from 'jsx-ast-utils';
1616
import type { JSXIdentifier } from 'ast-types-flow';
1717
import includes from 'array-includes';
18-
import has from 'has';
18+
import hasOwn from 'hasown';
1919
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
2020
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
2121
import getElementType from '../util/getElementType';
@@ -68,7 +68,7 @@ export default ({
6868
// Allow overrides from rule configuration for specific elements and
6969
// roles.
7070
const allowedRoles = (options[0] || {});
71-
if (has(allowedRoles, type) && includes(allowedRoles[type], role)) {
71+
if (hasOwn(allowedRoles, type) && includes(allowedRoles[type], role)) {
7272
return;
7373
}
7474
if (

‎src/rules/no-redundant-roles.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// ----------------------------------------------------------------------------
1111

1212
import includes from 'array-includes';
13-
import has from 'has';
13+
import hasOwn from 'hasown';
1414
import type { JSXOpeningElement } from 'ast-types-flow';
1515
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
1616
import getElementType from '../util/getElementType';
@@ -58,7 +58,7 @@ export default ({
5858
const allowedRedundantRoles = (options[0] || {});
5959
let redundantRolesForElement;
6060

61-
if (has(allowedRedundantRoles, type)) {
61+
if (hasOwn(allowedRedundantRoles, type)) {
6262
redundantRolesForElement = allowedRedundantRoles[type];
6363
} else {
6464
redundantRolesForElement = DEFAULT_ROLE_EXCEPTIONS[type] || [];

‎src/util/getElementType.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import type { JSXOpeningElement } from 'ast-types-flow';
6-
import has from 'has';
6+
import hasOwn from 'hasown';
77
import { elementType, getProp, getLiteralPropValue } from 'jsx-ast-utils';
88

99
import type { ESLintContext } from '../../flow/eslint';
@@ -21,7 +21,7 @@ const getElementType = (context: ESLintContext): ((node: JSXOpeningElement) => s
2121
return rawType;
2222
}
2323

24-
return has(componentMap, rawType) ? componentMap[rawType] : rawType;
24+
return hasOwn(componentMap, rawType) ? componentMap[rawType] : rawType;
2525
};
2626
};
2727

0 commit comments

Comments
 (0)
Please sign in to comment.