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

fix(dependencies): stopping (and preventing) full lodash library import... now using only method level imports. #26710

Merged
merged 8 commits into from
Jan 23, 2024
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
2 changes: 2 additions & 0 deletions superset-frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module.exports = {
'prettier',
'react',
'file-progress',
'lodash',
'theme-colors',
'translation-vars',
],
Expand Down Expand Up @@ -241,6 +242,7 @@ module.exports = {
'jsx-a11y/anchor-is-valid': 1,
'jsx-a11y/click-events-have-key-events': 0, // re-enable up for discussion
'jsx-a11y/mouse-events-have-key-events': 0, // re-enable up for discussion
'lodash/import-scope': [2, 'member'],
'new-cap': 0,
'no-bitwise': 0,
'no-continue': 0,
Expand Down
25 changes: 25 additions & 0 deletions superset-frontend/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 superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
"eslint-plugin-jest": "^24.7.0",
"eslint-plugin-jest-dom": "^3.6.5",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-lodash": "^7.4.0",
"eslint-plugin-no-only-tests": "^2.4.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.22.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
/* eslint-disable sort-keys */

const Generator = require('yeoman-generator');
const _ = require('lodash');
Copy link
Member

Choose a reason for hiding this comment

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

Can't we do const { kebabCase, startCase, camelCase, upperFirst } = require('lodash'); instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just saw this after merging..... but... yes I suppose we can. I'll open a smaller/less contentious PR on some rainy day

// eslint-disable-next-line lodash/import-scope
const kebabCase = require('lodash/kebabCase');
// eslint-disable-next-line lodash/import-scope
const startCase = require('lodash/startCase');
// eslint-disable-next-line lodash/import-scope
const camelCase = require('lodash/camelCase');
// eslint-disable-next-line lodash/import-scope
const upperFirst = require('lodash/upperFirst');

module.exports = class extends Generator {
async prompting() {
Expand All @@ -32,23 +39,23 @@ module.exports = class extends Generator {
name: 'packageName',
message: 'Package name:',
// Default to current folder name, e.g. superset-plugin-chart-hello-world
default: _.kebabCase(this.appname),
default: kebabCase(this.appname),
},
{
type: 'input',
name: 'pluginName',
message: 'Plugin name:',
// Hello World
default: _.startCase(
_.camelCase(this.appname.replace('superset plugin chart', '').trim()),
default: startCase(
camelCase(this.appname.replace('superset plugin chart', '').trim()),
),
},
{
type: 'input',
name: 'description',
message: 'Description:',
// Superset Plugin Chart Hello World
default: _.upperFirst(_.startCase(this.appname)),
default: upperFirst(startCase(this.appname)),
},
{
type: 'list',
Expand All @@ -70,7 +77,7 @@ module.exports = class extends Generator {

writing() {
// SupersetPluginChartHelloWorld
const packageLabel = _.upperFirst(_.camelCase(this.answers.packageName));
const packageLabel = upperFirst(camelCase(this.answers.packageName));

const params = {
...this.answers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import isEmpty from 'lodash/isEmpty';
import isBoolean from 'lodash/isBoolean';
import { isEmpty, isBoolean } from 'lodash';

import { QueryObject } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import omit from 'lodash/omit';
import { omit } from 'lodash';

import {
AdhocColumn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
* under the License.
*/

import camelCase from 'lodash/camelCase';
import isPlainObject from 'lodash/isPlainObject';
import mapKeys from 'lodash/mapKeys';
import { camelCase, isPlainObject, mapKeys } from 'lodash';

export default function convertKeysToCamelCase<T>(object: T) {
if (object === null || object === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { EChartsCoreOption, GaugeSeriesOption } from 'echarts';
import { GaugeDataItemOption } from 'echarts/types/src/chart/gauge/GaugeSeries';
import { CallbackDataParams } from 'echarts/types/src/util/types';
import range from 'lodash/range';
import { range } from 'lodash';
import { parseNumbersList } from '../utils/controls';
import {
DEFAULT_FORM_DATA as DEFAULT_GAUGE_FORM_DATA,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import { DataRecord, DataRecordValue } from '@superset-ui/core';
import _ from 'lodash';
import { groupBy as _groupBy, isNumber, transform } from 'lodash';

export type TreeNode = {
name: DataRecordValue;
Expand All @@ -28,7 +28,7 @@ export type TreeNode = {
};

function getMetricValue(datum: DataRecord, metric: string) {
return _.isNumber(datum[metric]) ? (datum[metric] as number) : 0;
return isNumber(datum[metric]) ? (datum[metric] as number) : 0;
}

export function treeBuilder(
Expand All @@ -38,8 +38,8 @@ export function treeBuilder(
secondaryMetric?: string,
): TreeNode[] {
const [curGroupBy, ...restGroupby] = groupBy;
const curData = _.groupBy(data, curGroupBy);
return _.transform(
const curData = _groupBy(data, curGroupBy);
return transform(
curData,
(result, value, key) => {
const name = curData[key][0][curGroupBy]!;
Expand Down
3 changes: 1 addition & 2 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import {
t,
isFeatureEnabled,
} from '@superset-ui/core';
import invert from 'lodash/invert';
import mapKeys from 'lodash/mapKeys';
import { invert, mapKeys } from 'lodash';

import { now } from 'src/utils/dates';
import {
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/SqlLab/components/App/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { Redirect } from 'react-router-dom';
import { css, styled, t } from '@superset-ui/core';
import throttle from 'lodash/throttle';
import { throttle } from 'lodash';
import {
LOCALSTORAGE_MAX_USAGE_KB,
LOCALSTORAGE_WARNING_THRESHOLD,
Expand Down
4 changes: 1 addition & 3 deletions superset-frontend/src/SqlLab/components/SqlEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ import {
} from '@superset-ui/core';
import type { QueryEditor, SqlLabRootState } from 'src/SqlLab/types';
import type { DatabaseObject } from 'src/features/databases/types';
import debounce from 'lodash/debounce';
import throttle from 'lodash/throttle';
import { debounce, throttle, isBoolean, isEmpty } from 'lodash';
import Modal from 'src/components/Modal';
import Mousetrap from 'mousetrap';
import Button from 'src/components/Button';
Expand Down Expand Up @@ -93,7 +92,6 @@ import {
} from 'src/utils/localStorageHelpers';
import { EmptyStateBig } from 'src/components/EmptyState';
import getBootstrapData from 'src/utils/getBootstrapData';
import { isBoolean, isEmpty } from 'lodash';
import TemplateParamsEditor from '../TemplateParamsEditor';
import SouthPane from '../SouthPane';
import SaveQuery, { QueryPayload } from '../SaveQuery';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React from 'react';
import pick from 'lodash/pick';
import { pick } from 'lodash';
import PropTypes from 'prop-types';
import { EditableTabs } from 'src/components/Tabs';
import { connect } from 'react-redux';
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/SqlLab/hooks/useQueryEditor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import pick from 'lodash/pick';
import { pick } from 'lodash';
import { shallowEqual, useSelector } from 'react-redux';
import { SqlLabRootState, QueryEditor } from 'src/SqlLab/types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import pick from 'lodash/pick';
import { pick } from 'lodash';
import { tableApiUtil } from 'src/hooks/apiResources/tables';
import {
BYTES_PER_CHAR,
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/components/DropdownButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import React, { ReactNode } from 'react';
import { AntdDropdown, AntdTooltip } from 'src/components';
import { styled } from '@superset-ui/core';
import kebabCase from 'lodash/kebabCase';
import { kebabCase } from 'lodash';

const StyledDropdownButton = styled.div`
.ant-btn-group {
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/components/Icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import React from 'react';
import _ from 'lodash';
import { startCase } from 'lodash';
import AntdEnhancedIcons from './AntdEnhanced';
import Icon from './Icon';
import IconType from './IconType';
Expand Down Expand Up @@ -168,7 +168,7 @@ const IconFileNames = [

const iconOverrides: Record<string, React.FC<IconType>> = {};
IconFileNames.forEach(fileName => {
const keyName = _.startCase(fileName).replace(/ /g, '');
const keyName = startCase(fileName).replace(/ /g, '');
iconOverrides[keyName] = (props: IconType) => (
<Icon fileName={fileName} {...props} />
);
Expand Down
3 changes: 1 addition & 2 deletions superset-frontend/src/components/Select/AsyncSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import React, {
} from 'react';
import { ensureIsArray, t, usePrevious } from '@superset-ui/core';
import { LabeledValue as AntdLabeledValue } from 'antd/lib/select';
import debounce from 'lodash/debounce';
import { isEqual, uniq } from 'lodash';
import { debounce, isEqual, uniq } from 'lodash';
import Icons from 'src/components/Icons';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import { FAST_DEBOUNCE, SLOW_DEBOUNCE } from 'src/constants';
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/components/TableView/TableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React, { useEffect, useRef } from 'react';
import isEqual from 'lodash/isEqual';
import { isEqual } from 'lodash';
import { styled, t } from '@superset-ui/core';
import { useFilters, usePagination, useSortBy, useTable } from 'react-table';
import { Empty } from 'src/components';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
useComponentDidUpdate,
} from '@superset-ui/core';
import { ParentSize } from '@visx/responsive';
import pick from 'lodash/pick';
import { pick } from 'lodash';
import Tabs from 'src/components/Tabs';
import DashboardGrid from 'src/dashboard/containers/DashboardGrid';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React, { useEffect } from 'react';
import pick from 'lodash/pick';
import { pick } from 'lodash';
import { shallowEqual, useSelector } from 'react-redux';
import { DashboardContextForExplore } from 'src/types/DashboardContextForExplore';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/* eslint-disable no-param-reassign */
import throttle from 'lodash/throttle';
import { throttle } from 'lodash';
import React, {
useEffect,
useState,
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/dashboard/util/charts/useChartIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import { useSelector } from 'react-redux';
import isEqual from 'lodash/isEqual';
import { isEqual } from 'lodash';
import { createSelector } from '@reduxjs/toolkit';
import { RootState } from 'src/dashboard/types';
import { useMemoCompare } from 'src/hooks/useMemoCompare';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from '@superset-ui/core';
import { Global } from '@emotion/react';
import { Column } from 'react-table';
import debounce from 'lodash/debounce';
import { debounce } from 'lodash';
import { Space } from 'src/components';
import { Input } from 'src/components/Input';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import React, { useCallback, useEffect, useState } from 'react';
import throttle from 'lodash/throttle';
import { throttle } from 'lodash';
import {
POPOVER_INITIAL_HEIGHT,
POPOVER_INITIAL_WIDTH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import React from 'react';
import { legacyValidateNumber, legacyValidateInteger } from '@superset-ui/core';
import debounce from 'lodash/debounce';
import { debounce } from 'lodash';
import { FAST_DEBOUNCE } from 'src/constants';
import ControlHeader from 'src/explore/components/ControlHeader';
import { Input } from 'src/components/Input';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import isEqual from 'lodash/isEqual';
import { isEqual } from 'lodash';
import {
AdhocFilter,
ensureIsArray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
tn,
} from '@superset-ui/core';
import { LabeledValue as AntdLabeledValue } from 'antd/lib/select';
import debounce from 'lodash/debounce';
import { debounce } from 'lodash';
import { useImmerReducer } from 'use-immer';
import { Select } from 'src/components';
import { SLOW_DEBOUNCE } from 'src/constants';
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/utils/downloadAsImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { SyntheticEvent } from 'react';
import domToImage from 'dom-to-image-more';
import kebabCase from 'lodash/kebabCase';
import { kebabCase } from 'lodash';
import { t, supersetTheme } from '@superset-ui/core';
import { addWarningToast } from 'src/components/MessageToasts/actions';

Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/utils/downloadAsPdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { SyntheticEvent } from 'react';
import domToPdf from 'dom-to-pdf';
import kebabCase from 'lodash/kebabCase';
import { kebabCase } from 'lodash';
import { logging, t } from '@superset-ui/core';
import { addWarningToast } from 'src/components/MessageToasts/actions';

Expand Down
Loading
Loading