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 list of type-aware rules, which can help track them down.

You can benchmark rule performance yourself by running the following in the 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 really 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

Rules performance optimization strategiesโ€‹

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

Disable some of the heaviest rulesโ€‹

After profiling rules, you can disable those of the slowest rules you can live without.

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 process from 'node:process';
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 globstars/**) can lead to performance degradation.

Pay special attention to: