-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
eslint-plugin-prettier is very slow #304
Comments
That is indeed a long time compared to your other files.
|
I was reading a tweet regarding this today and thought I should give it a try, I was surprised to see the results (this is a React Native, Typescript codebase).
Rule | Time (ms) | Relative
:---------------------------------|----------:|--------:
prettier/prettier | 1333.671 | 91.6%
react/no-string-refs | 46.890 | 3.2%
@typescript-eslint/no-unused-vars | 7.696 | 0.5%
semi | 4.267 | 0.3%
react-native/no-inline-styles | 4.207 | 0.3%
react-hooks/exhaustive-deps | 3.590 | 0.2%
react-hooks/rules-of-hooks | 3.248 | 0.2%
no-obj-calls | 2.784 | 0.2%
no-div-regex | 2.560 | 0.2%
no-undef-init | 2.220 | 0.2%
"@react-native-community/eslint-config": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^3.2.0",
"@typescript-eslint/parser": "^3.2.0",
"eslint": "^7.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react-hooks": "^4.0.4",
"prettier": "^2.0.5",
module.exports = {
bracketSpacing: true,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
semi: false,
};
I'm not accustomed with prettier cli's API so I don't know how to trigger the Timing=1 to compare the results, neither could I capture the output of |
You'll want to redirect stderr in addition to stdout to capture the debugging information: |
Seeing the same thing:
|
Same issue here. It's fast when we run Prettier via the VSCode plugin
Dependencies:
ESLint config:
|
Eslint config: module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
env: {
browser: true,
jest: false,
},
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
ecmaFeatures: {
jsx: true, // Allows for the parsing of JSX
},
},
settings: {
react: {
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
},
},
extends: [
'plugin:react-hooks/recommended',
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslin
],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
'react/prop-types': 0,
'react/display-name': 0,
'react/no-unescaped-entities': 0,
'arrow-parens': ['error', 'as-needed'],
'@typescript-eslint/ban-ts-comment': [0, 'allow-with-description'],
},
ignorePatterns: ['scripts', 'config', 'node_modules'],
} |
@BPScott Can this problem be solved? |
This looks related to the issue opened in prettier-eslint-cli repo |
Same here, prettier takes a lot of time, which results in really bad developer experience
|
Same here
|
Same here
|
same here
|
any updates on this? |
@yekver no, I give up |
Bad to see |
Same problem here. I'm removing this rule from my eslint config and running prettier as a separate step (it is drastically faster) |
Could this be one cause? eslint-plugin-prettier/eslint-plugin-prettier.js Lines 175 to 188 in 885f484
This means it is stuck until reading/parsing the files finished and then it still has to run Correct me if I am wrong, but it doesn't look like eslint plugins can use any async code? |
This should be fixed as of v3.3.0. I've known for a while that not clearing the prettier config cache is the fix for this but wanted to see if there was a way to get the performance speedup without impacting usage in editors - as with this change eslint plugins in editors keep using old cached prettier config instead of spotting when you make changes to prettier config. The solution is easy but not ideal: "When you make a config change you may need to restart your editor for it to notice". I couldn't find fix that avoided that, but the size of the speedup is worth needing that extra step as 99% of the time you're not fiddling with settings. |
@BPScott In my trials running it from the CLI, comparing my old version Further to this, the version of prettier plays a role in execution time: |
starting with
and now with
thx a lot @BPScott ! |
eslint: 8.11.0
|
This may help someone: I was able to reduce the time from 4 seconds to 370ms on my small project by creating a .prettierignore file:
|
Indeed upgrading to the latest version Before:
After:
|
Interesting :D
This is with latest prettier
module.exports = {
// Specifies the ESLint parser
parser: '@typescript-eslint/parser',
extends: [
// Uses the recommended rules from the @typescript-eslint/eslint-plugin
'plugin:@typescript-eslint/recommended',
// Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
'prettier',
'plugin:lit/recommended',
],
parserOptions: {
// Allows for the parsing of modern ECMAScript features
ecmaVersion: 2018,
// Allows for the use of imports
sourceType: 'module',
},
rules: {
'@typescript-eslint/explicit-function-return-type': 0,
'simple-import-sort/imports': 'error',
'sort-imports': 'off',
'import/order': 'off',
'prettier/prettier': [
'error',
{
trailingComma: 'es5',
semi: true,
singleQuote: true,
printWidth: 120,
endOfLine: 'auto',
},
],
indent: ['off', 2],
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/camelcase': 0,
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['off'],
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'lit/no-legacy-template-syntax': 'error',
'lit/no-template-arrow': 'off',
},
plugins: ['simple-import-sort', '@typescript-eslint', 'prettier', 'lit'],
}; |
I had a large js file with 30K line of code in my project's root directory. adding it to the .prettierignore file solved the issue for me. so, I think that the issue is not with the prettier plugin it's related to projects, just look for the large files and prettierignore it. |
Don't forget to ignore Example using the new flat eslint config import eslint from "@eslint/js";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
export default [
{
ignores: ["node_modules", ".yarn"],
},
eslint.configs.recommended,
eslintPluginPrettierRecommended
]; |
@sjymon you're probably linting files you shouldn't be, like |
What version of
eslint
are you using?v7.2.0
What version of
prettier
are you using?v2.0.5
What version of
eslint-plugin-prettier
are you using?v3.1.3
Please paste any applicable config files that you're using (e.g.
.prettierrc
or.eslintrc
files)What source code are you linting?
JavaScript、JSON、LESS
What did you expect to happen?
less time
What actually happened?
It takes a long time
The text was updated successfully, but these errors were encountered: