[英]Airbnb Eslint config is too slow on >12 versions
我有 ESLint 的配置
{
"env": {
"browser": true,
"node": true,
"es2020": true
},
"extends": [
"airbnb-typescript/base",
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
"modules": true,
"arrowFunctions": true,
"classes": true
},
"ecmaVersion": 11,
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"react",
"react-hooks",
"@typescript-eslint",
"testing-library",
"jest-dom"
],
"settings": {
"import/resolver": {
"typescript": {}
},
"react": {
"version": "detect"
}
},
"rules": {
"class-methods-use-this": "off",
"no-restricted-syntax": "off",
"no-underscore-dangle": "off",
"no-return-assign": "off",
"linebreak-style": "off",
"no-continue": "off",
"no-plusplus": "off",
"func-names": "off",
"no-param-reassign": ["error", { "props": false }],
"no-empty": ["error", { "allowEmptyCatch": true }],
"object-curly-newline": ["error", {
"ImportDeclaration": { "minProperties": 5 }
}],
"arrow-parens": ["error", "as-needed"],
"quote-props": ["error", "as-needed"],
"max-len": ["error", {"code": 110}],
"indent": ["error", 4, {
"ignoredNodes": ["JSXElement *"]
}],
"prefer-destructuring": ["error", {
"array": false,
"object": true
}],
"no-console": "error",
"jsx-quotes": "error",
"max-lines": "error",
"import/prefer-default-export": "off",
"import/extensions": "off",
"import/no-cycle": "error",
"jsx-a11y/mouse-events-have-key-events": "off",
"jsx-a11y/control-has-associated-label": "off",
"jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/anchor-is-valid": "off",
"react/destructuring-assignment": "off",
"react/jsx-first-prop-new-line": "off",
"react/jsx-props-no-spreading": "off",
"react/jsx-max-props-per-line": "off",
"react/display-name": "off",
"react/prop-types": "off",
"react/jsx-closing-bracket-location": ["error", "after-props"],
"react/function-component-definition": ["error", {
"namedComponents": "arrow-function",
"unnamedComponents": "arrow-function"
}],
"react/jsx-child-element-spacing": "error",
"react/jsx-no-useless-fragment": "error",
"react/jsx-indent-props": ["error", 4],
"react/jsx-indent": ["error", 4],
"react/require-default-props": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unnecessary-type-constraint": "off",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-throw-literal": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-unused-vars": ["error", {
"args": "after-used"
}],
"@typescript-eslint/indent": ["error", 4, {
"ignoredNodes": ["JSXElement *"]
}]
}
}
它確實運作良好。 但僅適用於eslint-config-airbnb-typescript@12
。 如果我將此數據包更新到更高版本,ESLint 會慢 4 倍——檢查單個文件從 15 秒到 60 秒。
那是一個 package.json
"@typescript-eslint/eslint-plugin": "5.33.1",
"@typescript-eslint/parser": "5.33.1",
"eslint": "7.32.0",
"eslint-config-airbnb-typescript": "12.3.1",
"eslint-import-resolver-typescript": "3.5.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest-dom": "4.0.2",
"eslint-plugin-jsx-a11y": "6.4.1",
我不明白這種放緩的原因。 你能告訴我,有什么問題嗎?
出色地。 我在這里發現了一些問題。
import/no-cycle
比其他規則要長得多。 因此,出於調試目的,我將其關閉。 另外,我添加了maxDepth
標志來減少 linting 時間;@typescript-eslint/indent
和indent
不應該一起應用,所以我從我的配置中刪除了indent
;"ignoredNodes": ["JSXElement *"]
,因為我在幾年前添加了這一行。 現在這條線沒有什么好處,所以我刪除了它。airbnb-typescript
需要用airbnb
聲明。 另外,不需要使用eslint:recommended
和plugin:react/recommended
quote-props
, @typescript-eslint/no-unused-vars
等 - 它們已經寫在更新版本中,所以我從我的配置中刪除了這些規則現在 linting 時間非常接近舊版本的時間。
在命令行運行時可以使用TIMING=1
來調試哪個規則慢!
$ TIMING=1 eslint lib
Rule | Time (ms) | Relative
:-----------------------|----------:|--------:
no-multi-spaces | 52.472 | 6.1%
camelcase | 48.684 | 5.7%
no-irregular-whitespace | 43.847 | 5.1%
valid-jsdoc | 40.346 | 4.7%
handle-callback-err | 39.153 | 4.6%
space-infix-ops | 35.444 | 4.1%
no-undefined | 25.693 | 3.0%
no-shadow | 22.759 | 2.7%
no-empty-class | 21.976 | 2.6%
semi | 19.359 | 2.3%
https://eslint.org/docs/latest/developer-guide/working-with-rules#performance-testing
如果它可能對下一個人有幫助,我發現通過刪除我的parserOptions.project
值可以獲得很大的性能提升。 它需要禁用這些規則:
rules: {
"@typescript-eslint/no-implied-eval": "off",
"@typescript-eslint/no-throw-literal": "off",
"@typescript-eslint/return-await": "off",
"@typescript-eslint/dot-notation": "off",
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.