Skip to content

Commit

Permalink
Lodash: Refactor away from _.isPlainObject() (#42508)
Browse files Browse the repository at this point in the history
* Lodash: Refactor away from _.isPlainObject()

* Revert package-lock.json changes

* Dedupe is-plain-obj

* Get rid of dev deps
  • Loading branch information
tyxla committed Aug 2, 2022
1 parent 22ba73a commit e3c8a6c
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 30 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -107,6 +107,7 @@ module.exports = {
'isNumber',
'isObject',
'isObjectLike',
'isPlainObject',
'isString',
'isUndefined',
'keyBy',
Expand Down
51 changes: 47 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/blocks/package.json
Expand Up @@ -43,6 +43,7 @@
"@wordpress/shortcode": "file:../shortcode",
"colord": "^2.7.0",
"hpq": "^1.3.0",
"is-plain-obj": "^4.1.0",
"lodash": "^4.17.21",
"memize": "^1.1.0",
"rememo": "^4.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/blocks/src/store/actions.js
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
import { castArray, isPlainObject, omit, pick, some } from 'lodash';
import isPlainObject from 'is-plain-obj';
import { castArray, omit, pick, some } from 'lodash';

/**
* WordPress dependencies
Expand Down
8 changes: 5 additions & 3 deletions packages/components/src/text/hook.js
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { css } from '@emotion/react';
import { isPlainObject } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -167,8 +166,11 @@ export default function useText( props ) {
*/
if ( ! truncate && Array.isArray( children ) ) {
content = Children.map( children, ( child ) => {
// @ts-ignore
if ( ! isPlainObject( child ) || ! ( 'props' in child ) ) {
if (
typeof child !== 'object' ||
child === null ||
! ( 'props' in child )
) {
return child;
}

Expand Down
1 change: 1 addition & 0 deletions packages/data/package.json
Expand Up @@ -35,6 +35,7 @@
"@wordpress/priority-queue": "file:../priority-queue",
"@wordpress/redux-routine": "file:../redux-routine",
"equivalent-key-map": "^0.2.2",
"is-plain-obj": "^4.1.0",
"is-promise": "^4.0.0",
"lodash": "^4.17.21",
"redux": "^4.1.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/data/src/plugins/persistence/index.js
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
import { merge, isPlainObject } from 'lodash';
import isPlainObject from 'is-plain-obj';
import { merge } from 'lodash';

/**
* Internal dependencies
Expand Down
1 change: 1 addition & 0 deletions packages/element/package.json
Expand Up @@ -32,6 +32,7 @@
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.11",
"@wordpress/escape-html": "file:../escape-html",
"is-plain-obj": "^4.1.0",
"lodash": "^4.17.21",
"react": "^17.0.2",
"react-dom": "^17.0.2"
Expand Down
3 changes: 2 additions & 1 deletion packages/element/src/serialize.js
Expand Up @@ -28,7 +28,8 @@
/**
* External dependencies
*/
import { kebabCase, isPlainObject } from 'lodash';
import isPlainObject from 'is-plain-obj';
import { kebabCase } from 'lodash';

/**
* WordPress dependencies
Expand Down
14 changes: 5 additions & 9 deletions packages/npm-package-json-lint-config/test/index.test.js
@@ -1,17 +1,13 @@
/**
* External dependencies
*/
import isPlainObject from 'is-plain-obj';

/**
* Internal dependencies
*/
import config from '../';

const isPlainObject = ( obj ) => {
return (
typeof obj === 'object' &&
obj !== null &&
obj.constructor === Object &&
Object.prototype.toString.call( obj ) === '[object Object]'
);
};

describe( 'npm-package-json-lint config tests', () => {
it( 'should be an object', () => {
expect( isPlainObject( config ) ).toBeTruthy();
Expand Down
14 changes: 5 additions & 9 deletions packages/prettier-config/test/index.js
@@ -1,17 +1,13 @@
/**
* External dependencies
*/
import isPlainObject from 'is-plain-obj';

/**
* Internal dependencies
*/
import config from '../lib/';

const isPlainObject = ( obj ) => {
return (
typeof obj === 'object' &&
obj !== null &&
obj.constructor === Object &&
Object.prototype.toString.call( obj ) === '[object Object]'
);
};

describe( 'prettier config tests', () => {
it( 'should be an object', () => {
expect( isPlainObject( config ) ).toBeTruthy();
Expand Down
1 change: 1 addition & 0 deletions packages/redux-routine/package.json
Expand Up @@ -30,6 +30,7 @@
"sideEffects": false,
"dependencies": {
"@babel/runtime": "^7.16.0",
"is-plain-obj": "^4.1.0",
"is-promise": "^4.0.0",
"lodash": "^4.17.21",
"rungen": "^0.3.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/redux-routine/src/is-action.js
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { isPlainObject } from 'lodash';
import isPlainObject from 'is-plain-obj';

/* eslint-disable jsdoc/valid-types */
/**
Expand Down
2 changes: 1 addition & 1 deletion test/native/jest.config.js
Expand Up @@ -65,7 +65,7 @@ module.exports = {
// See: https://github.com/wordpress-mobile/gutenberg-mobile/pull/257#discussion_r234978268
// There is no overloading in jest so we need to rewrite the config from react-native-jest-preset:
// https://github.com/facebook/react-native/blob/HEAD/jest-preset.json#L20
'node_modules/(?!(simple-html-tokenizer|(jest-)?react-native|@react-native|react-clone-referenced-element|@react-navigation))',
'node_modules/(?!(simple-html-tokenizer|is-plain-obj|(jest-)?react-native|@react-native|react-clone-referenced-element|@react-navigation))',
],
snapshotSerializers: [ '@emotion/jest/serializer' ],
reporters: [ 'default', 'jest-junit' ],
Expand Down
1 change: 1 addition & 0 deletions test/unit/jest.config.js
Expand Up @@ -36,6 +36,7 @@ module.exports = {
transform: {
'^.+\\.[jt]sx?$': '<rootDir>/test/unit/scripts/babel-transformer.js',
},
transformIgnorePatterns: [ 'node_modules/(?!(is-plain-obj))' ],
snapshotSerializers: [
'enzyme-to-json/serializer',
'@emotion/jest/serializer',
Expand Down

0 comments on commit e3c8a6c

Please sign in to comment.