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 _.isString() #42268

Merged
merged 2 commits into from
Jul 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module.exports = {
'isNil',
'isNumber',
'isObjectLike',
'isString',
'isUndefined',
'keyBy',
'keys',
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/colors/with-colors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { isString, kebabCase, reduce, upperFirst } from 'lodash';
import { kebabCase, reduce, upperFirst } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -78,7 +78,7 @@ function createColorHOC( colorTypes, withColorPalette ) {
( colorObject, colorType ) => {
return {
...colorObject,
...( isString( colorType )
...( typeof colorType === 'string'
? { [ colorType ]: kebabCase( colorType ) }
: colorType ),
};
Expand Down
12 changes: 2 additions & 10 deletions packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
/**
* External dependencies
*/
import {
camelCase,
isEmpty,
isObject,
isString,
mapKeys,
pick,
pickBy,
} from 'lodash';
import { camelCase, isEmpty, isObject, mapKeys, pick, pickBy } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -302,7 +294,7 @@ function translateBlockSettingUsingI18nSchema(
settingValue,
textdomain
) {
if ( isString( i18nSchema ) && isString( settingValue ) ) {
if ( typeof i18nSchema === 'string' && typeof settingValue === 'string' ) {
// eslint-disable-next-line @wordpress/i18n-no-variables, @wordpress/i18n-text-domain
return _x( settingValue, i18nSchema, textdomain );
}
Expand Down
6 changes: 3 additions & 3 deletions packages/blocks/src/api/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { every, has, isString, reduce, maxBy } from 'lodash';
import { every, has, reduce, maxBy } from 'lodash';
import { colord, extend } from 'colord';
import namesPlugin from 'colord/plugins/names';
import a11yPlugin from 'colord/plugins/a11y';
Expand Down Expand Up @@ -75,7 +75,7 @@ export function isUnmodifiedDefaultBlock( block ) {
export function isValidIcon( icon ) {
return (
!! icon &&
( isString( icon ) ||
( typeof icon === 'string' ||
isValidElement( icon ) ||
typeof icon === 'function' ||
icon instanceof Component )
Expand Down Expand Up @@ -126,7 +126,7 @@ export function normalizeIconObject( icon ) {
* @return {?Object} Block type.
*/
export function normalizeBlockType( blockTypeOrName ) {
if ( isString( blockTypeOrName ) ) {
if ( typeof blockTypeOrName === 'string' ) {
return getBlockType( blockTypeOrName );
}

Expand Down
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- `Slot`/`Fill`: Refactor away from Lodash ([#42153](https://github.com/WordPress/gutenberg/pull/42153/)).
- `ComboboxControl`: Refactor away from `_.deburr()` ([#42169](https://github.com/WordPress/gutenberg/pull/42169/)).
- `FormTokenField`: Refactor away from `_.identity()` ([#42215](https://github.com/WordPress/gutenberg/pull/42215/)).
- `MenuItem`: Refactor away from `_.isString()` ([#42268](https://github.com/WordPress/gutenberg/pull/42268/)).
- `Shortcut`: Refactor away from `_.isString()` ([#42268](https://github.com/WordPress/gutenberg/pull/42268/)).

### Bug Fix

Expand Down
3 changes: 1 addition & 2 deletions packages/components/src/menu-item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { isString } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -41,7 +40,7 @@ export function MenuItem( props, ref ) {
);
}

if ( icon && ! isString( icon ) ) {
if ( icon && typeof icon !== 'string' ) {
icon = cloneElement( icon, {
className: classnames( 'components-menu-items__item-icon', {
'has-icon-right': iconPosition === 'right',
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/shortcut/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { isString, isObject } from 'lodash';
import { isObject } from 'lodash';

/** @typedef {string | { display: string, ariaLabel: string }} Shortcut */
/**
Expand All @@ -22,7 +22,7 @@ function Shortcut( { shortcut, className } ) {
let displayText;
let ariaLabel;

if ( isString( shortcut ) ) {
if ( typeof shortcut === 'string' ) {
displayText = shortcut;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { isString } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -37,7 +36,7 @@ const ShortcutList = ( { shortcuts } ) => (
className="customize-widgets-keyboard-shortcut-help-modal__shortcut"
key={ index }
>
{ isString( shortcut ) ? (
{ typeof shortcut === 'string' ? (
<DynamicShortcut name={ shortcut } />
) : (
<Shortcut { ...shortcut } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { isString } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -41,7 +40,7 @@ const ShortcutList = ( { shortcuts } ) => (
className="edit-post-keyboard-shortcut-help-modal__shortcut"
key={ index }
>
{ isString( shortcut ) ? (
{ typeof shortcut === 'string' ? (
<DynamicShortcut name={ shortcut } />
) : (
<Shortcut { ...shortcut } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
forEach,
get,
isEmpty,
isString,
kebabCase,
pickBy,
reduce,
Expand Down Expand Up @@ -185,7 +184,7 @@ function getStylesDeclarations( blockStyles = {} ) {

const styleValue = get( blockStyles, pathToValue );

if ( !! properties && ! isString( styleValue ) ) {
if ( !! properties && typeof styleValue !== 'string' ) {
Object.entries( properties ).forEach( ( entry ) => {
const [ name, prop ] = entry;

Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/global-styles/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { get, find, isString } from 'lodash';
import { get, find } from 'lodash';

/* Supporting data. */
export const ROOT_BLOCK_NAME = 'root';
Expand Down Expand Up @@ -213,7 +213,7 @@ function getValueFromCustomVariable( features, blockName, variable, path ) {
}

export function getValueFromVariable( features, blockName, variable ) {
if ( ! variable || ! isString( variable ) ) {
if ( ! variable || typeof variable !== 'string' ) {
return variable;
}
const USER_VALUE_PREFIX = 'var:';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { isString } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -34,7 +33,7 @@ const ShortcutList = ( { shortcuts } ) => (
className="edit-site-keyboard-shortcut-help-modal__shortcut"
key={ index }
>
{ isString( shortcut ) ? (
{ typeof shortcut === 'string' ? (
<DynamicShortcut name={ shortcut } />
) : (
<Shortcut { ...shortcut } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { isString } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -37,7 +36,7 @@ const ShortcutList = ( { shortcuts } ) => (
className="edit-widgets-keyboard-shortcut-help-modal__shortcut"
key={ index }
>
{ isString( shortcut ) ? (
{ typeof shortcut === 'string' ? (
<DynamicShortcut name={ shortcut } />
) : (
<Shortcut { ...shortcut } />
Expand Down
9 changes: 4 additions & 5 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { find, get, has, isString, includes, some } from 'lodash';
import { find, get, has, includes, some } from 'lodash';
import createSelector from 'rememo';

/**
Expand Down Expand Up @@ -1605,10 +1605,9 @@ export function __experimentalGetTemplateInfo( state, template ) {
const { title: defaultTitle, description: defaultDescription } =
__experimentalGetDefaultTemplateType( state, slug );

const templateTitle = isString( title ) ? title : title?.rendered;
const templateDescription = isString( description )
? description
: description?.raw;
const templateTitle = typeof title === 'string' ? title : title?.rendered;
const templateDescription =
typeof description === 'string' ? description : description?.raw;
const templateIcon =
__experimentalGetDefaultTemplatePartAreas( state ).find(
( item ) => area === item.area
Expand Down
9 changes: 2 additions & 7 deletions packages/list-reusable-blocks/src/utils/import.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isString } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -31,8 +26,8 @@ async function importReusableBlock( file ) {
parsedContent.__file !== 'wp_block' ||
! parsedContent.title ||
! parsedContent.content ||
! isString( parsedContent.title ) ||
! isString( parsedContent.content )
typeof parsedContent.title !== 'string' ||
typeof parsedContent.content !== 'string'
) {
throw new Error( 'Invalid Reusable block JSON file' );
}
Expand Down
4 changes: 2 additions & 2 deletions packages/redux-routine/src/is-action.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { isPlainObject, isString } from 'lodash';
import { isPlainObject } from 'lodash';

/* eslint-disable jsdoc/valid-types */
/**
Expand All @@ -12,7 +12,7 @@ import { isPlainObject, isString } from 'lodash';
* @return {object is import('redux').AnyAction} Whether object is an action.
*/
export function isAction( object ) {
return isPlainObject( object ) && isString( object.type );
return isPlainObject( object ) && typeof object.type === 'string';
}

/**
Expand Down