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 _.startsWith() #43019

Merged
merged 3 commits into from
Aug 9, 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 @@ -128,6 +128,7 @@ module.exports = {
'reverse',
'size',
'snakeCase',
'startsWith',
'stubFalse',
'stubTrue',
'sum',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { startsWith } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -20,6 +15,6 @@ import { isURL } from '@wordpress/url';
* @return {boolean} whether or not the value is potentially a URL.
*/
export default function isURLLike( val ) {
const isInternal = startsWith( val, '#' );
const isInternal = val?.startsWith( '#' );
return isURL( val ) || ( val && val.includes( 'www.' ) ) || isInternal;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import { getProtocol, prependHTTP } from '@wordpress/url';
import { useCallback } from '@wordpress/element';
import { useSelect } from '@wordpress/data';

/**
* External dependencies
*/
import { startsWith } from 'lodash';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -38,7 +33,7 @@ export const handleDirectEntry = ( val ) => {
type = TEL_TYPE;
}

if ( startsWith( val, '#' ) ) {
if ( val?.startsWith( '#' ) ) {
type = INTERNAL_TYPE;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/blocks/src/api/serializer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { isEmpty, reduce, castArray, startsWith } from 'lodash';
import { isEmpty, reduce, castArray } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -320,7 +320,7 @@ export function getCommentDelimitedContent(
: '';

// Strip core blocks of their namespace prefix.
const blockName = startsWith( rawBlockName, 'core/' )
const blockName = rawBlockName?.startsWith( 'core/' )
? rawBlockName.slice( 5 )
: rawBlockName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { find, startsWith, get, camelCase, has } from 'lodash';
import { find, get, camelCase, has } from 'lodash';
import { Dimensions } from 'react-native';

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ export function getBlockColors(

// Custom colors.
Object.entries( blockStyleAttributes ).forEach( ( [ key, value ] ) => {
const isCustomColor = startsWith( value, '#' );
const isCustomColor = value?.startsWith?.( '#' );
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
let styleKey = key;

if ( BLOCK_STYLE_ATTRIBUTES_MAPPING[ styleKey ] ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
pickBy,
reduce,
set,
startsWith,
} from 'lodash';

/**
Expand Down Expand Up @@ -50,7 +49,7 @@ function compileStyleValue( uncompiledValue ) {
const VARIABLE_REFERENCE_PREFIX = 'var:';
const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
if ( startsWith( uncompiledValue, VARIABLE_REFERENCE_PREFIX ) ) {
if ( uncompiledValue?.startsWith( VARIABLE_REFERENCE_PREFIX ) ) {
const variable = uncompiledValue
.slice( VARIABLE_REFERENCE_PREFIX.length )
.split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )
Expand Down
4 changes: 2 additions & 2 deletions test/integration/full-content/full-content.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import glob from 'fast-glob';
import { startsWith, get } from 'lodash';
import { get } from 'lodash';
import { format } from 'util';

/**
Expand Down Expand Up @@ -237,7 +237,7 @@ describe( 'full post content fixture', () => {
.filter(
( basename ) =>
basename === nameToFilename ||
startsWith( basename, nameToFilename + '__' )
basename.startsWith( nameToFilename + '__' )
)
.map( ( basename ) => {
const { filename: htmlFixtureFileName } =
Expand Down