Skip to content

Commit

Permalink
docs(docs): added docs section for performance considerations
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaPontrandolfo committed Nov 12, 2023
1 parent 9ee23b0 commit 1fead5c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/docs-website/docs/core-philosophy/_category_.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"label": "💭 Core Philosophy",
"label": "💭 Core philosophy",
"position": 3,
"link": {
"type": "generated-index",
Expand Down
2 changes: 1 addition & 1 deletion apps/docs-website/docs/faq.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 16
sidebar_position: 17
---

# 📚 FAQ
Expand Down
2 changes: 1 addition & 1 deletion apps/docs-website/docs/migration-guide.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 14
sidebar_position: 15
---

# ♻ Migration guide
Expand Down
90 changes: 90 additions & 0 deletions apps/docs-website/docs/performance-considerations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
sidebar_position: 14
---

# ⚡ Performance tips

Depending on the device you are operating on, in-editor performance can be a concern with Sheriff. <br />
`@typescript-eslint` can be particularly taxing on the system, so, some performance considerations are in order.

## Rules performance benchmarking

The currently known slowest rules in Sheriff are:

- `@typescript-eslint/no-misused-promises`
- `@typescript-eslint/no-unsafe-argument`
- `@typescript-eslint/naming-convention`
- `@typescript-eslint/no-floating-promises`
- `import/no-unresolved`
- `import/no-named-as-default`

You can benchmark rules performance by yourself by running the following command in the terminal:

```bash npm2yarn
TIMING=1 npm run eslint .
```

Learn more in the [ESLint official docs section](https://eslint.org/docs/latest/extend/custom-rules#profile-rule-performance).

## Rules performance optimization strategies

There are a few techniques you can leverage to improve linting time. <br />
You can choose which technique to employ or mix-and-match them.

### Disable some of the heaviest rules

As simple as it sounds, you could assess which of the slowest rules you can live without and simply disable them.

### Enable some of the heaviest rules only on CI

This approach has a little more overhead, but you could try to run the heaviest rules only on CI.

Here is an example on how you can achieve it:

```js title="eslint.config.js"
import sheriff from "eslint-config-sheriff";
import { defineFlatConfig } from "eslint-define-config";

const sheriffOptions = {
react: false,
next: false,
lodash: false,
playwright: false,
jest: false,
vitest: false,
};

export default defineFlatConfig([
...sheriff(sheriffOptions),
{
rules: {
// highlight-next-line
"@typescript-eslint/no-misused-promises": process.env.CI ? 2 : 0,
},
},
]);
```

This is a tradeoff, as this approach is a DX degradation and could lead to some developer frustration, because perfectly valid code in local environment could instead fail in CI.

### Adopt ESLint cache

ESLint features an internal cache where you can store your previous runs.

This technique has pretty much no downsides and you should employ it in any case, regardless of any other factor.

Read the official docs on ESLint caching here: [command-line-interface#caching](https://eslint.org/docs/latest/use/command-line-interface#caching). <br />
Instead, if your project lives in a monorepo, you can follow [this guide](https://www.shew.dev/monorepos/guardrails/eslint).

### Revise glob patterns

ESLint, Typescript and Sheriff use minimatch syntax to handle glob patterns. <br />
Wide glob patterns can lead to performance degradation.

Pay special attention to:

- [ESLint files and ignore patterns](https://eslint.org/docs/latest/use/configure/configuration-files-new#specifying-files-and-ignores)
- [Typescript include and exclude patterns](https://typescript-eslint.io/linting/troubleshooting/performance-troubleshooting/#wide-includes-in-your-tsconfig)
- [Sheriff files options](./configuration#files)
- [Sheriff pathsOveriddes options](./configuration#pathsoveriddes)
- [wide-globs-in-parseroptionsproject](https://typescript-eslint.io/linting/typed-linting/monorepos/#wide-globs-in-parseroptionsproject)
2 changes: 1 addition & 1 deletion apps/docs-website/docs/prior-art.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 15
sidebar_position: 16
---

# 🧐 Prior art
Expand Down
6 changes: 5 additions & 1 deletion apps/docs-website/docs/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 17
sidebar_position: 18
---

# 🩹 Troubleshooting
Expand All @@ -10,3 +10,7 @@ Depending on the context and under specific conditions, `create-sheriff-config`
In this case you can simply install them yourself. The `create-sheriff-config` process should spit out the correct command prompt for you to do so. If that doesn't happen, refer to the [manual setup instructions](./setup/manual-setup.md).

Alternatively, consider switching package manager to [pnpm](https://pnpm.io/).

## My editor feels slow

Make sure to read the appropriate docs [here](./performance-considerations.md).

0 comments on commit 1fead5c

Please sign in to comment.