LogoSheriff
Documentation

Migration Guide

How to introduce Sheriff in large codebases

Step-by-step instructions

If you are setting up Sheriff in an already established codebase, follow these steps:

Start by running the Scaffolder and follow the advices that it prints in the console

Make sure that the only ESLint config file present in any workspace's package is the eslint.config.mjs

If you want to keep your existing custom rules on-top of Sheriff, move them to the eslint.config.mjs, after the sheriff function, so they will override it. Refer to the configuration instructions

Make sure to uninstall all the packages that Sheriff already incorporates out-of-the-box. Here is the list

Progressive adoption story

In massive codebases it can be troublesome to adapt to all these rules all at once. It is preferable to progressively fix the errors at your own pace, possibly with atomic commits and focused PRs.

You can achieve this by leveraging a few techniques:

  • open the eslint.config.mjs file and add a key files in the sheriffOptions object. The value accepts an array of filepaths, dictated by minimatch syntax. Only the matching files found in this array will be linted.

    See example below:

eslint.config.mjs
import { sheriff, tseslint } from "eslint-config-sheriff";

const sheriffOptions = {
  files: ["src/**/*"], // Only the files in the src directory will be linted.
  react: false,
  next: false,
  astro: false,
  lodash: false,
  remeda: false,
  playwright: false,
  storybook: true,
  jest: false,
  vitest: false,
};

export default tseslint.config(sheriff(sheriffOptions));
eslint.config.ts
import { , type SheriffSettings,   } from "eslint-config-sheriff";

const : SheriffSettings = {
  : ["src/**/*"], // Only the files in the src directory will be linted.
  : false,
  : false,
  : false,
  : false,
  : false,
  : false,
  : true,
  : false,
  : false,
};

export default .(());

Tip

By default, the Scaffolder will not add the files in the object and every js/ts file will be linted. Use this only if you want to specifically lint just a subsection of the codebase.

Last updated on