Skip to main content

🧠 Configuration

Base options

The eslint-config-sheriff package exports a sheriff function.
You can configure Sheriff as desired by passing an object to the optional parameter to the sheriff function.
Every config option can be turned on and off (by passing them booleans). As they are all opt-in, they are all disabled by default. If you bootstrapped the config with @sherifforg/cli some of these values will be inferred automatically from your project.

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

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

export default defineFlatConfig([...sheriff(sheriffOptions)]);

Remodeling

If you want, you can override any Sheriff rule in the eslint.config.js file.

For example, say you want to disable import/first:

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,
} satisfies SheriffSettings;

export default defineFlatConfig([
...sheriff(sheriffOptions),
{
rules: {
"import/first": 0, // `import/first` is now disabled everywhere.
},
},
]);

Likewise, say you want to enable a new rule:

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,
} satisfies SheriffSettings;

export default defineFlatConfig([
...sheriff(sheriffOptions),
{
rules: {
"import/first": 2, // `import/first` is now enabled everywhere.
},
},
]);

This is just the standard behavior for ESLint’s “flat” configuration system, illustrated here for your convenience. Sheriff does not alter this in any way.

For more in-depth information, refer to the official docs.

Advanced options

The upcoming configuration options are meant to be situational, tailored to serve only a niche group of users and designed to address specific use cases. Only use these if you end up needing them.

files

This option is primarily meant to be used while introducing Sheriff to an existing project.

Learn more in the ♻ Migration guide.

ignores

By default, Sheriff will ignore certain file paths, but you can choose to opt out of this behavior.

ignores: {
recommended: boolean;
inheritedFromGitignore: boolean;
}

ignores.recommended

With this option, Sheriff will ignore a list of commonly ignored folders:

  • **/node_modules/**
  • **/dist/**
  • **/build/**
  • **/artifacts/**
  • **/coverage/**
  • eslint.config.{js,mjs,cjs}

Example:

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,
ignores: {
recommended: true, // true by default. False to disable.
},
} satisfies SheriffSettings;

export default defineFlatConfig([...sheriff(sheriffOptions)]);

ignores.inheritedFromGitignore

With this option, Sheriff will ignore the same file paths specified in your .gitignore file.

Example:

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,
ignores: {
inheritedFromGitignore: true, // true by default. False to disable.
},
} satisfies SheriffSettings;

export default defineFlatConfig([...sheriff(sheriffOptions)]);

pathsOverrides

As outlined in the criteria page, Sheriff comes with sensible defaults. However, as your project grows, your team may come across the need to override some of these defaults. This option lets you do just that.

pathsOverrides: {
tsconfigLocation: string | string[];
tests: string[];
}

pathsOverrides.tsconfigLocation

By default, Sheriff will use the project: true option to find your project’s tsconfig.json.

However, if you happen to have multiple tsconfig.json files in your project (like tsconfig.json, tsconfig.eslint.json, tsconfig.node.json, etc…), you can use this parameter to specify the config Sheriff will pick up.

You can pass it a path as a string (or a list of file paths as an array of strings, see also: One tsconfig.json per package (and an optional one in the root) § Monorepo Configuration | typescript-eslint).

Example:

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,
pathsOverrides: {
tsconfigLocation: "./tsconfig.eslint.json",
},
} satisfies SheriffSettings;

export default defineFlatConfig([...sheriff(sheriffOptions)]);

pathsOverrides.tests

By default, Sheriff will only apply Jest or Vitest rules on specific files.

[
"**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts}",
"**/tests/**/*.{js,mjs,cjs,ts,mts,cts}",
"**/__tests__/**/*.{js,mjs,cjs,ts,mts,cts}"
]

This setting overrides the default.

It accepts an array of file paths, and supports minimatch syntax.

Example:

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,
pathsOverrides: {
tests: [
"**/*.mySpecialName.{js,mjs,cjs,ts,mts,cts}",
"**/mySpecialFolder/**/*.{js,mjs,cjs,ts,mts,cts}",
"**/__mySpecialFolder__/**/*.{js,mjs,cjs,ts,mts,cts}",
],
},
} satisfies SheriffSettings;

export default defineFlatConfig([...sheriff(sheriffOptions)]);

pathsOverrides.playwrightTests

By default, Sheriff will only apply Playwright rules on specific files.

"js,mjs,cjs,ts,mts,cts"

This setting overrides the default.

It accepts an array of file paths, and supports minimatch syntax.

Example:

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,
playwrightTests: {
tests: [
"**/*.mySpecialName.{js,mjs,cjs,ts,mts,cts}",
"**/mySpecialFolder/**/*.{js,mjs,cjs,ts,mts,cts}",
"**/__mySpecialFolder__/**/*.{js,mjs,cjs,ts,mts,cts}",
],
},
} satisfies SheriffSettings;

export default defineFlatConfig([...sheriff(sheriffOptions)]);

Customizing the no-restricted-syntax options

One of ESLint’s most powerful rules is no-restricted-syntax. It accepts an array of objects, each object of which represents a specific syntax feature that you want to forbid. Sheriff already comes with a preconfigured no-restricted-syntax entry. However, you can customize it in a few different ways.

Override

Override the rule in full.
You can add no-restricted-syntax to a configuration object of your own to fully override the Sheriff one. You can do this as you normally would, appending the rule to the configuration array after Sheriff.

Example:

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,
} satisfies SheriffSettings;

export default defineFlatConfig([
...sheriff(sheriffOptions),
{
rules: {
"no-restricted-syntax": [
2,
// Your custom rules here…
],
},
}
]);

Extend

Conveniently, Sheriff exports its own no-restricted-syntax entry as the baseNoRestrictedSyntaxRules array. To extend Sheriff’s entry of no-restricted-syntax, you can use the JavaScript spread syntax.

Example:

eslint.config.js
import sheriff, { baseNoRestrictedSyntaxRules } 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
} satisfies SheriffSettings;

export default defineFlatConfig([
...sheriff(sheriffOptions),
{
rules: {
"no-restricted-syntax": [
2,
...baseNoRestrictedSyntaxRules,
// Your custom rules here…
],
},
}
]);

Shrink

Conveniently, Sheriff exports its own no-restricted-syntax entry as the baseNoRestrictedSyntaxRules array.
To shrink Sheriff’s entry of no-restricted-syntax, you can use the Array#toSpliced() method to remove entries you dislike.
Every entry prints the index of itself at the end of the message property, so that you can identify the ones you want to remove.

Example:

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
} satisfies SheriffSettings;

export default defineFlatConfig([
...sheriff(sheriffOptions),
{
rules: {
"no-restricted-syntax": [
2,
...baseNoRestrictedSyntaxRules.toSpliced(2, 1) // This results in `baseNoRestrictedSyntaxRules` without the third element.
],
},
};
]);