Skip to content

Commit

Permalink
Lodash: Refactor away from _.isArray() (#41652)
Browse files Browse the repository at this point in the history
* Lodash: Refactor away from _.isArray()

* Restrict import
  • Loading branch information
tyxla authored Jun 11, 2022
1 parent 2fa50a6 commit ebb5d82
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 21 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module.exports = {
importNames: [
'differenceWith',
'findIndex',
'isArray',
'isUndefined',
'memoize',
'negate',
Expand Down
7 changes: 1 addition & 6 deletions packages/block-editor/src/components/list-view/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isArray } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -27,7 +22,7 @@ export const getBlockPositionDescription = ( position, siblingCount, level ) =>
* @return {boolean} Whether the block is in multi-selection set.
*/
export const isClientIdSelected = ( clientId, selectedBlockClientIds ) =>
isArray( selectedBlockClientIds ) && selectedBlockClientIds.length
Array.isArray( selectedBlockClientIds ) && selectedBlockClientIds.length
? selectedBlockClientIds.indexOf( clientId ) !== -1
: selectedBlockClientIds === clientId;

Expand Down
3 changes: 1 addition & 2 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import {
castArray,
first,
isArray,
isBoolean,
last,
map,
Expand Down Expand Up @@ -1450,7 +1449,7 @@ const checkAllowList = ( list, item, defaultResult = null ) => {
if ( isBoolean( list ) ) {
return list;
}
if ( isArray( list ) ) {
if ( Array.isArray( list ) ) {
// TODO: when there is a canonical way to detect that we are editing a post
// the following check should be changed to something like:
// if ( list.includes( 'core/post-content' ) && getEditorMode() === 'post-content' && item === null )
Expand Down
5 changes: 2 additions & 3 deletions packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
import {
camelCase,
isArray,
isEmpty,
isNil,
isObject,
Expand Down Expand Up @@ -306,9 +305,9 @@ function translateBlockSettingUsingI18nSchema(
return _x( settingValue, i18nSchema, textdomain );
}
if (
isArray( i18nSchema ) &&
Array.isArray( i18nSchema ) &&
! isEmpty( i18nSchema ) &&
isArray( settingValue )
Array.isArray( settingValue )
) {
return settingValue.map( ( value ) =>
translateBlockSettingUsingI18nSchema(
Expand Down
4 changes: 2 additions & 2 deletions packages/blocks/src/api/templates.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { every, map, get, mapValues, isArray } from 'lodash';
import { every, map, get, mapValues } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -84,7 +84,7 @@ export function synchronizeBlocksWithTemplate( blocks = [], template ) {
} );
};
const normalizeAttribute = ( definition, value ) => {
if ( isHTMLAttribute( definition ) && isArray( value ) ) {
if ( isHTMLAttribute( definition ) && Array.isArray( value ) ) {
// Introduce a deprecated call at this point
// When we're confident that "children" format should be removed from the templates.

Expand Down
3 changes: 1 addition & 2 deletions packages/components/src/button/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
View,
Platform,
} from 'react-native';
import { isArray } from 'lodash';
import { LongPressGestureHandler, State } from 'react-native-gesture-handler';

/**
Expand Down Expand Up @@ -153,7 +152,7 @@ export function Button( props ) {
( !! label &&
// The children are empty and...
( ! children ||
( isArray( children ) && ! children.length ) ) &&
( Array.isArray( children ) && ! children.length ) ) &&
// The tooltip is not explicitly disabled.
false !== showTooltip ) );

Expand Down
4 changes: 2 additions & 2 deletions packages/edit-post/src/components/block-manager/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { filter, includes, isArray } from 'lodash';
import { filter, includes } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -119,7 +119,7 @@ export default withSelect( ( select ) => {
const { getHiddenBlockTypes } = select( editPostStore );
const hiddenBlockTypes = getHiddenBlockTypes();
const numberOfHiddenBlocks =
isArray( hiddenBlockTypes ) && hiddenBlockTypes.length;
Array.isArray( hiddenBlockTypes ) && hiddenBlockTypes.length;

return {
blockTypes: getBlockTypes(),
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/theme-support-check/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { castArray, includes, isArray, get, some } from 'lodash';
import { castArray, includes, get, some } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -26,7 +26,7 @@ export function ThemeSupportCheck( {
// In the latter case, we need to verify `postType` exists
// within `supported`. If `postType` isn't passed, then the check
// should fail.
if ( 'post-thumbnails' === key && isArray( supported ) ) {
if ( 'post-thumbnails' === key && Array.isArray( supported ) ) {
return includes( supported, postType );
}
return supported;
Expand Down
4 changes: 2 additions & 2 deletions packages/element/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { isArray, isNumber, isString } from 'lodash';
import { isNumber, isString } from 'lodash';

/**
* Checks if the provided WP element is empty.
Expand All @@ -14,7 +14,7 @@ export const isEmptyElement = ( element ) => {
return false;
}

if ( isString( element ) || isArray( element ) ) {
if ( isString( element ) || Array.isArray( element ) ) {
return ! element.length;
}

Expand Down

0 comments on commit ebb5d82

Please sign in to comment.