Skip to content

Commit

Permalink
feat: add disable expensive rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ASafaeirad committed Oct 29, 2023
1 parent bdb7f31 commit 7bac8a1
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 19 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ interface Modules {
storybook?: boolean; // controls storybook plugin
tailwind?: boolean; // controls tailwindcss plugin
next?: boolean; // controls next plugin
prettier?: boolean; // controls prettier plugin
disableExpensiveRules?: boolean; // controls expensive rules
}
```

Expand All @@ -88,6 +90,32 @@ module.exports = init({
});
```

## Speed Optimization!

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% |

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:

```js
module.exports = init({
modules: {
disableExpensiveRules: !process.env.CI || !process.env.HUSKY // Or anywhere you want
},
});
```

This approach ensures a smoother development experience while still enforcing rigorous code quality checks in environments where performance is less of a concern.

## React/NextJS configuration

React/NextJS configuration should automatically work with Auto Module Detection, but if you need to have more control over the rules you can configure it through `modules.react`.
Expand Down
13 changes: 13 additions & 0 deletions expensive-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @type { import('eslint').Linter.Config } */
module.exports = {
rules: {
'@typescript-eslint/no-misused-promises': 'off',
'prettier/prettier': 'off',
'import/no-cycle': 'off',
'import/namespace': 'off',
'import/no-deprecated': 'off',
'import/named': 'off',
'import/export': 'off',
'@typescript-eslint/no-floating-promises': 'off',
},
};
2 changes: 2 additions & 0 deletions init.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface Options extends Config {
test?: boolean;
cypress?: boolean;
storybook?: boolean;
prettier?: boolean;
disableExpensiveRules?: boolean;
};
}

Expand Down
3 changes: 2 additions & 1 deletion init.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function init(opts = {}) {
opts.test && require.resolve('./jest'),
opts.esm && require.resolve('./esm'),
opts.strict && require.resolve('./strict'),
require.resolve('./prettier'),
opts.prettier && require.resolve('./prettier'),
opts.disableExpensiveRules && require.resolve('./expensive-rules'),
]
.concat(extraExtends)
.filter(Boolean),
Expand Down
22 changes: 5 additions & 17 deletions naming-convention.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ module.exports = [
{
selector: 'default',
format: ['camelCase'],
filter: {
regex: '^_+$',
match: false,
},
filter: { regex: '^_+$', match: false },
},
{ selector: 'import', format: null },
{
selector: 'function',
format: ['camelCase', 'PascalCase'],
Expand All @@ -15,24 +13,15 @@ module.exports = [
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
filter: {
regex: '^_+$',
match: false,
},
filter: { regex: '^_+$', match: false },
},
{
selector: 'parameter',
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow',
filter: {
regex: '^_+$',
match: false,
},
},
{
selector: 'memberLike',
format: null,
filter: { regex: '^_+$', match: false },
},
{ selector: 'memberLike', format: null },
{
selector: 'memberLike',
modifiers: ['static'],
Expand All @@ -53,7 +42,6 @@ module.exports = [
selector: 'enumMember',
format: ['PascalCase'],
},
// disallow I prefix for interfaces
{
selector: 'interface',
format: ['PascalCase'],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"node.js",
"packages.js",
"prettier.js",
"expensive-rules.js",
"promise.js",
"react.js",
"registerOpts.js",
Expand Down
2 changes: 2 additions & 0 deletions registerOpts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const defaultOptions = {
typescript: hasDep('typescript'),
tailwind: hasDep('tailwindcss'),
cspell: hasDep('cspell'),
prettier: hasDep('prettier'),
disableExpensiveRules: false,
import: true,
node: true,
};
Expand Down
2 changes: 1 addition & 1 deletion typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/generic-type-naming': 'off',
'@typescript-eslint/init-declarations': ['off'],
'@typescript-eslint/init-declarations': 'off',
'@typescript-eslint/lines-between-class-members': ['warn', 'always', { exceptAfterSingleLine: true }],
'@typescript-eslint/member-naming': 'off',
'@typescript-eslint/member-ordering': 'off',
Expand Down

0 comments on commit 7bac8a1

Please sign in to comment.