From 923aaba047ee8afd9edc362208d49c26ae27aaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <7971419+crazyair@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:10:56 +0800 Subject: [PATCH] chore: add lodash eslint (#45627) --- .eslintrc.js | 12 +++++++++++- components/config-provider/__tests__/theme.test.tsx | 7 ++++--- components/form/demo/custom-feedback-icons.tsx | 5 ++--- components/upload/__tests__/upload.test.tsx | 9 +++++---- package.json | 1 + scripts/generate-authors.ts | 8 +++++--- tests/shared/demoTest.tsx | 7 ++++--- 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 12e49328d2..ca15e66249 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -25,7 +25,16 @@ module.exports = { }, }, parser: '@typescript-eslint/parser', - plugins: ['react', '@babel', 'jest', '@typescript-eslint', 'react-hooks', 'unicorn', 'markdown'], + plugins: [ + 'react', + '@babel', + 'jest', + '@typescript-eslint', + 'react-hooks', + 'unicorn', + 'markdown', + 'lodash', + ], // https://github.com/typescript-eslint/typescript-eslint/issues/46#issuecomment-470486034 overrides: [ { @@ -156,6 +165,7 @@ module.exports = { 'react/no-unused-class-component-methods': 0, 'import/extensions': 0, 'import/no-cycle': 2, + 'lodash/import-scope': 2, 'import/no-extraneous-dependencies': [ 'error', { diff --git a/components/config-provider/__tests__/theme.test.tsx b/components/config-provider/__tests__/theme.test.tsx index d3c14df61c..dc691224be 100644 --- a/components/config-provider/__tests__/theme.test.tsx +++ b/components/config-provider/__tests__/theme.test.tsx @@ -1,10 +1,11 @@ -import { kebabCase } from 'lodash'; -import canUseDom from 'rc-util/lib/Dom/canUseDom'; import React from 'react'; +import kebabCase from 'lodash/kebabCase'; +import canUseDom from 'rc-util/lib/Dom/canUseDom'; + import ConfigProvider from '..'; import { InputNumber } from '../..'; -import { render } from '../../../tests/utils'; import { resetWarned } from '../../_util/warning'; +import { render } from '../../../tests/utils'; import theme from '../../theme'; import { useToken } from '../../theme/internal'; diff --git a/components/form/demo/custom-feedback-icons.tsx b/components/form/demo/custom-feedback-icons.tsx index 7af3c276a3..4719749dae 100644 --- a/components/form/demo/custom-feedback-icons.tsx +++ b/components/form/demo/custom-feedback-icons.tsx @@ -1,9 +1,8 @@ import React from 'react'; -import { uniqueId } from 'lodash'; - -import { createStyles, css } from 'antd-style'; import { AlertFilled, CloseSquareFilled } from '@ant-design/icons'; import { Button, Form, Input, Tooltip } from 'antd'; +import { createStyles, css } from 'antd-style'; +import uniqueId from 'lodash/uniqueId'; const useStyle = createStyles(() => ({ 'custom-feedback-icons': css` diff --git a/components/upload/__tests__/upload.test.tsx b/components/upload/__tests__/upload.test.tsx index 891c899c11..6e1d790dd5 100644 --- a/components/upload/__tests__/upload.test.tsx +++ b/components/upload/__tests__/upload.test.tsx @@ -1,13 +1,14 @@ -import { produce } from 'immer'; -import { cloneDeep } from 'lodash'; -import type { UploadRequestOption } from 'rc-upload/lib/interface'; import React, { useEffect, useRef } from 'react'; +import { produce } from 'immer'; +import cloneDeep from 'lodash/cloneDeep'; +import type { UploadRequestOption } from 'rc-upload/lib/interface'; + import type { RcFile, UploadFile, UploadProps } from '..'; import Upload from '..'; +import { resetWarned } from '../../_util/warning'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import { act, fireEvent, render, waitFakeTimer } from '../../../tests/utils'; -import { resetWarned } from '../../_util/warning'; import Form from '../../form'; import { getFileItem, isImageUrl, removeFileItem } from '../utils'; import { setup, teardown } from './mock'; diff --git a/package.json b/package.json index cffb89ad0a..a9392971f2 100644 --- a/package.json +++ b/package.json @@ -232,6 +232,7 @@ "eslint-plugin-import": "^2.28.0", "eslint-plugin-jest": "^27.0.1", "eslint-plugin-jsx-a11y": "^6.2.1", + "eslint-plugin-lodash": "^7.4.0", "eslint-plugin-markdown": "^3.0.0", "eslint-plugin-react": "^7.31.8", "eslint-plugin-react-hooks": "^4.1.2", diff --git a/scripts/generate-authors.ts b/scripts/generate-authors.ts index 0195abad01..648d40d320 100644 --- a/scripts/generate-authors.ts +++ b/scripts/generate-authors.ts @@ -1,6 +1,8 @@ import fs from 'fs'; import path from 'path'; -import _ from 'lodash'; +import remove from 'lodash/remove'; +import sortBy from 'lodash/sortBy'; +import unionBy from 'lodash/unionBy'; import simpleGit from 'simple-git'; const cwd = process.cwd(); @@ -18,7 +20,7 @@ const excludes = [ async function execute() { let { all } = await git.log(); - all = _.remove(all, ({ author_email: email }) => { + all = remove(all, ({ author_email: email }) => { for (let i = 0; i < excludes.length; i++) { const item = excludes[i]; if (email.includes(item)) { @@ -28,7 +30,7 @@ async function execute() { return true; }); - all = _.sortBy(_.unionBy(all, 'author_email'), 'author_name'); + all = sortBy(unionBy(all, 'author_email'), 'author_name'); fs.writeFileSync( path.join(cwd, 'contributors.json'), diff --git a/tests/shared/demoTest.tsx b/tests/shared/demoTest.tsx index 620bed701f..538a4a3c7e 100644 --- a/tests/shared/demoTest.tsx +++ b/tests/shared/demoTest.tsx @@ -1,15 +1,16 @@ /* eslint-disable react/jsx-no-constructed-context-values */ import path from 'path'; +import * as React from 'react'; import { createCache, StyleProvider } from '@ant-design/cssinjs'; import { globSync } from 'glob'; -import * as React from 'react'; +import kebabCase from 'lodash/kebabCase'; import { renderToString } from 'react-dom/server'; -import { kebabCase } from 'lodash'; + +import { resetWarned } from '../../components/_util/warning'; import { render } from '../utils'; import { TriggerMockContext } from './demoTestContext'; import { excludeWarning, isSafeWarning } from './excludeWarning'; import rootPropsTest from './rootPropsTest'; -import { resetWarned } from '../../components/_util/warning'; export { rootPropsTest };