From 45d2745b6798b7900f7c90b0da59f62157d7c807 Mon Sep 17 00:00:00 2001 From: q1anx1 <55543743+qianxi0410@users.noreply.github.com> Date: Sun, 7 Aug 2022 11:51:53 +0800 Subject: [PATCH] chore(style): add eslint rules: no-unused-imports and no-unused-vars (#976) * feat(web): no-unused-imports and no-unused-vars * chore: fix json style --- web/.eslintrc | 45 +++++++++++++++++++++++++++++------------ web/package.json | 7 ++++--- web/src/UserEditPage.js | 1 - web/yarn.lock | 12 +++++++++++ 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/web/.eslintrc b/web/.eslintrc index 25d8a480..e4a43f0c 100644 --- a/web/.eslintrc +++ b/web/.eslintrc @@ -17,6 +17,7 @@ "version": "detect" } }, + "plugins": ["unused-imports"], "extends": ["eslint:recommended", "plugin:react/recommended"], "rules": { // "eqeqeq": "error", @@ -45,30 +46,48 @@ "curly": ["error", "all"], "brace-style": ["error", "1tbs", { "allowSingleLine": true }], "no-mixed-spaces-and-tabs": "error", - "sort-imports": ["error", { - "ignoreDeclarationSort": true - }], - "no-multiple-empty-lines": ["error", { "max": 1, "maxBOF": 0, "maxEOF": 0 }], + "sort-imports": [ + "error", + { + "ignoreDeclarationSort": true + } + ], + "no-multiple-empty-lines": [ + "error", + { "max": 1, "maxBOF": 0, "maxEOF": 0 } + ], "space-unary-ops": ["error", { "words": true, "nonwords": false }], "space-infix-ops": "error", "key-spacing": ["error", { "beforeColon": false, "afterColon": true }], "comma-style": ["error", "last"], - "comma-dangle": ["error", { - "arrays": "always-multiline", - "objects": "always-multiline", - "imports": "never", - "exports": "never", - "functions": "never" - }], + "comma-dangle": [ + "error", + { + "arrays": "always-multiline", + "objects": "always-multiline", + "imports": "never", + "exports": "never", + "functions": "never" + } + ], "no-multi-spaces": ["error", { "ignoreEOLComments": true }], - + "unused-imports/no-unused-imports": "error", + "unused-imports/no-unused-vars": [ + "error", + { + "vars": "all", + "varsIgnorePattern": "^_", + "args": "none", + "argsIgnorePattern": "^_" + } + ], "react/prop-types": "off", "react/display-name": "off", "react/react-in-jsx-scope": "off", // don't use strict mod now, otherwise there are a lot of errors in the codebase - "no-unused-vars": "warn", + "no-unused-vars": "off", "react/no-deprecated": "warn", "no-case-declarations": "warn", "react/jsx-key": "warn" diff --git a/web/package.json b/web/package.json index 4dfc4983..aa33e6a5 100644 --- a/web/package.json +++ b/web/package.json @@ -12,13 +12,16 @@ "antd": "^4.15.5", "codemirror": "^5.61.1", "copy-to-clipboard": "^3.3.1", + "core-js": "^3.21.1", "craco-less": "^1.17.1", + "eslint-plugin-unused-imports": "^2.0.0", "file-saver": "^2.0.5", "i18n-iso-countries": "^7.0.0", "i18next": "^19.8.9", "moment": "^2.29.1", "qs": "^6.10.2", "react": "^17.0.2", + "react-app-polyfill": "^3.0.0", "react-codemirror2": "^7.2.1", "react-cropper": "^2.1.7", "react-device-detect": "^1.14.0", @@ -29,9 +32,7 @@ "react-i18next": "^11.8.7", "react-router-dom": "^5.2.0", "react-scripts": "4.0.3", - "react-social-login-buttons": "^3.4.0", - "react-app-polyfill": "^3.0.0", - "core-js": "^3.21.1" + "react-social-login-buttons": "^3.4.0" }, "scripts": { "start": "cross-env PORT=7001 craco start", diff --git a/web/src/UserEditPage.js b/web/src/UserEditPage.js index b5fc2553..b406239d 100644 --- a/web/src/UserEditPage.js +++ b/web/src/UserEditPage.js @@ -15,7 +15,6 @@ import React from "react"; import {Button, Card, Col, Input, Result, Row, Select, Spin, Switch} from "antd"; import * as UserBackend from "./backend/UserBackend"; -import * as UserWebauthnBackend from "./backend/UserWebauthnBackend"; import * as OrganizationBackend from "./backend/OrganizationBackend"; import * as Setting from "./Setting"; import {LinkOutlined} from "@ant-design/icons"; diff --git a/web/yarn.lock b/web/yarn.lock index 941bc88d..fa784c81 100644 --- a/web/yarn.lock +++ b/web/yarn.lock @@ -4907,6 +4907,18 @@ eslint-plugin-testing-library@^3.9.2: dependencies: "@typescript-eslint/experimental-utils" "^3.10.1" +eslint-plugin-unused-imports@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-2.0.0.tgz#d8db8c4d0cfa0637a8b51ce3fd7d1b6bc3f08520" + integrity sha512-3APeS/tQlTrFa167ThtP0Zm0vctjr4M44HMpeg1P4bK6wItarumq0Ma82xorMKdFsWpphQBlRPzw/pxiVELX1A== + dependencies: + eslint-rule-composer "^0.3.0" + +eslint-rule-composer@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz#79320c927b0c5c0d3d3d2b76c8b4a488f25bbaf9" + integrity sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg== + eslint-scope@^4.0.3: version "4.0.3" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.3.tgz#ca03833310f6889a3264781aa82e63eb9cfe7848"