Skip to content

Commit

Permalink
Lodash: Refactor some _.isEmpty() instances (#47353)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Jan 24, 2023
1 parent 4be3528 commit 15aea27
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 36 deletions.
7 changes: 1 addition & 6 deletions packages/block-editor/src/components/font-family/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -25,7 +20,7 @@ export default function FontFamilyControl( {
fontFamilies = blockLevelFontFamilies;
}

if ( isEmpty( fontFamilies ) ) {
if ( ! fontFamilies || fontFamilies.length === 0 ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -39,7 +34,7 @@ export default function ImageSizeControl( {

return (
<>
{ ! isEmpty( imageSizeOptions ) && (
{ imageSizeOptions && imageSizeOptions.length > 0 && (
<SelectControl
__nextHasNoMarginBottom
label={ __( 'Image size' ) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -135,7 +130,7 @@ function InserterSearchResults( {
);

const hasItems =
! isEmpty( filteredBlockTypes ) || ! isEmpty( filteredBlockPatterns );
filteredBlockTypes.length > 0 || filteredBlockPatterns.length > 0;

const blocksUI = !! filteredBlockTypes.length && (
<InserterPanel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -211,5 +206,5 @@ export function isValuesDefined( values ) {
if ( values === undefined || values === null ) {
return false;
}
return ! isEmpty( Object.values( values ).filter( ( value ) => !! value ) );
return Object.values( values ).filter( ( value ) => !! value ).length > 0;
}
7 changes: 1 addition & 6 deletions packages/block-library/src/heading/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -41,7 +36,7 @@ export const settings = {
}

if ( context === 'accessibility' ) {
return isEmpty( content )
return ! content || content.length === 0
? sprintf(
/* translators: accessibility text. %s: heading level. */
__( 'Level %s. Empty.' ),
Expand Down
7 changes: 1 addition & 6 deletions packages/block-library/src/paragraph/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -35,7 +30,7 @@ export const settings = {
__experimentalLabel( attributes, { context } ) {
if ( context === 'accessibility' ) {
const { content } = attributes;
return isEmpty( content ) ? __( 'Empty' ) : content;
return ! content || content.length === 0 ? __( 'Empty' ) : content;
}
},
transforms,
Expand Down

1 comment on commit 15aea27

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 15aea27.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3996533688
📝 Reported issues:

Please sign in to comment.