LogoSheriff
Documentation/CLI usage

The Doctor

Self-lint your Sheriff configuration

The Doctor is a diagnostic tool that monitor your Sheriff configuration and ensure it stays up-to-date with your project dependencies.

Example usecase

Picture this: you kickstart your project and opt for jest as your unit testing solution of choice. You setup Sheriff with the Scaffolder and it automatically enables the jest support for your project. All great.

But then, one day, you decide to switch to vitest. You update your project dependencies and forget to update your Sheriff configuration.

Here is where the Doctor comes into picture: it will catch this mismatch and warn you about it, so you can readily turn off the jest support in your Sheriff configuration and turn on the vitest support.

All is good again.

How to run it

To get started, install it in your project:

npm i -D @sherifforg/cli
pnpm add -D @sherifforg/cli
yarn add --dev @sherifforg/cli
bun add --dev @sherifforg/cli

Add the command to your package.json scripts:

package.json
{
  "scripts": {
    "sheriff": "sheriff"
  }
}

And then run it:

pnpm sheriff

It is advised to integrate the Doctor in your CI pipelines, but you can also integrate it into pre-commit hooks if that's your preference.

How it works

The sheriff command will scan your project dependencies and your Sheriff configuration object. If Sheriff finds some dependencies that don't have the corresponding Sheriff options enabled, it will throw an error.

Example

package.json
{
  "name": "my-project",
  "dependencies": {
    "react": "^18.3.1",
  }
}
eslint.config.mjs
import { sheriff, tseslint } from 'eslint-config-sheriff';

const sheriffOptions = {
  react: false, // ❌ this will throw an error
};

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

const : SheriffSettings = {
  : false, // ❌ this will throw an error
};

export default .(());
eslint.config.mjs
import { sheriff, tseslint } from 'eslint-config-sheriff';

const sheriffOptions = {
  react: true, // ✅ this will pass
};

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

const : SheriffSettings = {
  : true, // ✅ this will pass
};

export default .(());

Warning

The Doctor will scan the config file trying to find a variable named exactly sheriffOptions. If your configuration object variable is called in any other way, nothing will work. Make sure the variable is named sheriffOptions.

Options

The Doctor is very flexible and offers a variety of options to customize it's behavior. Check out the API reference for detailed info on the available options.

You can:

  • skip the check for a specific dependency. This is useful in scenarios where the mismatch is intended, meaning that you don't want Sheriff linting support for a specific dependency even if Sheriff support is available
  • let the process finish without throwing erros even if problems with the dependencies are found. In this case the Doctor will just signal problems as warnings

Last updated on