Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lodash: Refactor away from _.isArray() #41652

Merged
merged 2 commits into from Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
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
@@ -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
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
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
@@ -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
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
@@ -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
@@ -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
@@ -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