Skip to content

Getting Started

Use WithESLint to make managing ESLint configurations for your project easier. This guide will assist you in getting started with your project.

Installation

Terminal window
pnpm add -D eslint witheslint

Configuration

  • Directory.vscode
    • settings.json
  • eslint.config.mjs
  • lefthook.yaml
  • package.json
  1. Define ESLint configurations:

    eslint.config.mjs
    import { defineConfig } from 'witheslint'
    export default defineConfig()

    see customization for more details.

  2. Provide convenient ESLint command line operations:

    package.json
    {
    "scripts": {
    "lint": "eslint",
    "lint:fix": "eslint --fix"
    }
    }
  3. Format and lint the staged files before committing or pushing:

    Terminal window
    pnpm add -D lefthook
    lefthook.yaml
    pre-commit:
    commands:
    eslint:
    glob: '*.{js,ts}'
    run: pnpm eslint --fix {staged_files}
    stage_fixed: true

    Once configured, run lefthook install to set up the hooks.

  4. Needs IDE support? Let’s configure your editor:

    VS Code
    1. Install VS Code extension:

    2. Add the following settings to your project setting:

      .vscode/settings.json
      {
      // Disable the default formatter, use eslint instead
      "prettier.enable": false,
      "editor.formatOnSave": false,
      // Auto fix
      "editor.codeActionsOnSave": {
      "source.fixAll.eslint": "explicit",
      "source.organizeImports": "never"
      },
      // Enable the ESlint flat config support
      "eslint.useFlatConfig": true,
      "eslint.runtime": "node",
      // Enable eslint for supported languages
      "eslint.validate": [
      "javascript",
      "javascriptreact",
      "typescript",
      "typescriptreact",
      // "astro",
      // "svelte",
      // "vue",
      ]
      }
    JetBrains IDEs
    1. Open the Settings dialog

    2. Go to Languages & Frameworks -> JavaScript -> Code Quality Tools -> ESLint

    3. Select the Run eslint --fix on save checkbox.

  5. Enjoy!