Skip to content

Commit

Permalink
[Refactor] use hasown instead of has
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 21, 2023
1 parent 46ffbc3 commit 9a8edde
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -83,7 +83,7 @@
"axobject-query": "^3.2.1",
"damerau-levenshtein": "^1.0.8",
"emoji-regex": "^9.2.2",
"has": "^1.0.3",
"hasown": "^2.0.0",
"jsx-ast-utils": "^3.3.5",
"language-tags": "^1.0.9",
"minimatch": "^3.1.2",
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-interactive-element-to-noninteractive-role.js
Expand Up @@ -17,7 +17,7 @@ import {
} from 'jsx-ast-utils';
import type { JSXIdentifier } from 'ast-types-flow';
import includes from 'array-includes';
import has from 'has';
import hasOwn from 'hasown';
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
import getElementType from '../util/getElementType';
Expand Down Expand Up @@ -70,7 +70,7 @@ export default ({
// Allow overrides from rule configuration for specific elements and
// roles.
const allowedRoles = (options[0] || {});
if (has(allowedRoles, type) && includes(allowedRoles[type], role)) {
if (hasOwn(allowedRoles, type) && includes(allowedRoles[type], role)) {
return;
}
if (
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-noninteractive-element-interactions.js
Expand Up @@ -17,7 +17,7 @@ import {
} from 'jsx-ast-utils';
import type { JSXOpeningElement } from 'ast-types-flow';
import includes from 'array-includes';
import has from 'has';
import hasOwn from 'hasown';
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
import { arraySchema, generateObjSchema } from '../util/schemas';
import getElementType from '../util/getElementType';
Expand Down Expand Up @@ -62,7 +62,7 @@ export default ({
const config = (options[0] || {});
const interactiveProps = config.handlers || defaultInteractiveProps;
// Allow overrides from rule configuration for specific elements and roles.
if (has(config, type)) {
if (hasOwn(config, type)) {
attributes = attributes.filter((attr) => attr.type !== 'JSXSpreadAttribute' && !includes(config[type], propName(attr)));
}

Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-noninteractive-element-to-interactive-role.js
Expand Up @@ -15,7 +15,7 @@ import {
} from 'jsx-ast-utils';
import type { JSXIdentifier } from 'ast-types-flow';
import includes from 'array-includes';
import has from 'has';
import hasOwn from 'hasown';
import type { ESLintConfig, ESLintContext, ESLintVisitorSelectorConfig } from '../../flow/eslint';
import type { ESLintJSXAttribute } from '../../flow/eslint-jsx';
import getElementType from '../util/getElementType';
Expand Down Expand Up @@ -68,7 +68,7 @@ export default ({
// Allow overrides from rule configuration for specific elements and
// roles.
const allowedRoles = (options[0] || {});
if (has(allowedRoles, type) && includes(allowedRoles[type], role)) {
if (hasOwn(allowedRoles, type) && includes(allowedRoles[type], role)) {
return;
}
if (
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-redundant-roles.js
Expand Up @@ -10,7 +10,7 @@
// ----------------------------------------------------------------------------

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

if (has(allowedRedundantRoles, type)) {
if (hasOwn(allowedRedundantRoles, type)) {
redundantRolesForElement = allowedRedundantRoles[type];
} else {
redundantRolesForElement = DEFAULT_ROLE_EXCEPTIONS[type] || [];
Expand Down
4 changes: 2 additions & 2 deletions src/util/getElementType.js
Expand Up @@ -3,7 +3,7 @@
*/

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

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

return has(componentMap, rawType) ? componentMap[rawType] : rawType;
return hasOwn(componentMap, rawType) ? componentMap[rawType] : rawType;
};
};

Expand Down

0 comments on commit 9a8edde

Please sign in to comment.