Skip to content

Commit

Permalink
fix: exlcude prettier from expensive rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ASafaeirad committed Oct 29, 2023
1 parent 591a0fa commit 6ea61d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,32 @@ module.exports = init({

It's crucial to balance the benefits of linting rules against their performance impact. Below is a table highlighting the most resource-intensive linting rules encountered in a real-world React project:

| Rule | Time (ms) | Relative |
| --------------------------------------- | --------- | -------- |
| @cspell/spellchecker | 4298.302 | 25.0% |
| prettier/prettier | 3299.631 | 19.2% |
| @typescript-eslint/no-misused-promises | 2473.767 | 14.4% |
| import/no-cycle | 1177.111 | 6.8% |
| import/namespace | 1148.731 | 6.7% |
| Rule | Time (ms) | Relative |
| -------------------------------------- | --------- | -------- |
| @cspell/spellchecker | 4298.302 | 25.0% |
| prettier/prettier | 3299.631 | 19.2% |
| @typescript-eslint/no-misused-promises | 2473.767 | 14.4% |
| import/no-cycle | 1177.111 | 6.8% |
| import/namespace | 1148.731 | 6.7% |

As illustrated, certain rules significantly increase linting time, potentially hindering the developer experience by slowing down the feedback loop. To mitigate this, you may consider disabling these resource-intensive rules in the development environment. However, they can remain active in environments where performance is less critical, such as Continuous Integration (CI) systems or during pre-commit checks (git hooks).

To conditionally disable expensive linting rules, you can modify your configuration as follows:

list of expensiveRules to be effected:

```js
'@cspell/spellchecker'
'@typescript-eslint/no-misused-promises'
'import/no-cycle'
'import/namespace'
```

```js
module.exports = init({
modules: {
disableExpensiveRules: !process.env.CI || !process.env.HUSKY // Or anywhere you want
prettier: false // So you should run the formatter explicitly.
},
});
```
Expand Down
2 changes: 1 addition & 1 deletion init.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function init(opts = {}) {
opts.test && require.resolve('./jest'),
opts.esm && require.resolve('./esm'),
opts.strict && require.resolve('./strict'),
!opts.disableExpensiveRules && opts.prettier && require.resolve('./prettier'),
opts.prettier && require.resolve('./prettier'),
!opts.disableExpensiveRules && opts.cspell && require.resolve('./cspell'),
]
.concat(extraExtends)
Expand Down

0 comments on commit 6ea61d8

Please sign in to comment.