Skip to main content

⚡ Performance tips

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

Rules performance benchmarking

The slowest rules in Sheriff are the ones that require type information to work.
typescript-eslint maintains a list of type-aware rules, which can help track them down.

You can benchmark rule performance by running the following in a terminal:

TIMING=1 npx eslint

Learn more on the official ESLint docs page on profiling rule performance.

warning

If typed linting is enabled, the first typescript-eslint rule to run will look a lot slower, when, in reality, all typescript-eslint rules are at minimum as slow as a tsc run, but the output is cached. For more information, see Slow ESLint Rules § Performance | typescript-eslint.

Rule performance optimization strategies

You can leverage a few different techniques to improve slow linting time.
You can choose one technique to employ or mix-and-match them.

Disable some of the heaviest rules

After profiling rules, you can assess which of the slowest rules you can live without and 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 of how to achieve this:

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

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

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

There is a tradeoff here, as this approach is a DX degradation that can lead to developer frustration, because code that is perfectly valid local environment could still fail in CI.

You may find typescript-eslint’s disableTypeChecked config useful in these scenarios.

Review glob patterns

ESLint, TypeScript and Sheriff use minimatch syntax to handle glob patterns.
Wide glob patterns (in particular, the usage of globstars1) can lead to performance degradations.

Pay special attention to:

Footnotes

  1. A globstar is a ** pattern.