Skip to content

Commit

Permalink
Apply eslint autofix for curly rule violations
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Apr 30, 2024
1 parent d6226be commit 0221522
Show file tree
Hide file tree
Showing 151 changed files with 875 additions and 306 deletions.
7 changes: 5 additions & 2 deletions bin/api-docs/gen-theme-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,13 @@ const formatType = ( prop ) => {
const types = [];

propTypes.forEach( ( item ) => {
if ( item.type ) types.push( item.type );
if ( item.type ) {
types.push( item.type );
}
// refComplete is always an object
if ( item.$ref && item.$ref === '#/definitions/refComplete' )
if ( item.$ref && item.$ref === '#/definitions/refComplete' ) {
types.push( 'object' );
}
} );

type = [ ...new Set( types ) ].join( ', ' );
Expand Down
4 changes: 3 additions & 1 deletion bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ function sanitizeBranchName( branch ) {
* @return {number|undefined} Median value or undefined if array empty.
*/
function median( array ) {
if ( ! array || ! array.length ) return undefined;
if ( ! array || ! array.length ) {
return undefined;
}

const numbers = [ ...array ].sort( ( a, b ) => a - b );
const middleIndex = Math.floor( numbers.length / 2 );
Expand Down
4 changes: 3 additions & 1 deletion packages/block-editor/src/components/alignment-control/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ function AlignmentUI( {
);

function setIcon() {
if ( activeAlignment ) return activeAlignment.icon;
if ( activeAlignment ) {
return activeAlignment.icon;
}
return isRTL() ? alignRight : alignLeft;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export const BlockMover = ( {
const option = blockPageMoverOptions.find(
( el ) => el.value === value
);
if ( option && option.onSelect ) option.onSelect();
if ( option && option.onSelect ) {
option.onSelect();
}
};

const onLongPressMoveUp = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ function PatternTransformationsMenu( {
} ) {
const [ showTransforms, setShowTransforms ] = useState( false );
const patterns = useTransformedPatterns( statePatterns, blocks );
if ( ! patterns.length ) return null;
if ( ! patterns.length ) {
return null;
}

return (
<MenuGroup className="block-editor-block-switcher__pattern__transforms__menugroup">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export const getPatternTransformedBlocks = (
selectedBlock.name,
consumedBlocks
);
if ( ! match ) continue;
if ( ! match ) {
continue;
}
isMatch = true;
consumedBlocks.add( match.clientId );
// We update (mutate) the matching pattern block.
Expand All @@ -71,7 +73,9 @@ export const getPatternTransformedBlocks = (
break;
}
// Bail eary if a selected block has not been matched.
if ( ! isMatch ) return;
if ( ! isMatch ) {
return;
}
}
return _patternBlocks;
};
Expand Down
19 changes: 14 additions & 5 deletions packages/block-editor/src/components/block-switcher/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ export const getMatchingBlockByName = (
) => {
const { clientId, name, innerBlocks = [] } = block;
// Check if block has been consumed already.
if ( consumedBlocks.has( clientId ) ) return;
if ( name === selectedBlockName ) return block;
if ( consumedBlocks.has( clientId ) ) {
return;
}
if ( name === selectedBlockName ) {
return block;
}
// Try to find a matching block from InnerBlocks recursively.
for ( const innerBlock of innerBlocks ) {
const match = getMatchingBlockByName(
innerBlock,
selectedBlockName,
consumedBlocks
);
if ( match ) return match;
if ( match ) {
return match;
}
}
};

Expand All @@ -47,11 +53,14 @@ export const getMatchingBlockByName = (
*/
export const getRetainedBlockAttributes = ( name, attributes ) => {
const contentAttributes = getBlockAttributesNamesByRole( name, 'content' );
if ( ! contentAttributes?.length ) return attributes;
if ( ! contentAttributes?.length ) {
return attributes;
}

return contentAttributes.reduce( ( _accumulator, attribute ) => {
if ( attributes[ attribute ] )
if ( attributes[ attribute ] ) {
_accumulator[ attribute ] = attributes[ attribute ];
}
return _accumulator;
}, {} );
};
4 changes: 3 additions & 1 deletion packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export default function BlockTools( {
} = unlock( useDispatch( blockEditorStore ) );

function onKeyDown( event ) {
if ( event.defaultPrevented ) return;
if ( event.defaultPrevented ) {
return;
}

if ( isMatch( 'core/block-editor/move-up', event ) ) {
const clientIds = getSelectedBlockClientIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ function __experimentalBlockVariationTransforms( { blockClientId } ) {
};

// Skip rendering if there are no variations
if ( ! variations?.length ) return null;
if ( ! variations?.length ) {
return null;
}

const baseClass = 'block-editor-block-variation-transforms';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ const FloatingToolbar = ( {
}, [ showFloatingToolbar ] );

useEffect( () => {
if ( showFloatingToolbar )
if ( showFloatingToolbar ) {
setPreviousSelection( { clientId: selectedClientId, parentId } );
}
}, [ selectedClientId ] );

const translationRange =
Expand Down Expand Up @@ -115,7 +116,9 @@ export default compose( [

const selectedClientId = getSelectedBlockClientId();

if ( ! selectedClientId ) return;
if ( ! selectedClientId ) {
return;
}

const rootBlockId = getBlockHierarchyRootClientId( selectedClientId );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,9 @@ export default function ColorPanel( {
].filter( Boolean );

elements.forEach( ( { name, label, showPanel } ) => {
if ( ! showPanel ) return;
if ( ! showPanel ) {
return;
}

const elementBackgroundColor = decodeValue(
inheritedValue?.elements?.[ name ]?.color?.background
Expand Down
4 changes: 3 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ function InserterMenu(
__nextHasNoMarginBottom
className="block-editor-inserter__search"
onChange={ ( value ) => {
if ( hoveredItem ) setHoveredItem( null );
if ( hoveredItem ) {
setHoveredItem( null );
}
setFilterValue( value );
} }
value={ filterValue }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const LineHeightControl = ( {

const adjustNextValue = ( nextValue, wasTypedOrPasted ) => {
// Set the next value without modification if lineHeight has been defined.
if ( isDefined ) return nextValue;
if ( isDefined ) {
return nextValue;
}

/**
* The following logic handles the initial spin up/down action
Expand All @@ -47,7 +49,9 @@ const LineHeightControl = ( {
case '0': {
// This means the user explicitly input '0', rather than using the
// spin down action from an undefined value state.
if ( wasTypedOrPasted ) return nextValue;
if ( wasTypedOrPasted ) {
return nextValue;
}
// Decrement by spin value.
return BASE_DEFAULT_VALUE - spin;
}
Expand Down
12 changes: 9 additions & 3 deletions packages/block-editor/src/components/link-control/search-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,19 @@ function SearchItemIcon( { isURL, suggestion } ) {
function addLeadingSlash( url ) {
const trimmedURL = url?.trim();

if ( ! trimmedURL?.length ) return url;
if ( ! trimmedURL?.length ) {
return url;
}

return url?.replace( /^\/?/, '/' );
}

function removeTrailingSlash( url ) {
const trimmedURL = url?.trim();

if ( ! trimmedURL?.length ) return url;
if ( ! trimmedURL?.length ) {
return url;
}

return url?.replace( /\/$/, '' );
}
Expand All @@ -95,7 +99,9 @@ const defaultTo = ( d ) => ( v ) => {
* @return {string} the processed url to display.
*/
function getURLForDisplay( url ) {
if ( ! url ) return url;
if ( ! url ) {
return url;
}

return pipe(
safeDecodeURI,
Expand Down
4 changes: 3 additions & 1 deletion packages/block-editor/src/components/list-view/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export function focusListItem( focusClientId, treeGridElement ) {
const row = treeGridElement?.querySelector(
`[role=row][data-block="${ focusClientId }"]`
);
if ( ! row ) return null;
if ( ! row ) {
return null;
}
// Focus the first focusable in the row, which is the ListViewBlockSelectButton.
return focus.focusable.find( row )[ 0 ];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ function useToolbarFocus( {
}
return () => {
window.cancelAnimationFrame( raf );
if ( ! onIndexChange || ! navigableToolbarRef ) return;
if ( ! onIndexChange || ! navigableToolbarRef ) {
return;
}
// When the toolbar element is unmounted and onIndexChange is passed, we
// pass the focused toolbar item index so it can be hydrated later.
const items = getAllFocusableToolbarItemsIn( navigableToolbarRef );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ export default function useBlockSync( {
// the subscription is triggering for a block (`clientId !== null`)
// and its block name can't be found because it's not on the list.
// (`getBlockName( clientId ) === null`).
if ( clientId !== null && getBlockName( clientId ) === null )
if ( clientId !== null && getBlockName( clientId ) === null ) {
return;
}

// When RESET_BLOCKS on parent blocks get called, the controlled blocks
// can reset to uncontrolled, in these situations, it means we need to populate
Expand Down
8 changes: 6 additions & 2 deletions packages/block-editor/src/components/rich-text/multiline.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,19 @@ function RichTextMultiline(
const newValues = values.slice();
let offset = 0;
if ( forward ) {
if ( ! newValues[ index + 1 ] ) return;
if ( ! newValues[ index + 1 ] ) {
return;
}
newValues.splice(
index,
2,
newValues[ index ] + newValues[ index + 1 ]
);
offset = newValues[ index ].length - 1;
} else {
if ( ! newValues[ index - 1 ] ) return;
if ( ! newValues[ index - 1 ] ) {
return;
}
newValues.splice(
index - 1,
2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const interactiveContentTags = new Set( [
] );

function prefixSelectKeys( selected, prefix ) {
if ( typeof selected !== 'object' ) return { [ prefix ]: selected };
if ( typeof selected !== 'object' ) {
return { [ prefix ]: selected };
}
return Object.fromEntries(
Object.entries( selected ).map( ( [ key, value ] ) => [
`${ prefix }.${ key }`,
Expand All @@ -39,7 +41,9 @@ function prefixSelectKeys( selected, prefix ) {
}

function getPrefixedSelectKeys( selected, prefix ) {
if ( selected[ prefix ] ) return selected[ prefix ];
if ( selected[ prefix ] ) {
return selected[ prefix ];
}
return Object.keys( selected )
.filter( ( key ) => key.startsWith( prefix + '.' ) )
.reduce( ( accumulator, key ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,18 @@ function getPositionTypeLabel( attributes ) {
export default function useBlockDisplayInformation( clientId ) {
return useSelect(
( select ) => {
if ( ! clientId ) return null;
if ( ! clientId ) {
return null;
}
const { getBlockName, getBlockAttributes } =
select( blockEditorStore );
const { getBlockType, getActiveBlockVariation } =
select( blocksStore );
const blockName = getBlockName( clientId );
const blockType = getBlockType( blockName );
if ( ! blockType ) return null;
if ( ! blockType ) {
return null;
}
const attributes = getBlockAttributes( clientId );
const match = getActiveBlockVariation( blockName, attributes );
const isSynced =
Expand All @@ -95,7 +99,9 @@ export default function useBlockDisplayInformation( clientId ) {
positionType: attributes?.style?.position?.type,
name: attributes?.metadata?.name,
};
if ( ! match ) return blockTypeInfo;
if ( ! match ) {
return blockTypeInfo;
}

return {
isSynced,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ export default function useOnBlockDrop(
initialPosition = 0,
clientIdsToReplace = []
) => {
if ( ! Array.isArray( blocks ) ) blocks = [ blocks ];
if ( ! Array.isArray( blocks ) ) {
blocks = [ blocks ];
}

const clientIds = getBlockOrder( targetRootClientId );
const clientId = clientIds[ targetBlockIndex ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import { store as blockEditorStore } from '../../store';
function setContentEditableWrapper( node, value ) {
node.contentEditable = value;
// Firefox doesn't automatically move focus.
if ( value ) node.focus();
if ( value ) {
node.focus();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ export default function useTabNav() {
// do it again here because after clearing block selection,
// focus land on the writing flow container and pressing Tab
// will no longer send focus through the focus capture element.
if ( event.target === node ) setNavigationMode( true );
if ( event.target === node ) {
setNavigationMode( true );
}
return;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ function useDuotoneStyles( {
const blockElement = useBlockElement( clientId );

useEffect( () => {
if ( ! isValidFilter ) return;
if ( ! isValidFilter ) {
return;
}

// Safari does not always update the duotone filter when the duotone colors
// are changed. When using Safari, force the block element to be repainted by
Expand Down

0 comments on commit 0221522

Please sign in to comment.