Skip to content

Commit 0852aa6

Browse files
MichaelDeBoeyljharb
authored andcommitted
[Refactor] don't destructure builtins
1 parent 9ff0f5f commit 0852aa6

9 files changed

+9
-27
lines changed

__mocks__/genInteractives.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import JSXElementMock from './JSXElementMock';
1010
import type { JSXAttributeMockType } from './JSXAttributeMock';
1111
import type { JSXElementMockType } from './JSXElementMock';
1212

13-
const { fromEntries } = Object;
14-
1513
const domElements = dom.keys();
1614
const roleNames = roles.keys();
1715

@@ -122,7 +120,7 @@ const nonInteractiveElementsMap: {[string]: Array<{[string]: string}>} = {
122120
ul: [],
123121
};
124122

125-
const indeterminantInteractiveElementsMap: { [key: string]: Array<any> } = fromEntries(domElements.map((name) => [name, []]));
123+
const indeterminantInteractiveElementsMap: { [key: string]: Array<any> } = Object.fromEntries(domElements.map((name) => [name, []]));
126124

127125
Object.keys(interactiveElementsMap)
128126
.concat(Object.keys(nonInteractiveElementsMap))

__tests__/__util__/helpers/parsers.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import path from 'path';
22
import semver from 'semver';
33
import { version } from 'eslint/package.json';
44

