ESLint: types for `eslintrc.js`

1.8k views Asked by At

I want my eslintrc.js to be typechecked, and to have all the type definitions of allowed rules builtin.

i.e. like:

module.exports = defineESLint({
  rules: {
    // intellisence: Enforce the consistent use of either backticks, double, or single quotes
    // quotes?: 'off' | 'warn' | 'error'
    // | ['warn' | 'error', 'single' | 'double', { avoidEscape?: true }]
    quotes: ["warn", 'single', {avoidEscape: true}],
  }
})

And I generally want this to work with all my eslint extensions

Currently all I can do is

{
  "$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/eslintrc.json",
  "rules": {
    "quotes": [
      "warn",
      "single",
      {
        "avoidEscape": true
      }
    ]
  }
}

in json, but it barely works

1

There are 1 answers

0
Dimava On BEST ANSWER

npm:eslint-define-config

usage:

.eslintrc.js

// @ts-check
const { defineConfig } = require('eslint-define-config');

module.exports = defineConfig({
  root: true,
  rules: {
    // rules...
  },
});

Improve your eslint configuration experience with:

  • auto-suggestions
  • type checking (Use // @ts-check at the first line in your .eslintrc.js)
  • documentation
  • deprecation warnings