Sheriff ESLint Configuration

website·Indexed 31 days ago

https://www.eslint-config-sheriff.dev

An opinionated, all-in-one ESLint configuration library designed to simplify complex linting setups. It includes a CLI consisting of The Scaffolder for automatic setup and The Doctor for configuration diagnostics. Sheriff provides built-in support for TypeScript, Prettier, and Vitest, with specific guidelines for monorepos and VSCode integration.

Tokens
7.1K
Snippets
27
Records
63
Agent score
59%

What's inside Sheriff

  1. Overview of Sheriff ESLint configuration

    Sheriff is a comprehensive, TypeScript-first ESLint configuration library designed for modern ECMAScript standards. It is built specifically for TypeScript codebases and does not currently support vanilla JavaScript. Sheriff is a pioneer in adopting the ESLint FlatConfig (introduced in ESLint v8.23.0) and follows a "zero overhead" and "plug & play" philosophy, allowing for easy setup while remaining highly customizable.
  2. Overview of Sheriff ESLint Configuration features

    Sheriff is an all-in-one ESLint solution designed to be a seamless replacement or addition to existing linting setups. Key characteristics include:

    • FlatConfig Support: Built to adhere to the new ESLint FlatConfig format, facilitating easier migration to the new configuration system.
    • No Framework Lock-in: It is an extended ESLint configuration, not a framework. Users can extend eslint.config.mjs or disable any specific Sheriff rule without limitations.
    • Formatting Agnostic: Sheriff does not impose strict formatting opinions. It supports the use of Prettier via a recommended 'golden path' but does not require it.
    • Typesafe Configuration: The configuration file can be made typesafe using eslint-config-ts.
    • Sensible Defaults: Includes hand-picked rules to prevent production issues and ensure style consistency, as well as preconfigured ignore patterns that incorporate .gitignore files.
  3. Overview of Sheriff CLI packages

    The Sheriff CLI is divided into two specialized packages:

    1. The Scaffolder: Provided by the @sherifforg/create-config package, used for initial configuration setup.
    2. The Doctor: Provided by the @sherifforg/cli package, used for diagnostics and maintenance.
  4. Overview of Sheriff ESLint configuration

    Sheriff is an ESLint configuration designed to be easy to set up, customize, and use in production. Unlike ESLint wrappers, Sheriff is not a wrapper; it is a sharable configuration that allows users to maintain full access to ESLint's capabilities without being locked into a limited ecosystem. Key advantages include native support for the FlatConfig format and a focus on solid principles rather than maximizing the number of rules.
  5. Understand Sheriff ESLint ruleset design philosophy

    Sheriff provides a predefined set of rules designed for a functional-light programming style. Unlike many other configurations, it does not offer tiered presets like "recommended" or "strict". It is designed to be opinionated but flexible, allowing developers to disable specific rules on a case-by-case basis if they prefer a different style (e.g., OOP) or find the configuration too strict.
  6. Simplify ESLint configuration maintenance with Sheriff

    Managing complex ESLint configurations typically requires deep expertise in JavaScript engines and library interactions, and creates a significant maintenance burden. Sheriff abstracts this complexity, allowing developers to maintain their ESLint configuration simply by updating the Sheriff package to the latest version.
  7. Initialize Sheriff using The Scaffolder

    The Scaffolder is a CLI utility that allows developers to introduce Sheriff into their project using a single terminal command. For a detailed list of available commands, refer to the CLI API reference, specifically the @sherifforg/create-config command.
  8. Quickstart static analysis with Sheriff

    Sheriff provides a battery-packed ESLint configuration for TypeScript projects designed to minimize manual setup and configuration decisions. It is intended to align teams of various skill levels by providing optimal defaults that prevent common mistakes.
    pnpm create @sherifforg/config
  9. Override or add ESLint rules in Sheriff

    Since Sheriff uses the ESLint FlatConfig system, you can override any Sheriff rule or add new ones by passing additional configuration objects to defineConfig after the sheriff() call.
    import { sheriff } from "eslint-config-sheriff";
    import { defineConfig } from "eslint/config";
    
    const sheriffOptions = { /* ... options ... */ };
    
    export default defineConfig(
      sheriff(sheriffOptions),
      {
        rules: {
          "import/first": 0, // Disable a rule
          "some-other-rule": 2, // Enable a rule
        },
      },
    );
  10. Initialize Sheriff using the Scaffolder CLI

    To set up Sheriff in a project, use the Scaffolder tool. The Scaffolder automatically infers project details and determines the optimal configuration. It can be added to a project at any time, and the tool will provide warnings if special precautions are needed during installation.
  11. Benchmark ESLint rule performance

    To identify which rules are slowing down your linting process, you can run ESLint with the TIMING environment variable set to 1. This will output the time taken by each rule.
    # Using npm
    TIMING=1 npx eslint
    
    # Using pnpm
    TIMING=1 pnpm dlx eslint
    
    # Using yarn
    TIMING=1 yarn dlx eslint
    
    # Using bun
    TIMING=1 bun x eslint
  12. Avoid using function overloads in TypeScript

    Function overloads are disallowed in favor of generics and conditional types. Overloads are considered a legacy feature that increases cognitive load, clutters VS Code tooltips, and introduces non-standard JavaScript syntax. Generics are recommended as a superior alternative for solving the same problems while maintaining consistency.