5-
const { entries } = Object;
6-
75
let tsParserVersion;
86
try {
97
// eslint-disable-next-line import/no-unresolved, global-require
@@ -23,7 +21,7 @@ function minEcmaVersion(features, parserOptions) {
2321
const result = Math.max(
2422
...[].concat(
2523
(parserOptions && parserOptions.ecmaVersion) || [],
26-
entries(minEcmaVersionForFeatures).flatMap((entry) => {
24+
Object.entries(minEcmaVersionForFeatures).flatMap((entry) => {
2725
const f = entry[0];
2826
const y = entry[1];
2927
return features.has(f) ? y : [];

__tests__/__util__/ruleOptionsMapperFactory.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* @flow
33
*/
44

5-
const { fromEntries, entries } = Object;
6-
75
type ESLintTestRunnerTestCase = {
86
code: string,
97
errors: ?Array<{ message: string, type: string }>,
@@ -23,7 +21,7 @@ export default function ruleOptionsMapperFactory(ruleOptions: Array<mixed> = [])
2321
code,
2422
errors,
2523
// Flatten the array of objects in an array of one object.
26-
options: [fromEntries((options || []).concat(ruleOptions).flatMap((item) => entries((item: any))))],
24+
options: [Object.fromEntries((options || []).concat(ruleOptions).flatMap((item) => Object.entries((item: any))))],
2725
parserOptions,
2826
settings,
2927
};

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import isInteractiveElement from '../util/isInteractiveElement';
2323
import isNonInteractiveRole from '../util/isNonInteractiveRole';
2424
import isPresentationRole from '../util/isPresentationRole';
2525

26-
const { hasOwn } = Object;
27-
2826
const errorMessage = 'Interactive elements should not be assigned non-interactive roles.';
2927

3028
export default ({
@@ -68,7 +66,7 @@ export default ({
6866
// Allow overrides from rule configuration for specific elements and
6967
// roles.
7068
const allowedRoles = (options[0] || {});
71-
if (hasOwn(allowedRoles, type) && allowedRoles[type].includes(role)) {
69+
if (Object.hasOwn(allowedRoles, type) && allowedRoles[type].includes(role)) {
7270
return;
7371
}
7472
if (

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import isNonInteractiveElement from '../util/isNonInteractiveElement';
2828
import isNonInteractiveRole from '../util/isNonInteractiveRole';
2929
import isPresentationRole from '../util/isPresentationRole';
3030

31-
const { hasOwn } = Object;
32-
3331
const errorMessage = 'Non-interactive elements should not be assigned mouse or keyboard event listeners.';
3432

3533
const defaultInteractiveProps = [].concat(
@@ -61,7 +59,7 @@ export default ({
6159
const config = (options[0] || {});
6260
const interactiveProps = config.handlers || defaultInteractiveProps;
6361
// Allow overrides from rule configuration for specific elements and roles.
64-
if (hasOwn(config, type)) {
62+
if (Object.hasOwn(config, type)) {
6563
attributes = attributes.filter((attr) => attr.type !== 'JSXSpreadAttribute' && !config[type].includes(propName(attr)));
6664
}
6765

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import getExplicitRole from '../util/getExplicitRole';
2121
import isNonInteractiveElement from '../util/isNonInteractiveElement';
2222
import isInteractiveRole from '../util/isInteractiveRole';
2323

24-
const { hasOwn } = Object;
25-
2624
const errorMessage = 'Non-interactive elements should not be assigned interactive roles.';
2725

2826
export default ({
@@ -66,7 +64,7 @@ export default ({
6664
// Allow overrides from rule configuration for specific elements and
6765
// roles.
6866
const allowedRoles = (options[0] || {});
69-
if (hasOwn(allowedRoles, type) && allowedRoles[type].includes(role)) {
67+
if (Object.hasOwn(allowedRoles, type) && allowedRoles[type].includes(role)) {
7068
return;
7169
}
7270
if (

src/rules/no-redundant-roles.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import getElementType from '../util/getElementType';
1515
import getExplicitRole from '../util/getExplicitRole';
1616
import getImplicitRole from '../util/getImplicitRole';
1717

18-
const { hasOwn } = Object;
19-
2018
const errorMessage = (element: string, implicitRole: string) => (
2119
`The element ${element} has an implicit role of ${implicitRole}. Defining this explicitly is redundant and should be avoided.`
2220
);
@@ -58,7 +56,7 @@ export default ({
5856
const allowedRedundantRoles = (options[0] || {});
5957
let redundantRolesForElement;
6058

61-
if (hasOwn(allowedRedundantRoles, type)) {
59+
if (Object.hasOwn(allowedRedundantRoles, type)) {
6260
redundantRolesForElement = allowedRedundantRoles[type];
6361
} else {
6462
redundantRolesForElement = DEFAULT_ROLE_EXCEPTIONS[type] || [];

src/util/getElementType.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { elementType, getProp, getLiteralPropValue } from 'jsx-ast-utils';
77

88
import type { ESLintContext } from '../../flow/eslint';
99

10-
const { hasOwn } = Object;
11-
1210
const getElementType = (context: ESLintContext): ((node: JSXOpeningElement) => string) => {
1311
const { settings } = context;
1412
const polymorphicPropName = settings['jsx-a11y']?.polymorphicPropName;
@@ -31,7 +29,7 @@ const getElementType = (context: ESLintContext): ((node: JSXOpeningElement) => s
3129
return rawType;
3230
}
3331

34-
return hasOwn(componentMap, rawType) ? componentMap[rawType] : rawType;
32+
return Object.hasOwn(componentMap, rawType) ? componentMap[rawType] : rawType;
3533
};
3634
};
3735

src/util/getSuggestion.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import editDistance from 'damerau-levenshtein';
22

3-
const { fromEntries } = Object;
4-
53
// Minimum edit distance to be considered a good suggestion.
64
const THRESHOLD = 2;
75

@@ -10,7 +8,7 @@ const THRESHOLD = 2;
108
* to return.
119
*/
1210
export default function getSuggestion(word, dictionary = [], limit = 2) {
13-
const distances = fromEntries(
11+
const distances = Object.fromEntries(
1412
dictionary.map((dictionaryWord) => {
1513
const distance = editDistance(word.toUpperCase(), dictionaryWord.toUpperCase());
1614
const { steps } = distance;

0 commit comments

Comments
 (0)