π€ Usage in CI
Introβ
The Sheriff CLI is composed of 2 packages:
@sherifforg/create-config
generates the boilerplate to setup Sheriff in your project@sherifforg/cli
lints the Sheriff configuration
The @sherifforg/cli
is invoked via the sheriff
command.
It is advised to integrate @sherifforg/cli
in your CI pipelines to ensure that the Sheriff configuration is always correct and up-to-date, but you can also integrate it into pre-commit hooks if thatβs your preference.
Usageβ
To get started, install it in your project:
- npm
- Yarn
- pnpm
- bun
npm i -D @sherifforg/cli
yarn add --dev @sherifforg/cli
pnpm add -D @sherifforg/cli
bun add --dev @sherifforg/cli
And then run it:
- npm
- Yarn
- pnpm
- bun
npx sheriff
yarn dlx sheriff
pnpm dlx sheriff
bun x sheriff
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 option enabled, it will throw an error.
Example:
{
"name": "my-project",
"dependencies": {
"react": "^18.3.1",
}
}
import { sheriff } from 'eslint-config-sheriff';
import { defineFlatConfig } from 'eslint-define-config';
const sheriffOptions = {
react: false, // β this will throw an error
};
export default defineFlatConfig([...sheriff(sheriffOptions)]);
import { sheriff } from 'eslint-config-sheriff';
import { defineFlatConfig } from 'eslint-define-config';
const sheriffOptions = {
react: false, // β
this will pass
};
export default defineFlatConfig([...sheriff(sheriffOptions)]);
Sheriff will scan the config file trying to find a variable named exactly sheriffOptions
. If your configuration object variable is called anything else, the CLI will fail to flag any issues. Ensure the variable is named sheriffOptions
.
Optionsβ
@sherifforg/cli
is very flexible and offers a variety of options to customize itβs behavior. Look at the API reference for the available options.
You can:
- skip the check for a specific dependency. This is useful in scenarios where a mismatch is intended, i.e. you don't want Sheriff linting support for a specific dependency, even if Sheriff support is available
- let the process finish without throwing errors even if problems with the dependencies are found. In this case, the CLI will convert all problems to warnings