NPM package Downloads Build Status License: MIT Code Style: Prettier Donate: PayPal

# eslint-define-config Provide a `defineConfig` function for `.eslintrc.js`, and a `defineFlatConfig` function for `eslint.config.js` files. > This project is written by a human and only partially automatically generated! > Some rules are even enhanced by hand! > Unfortunately, this has the disadvantage that not everything is immediately defined. For example, if a rule is not defined, it falls back to a basic definition. > However, the advantage is that you get documentation for pretty much everything in the code and usually get a direct link to the respective plugin or eslint rule. The types are also strictly typed. > > So if you are missing something like a rule or a plugin that should also be supported or a rule definition is e.g. out of date, feel free to open an issue or PR for it. # Installation ```bash # add eslint and eslint-define-config to project’s dev dependencies npm add --save-dev eslint eslint-define-config # or yarn add --dev eslint eslint-define-config # or pnpm add --save-dev eslint eslint-define-config ``` # Usage `.eslintrc.js` ```ts // @ts-check // To activate auto-suggestions for Rules of specific plugins, you need to add a `/// ` comment. // ⚠️ This feature is very new and requires the support of the respective plugin owners. /// const { defineConfig } = require('eslint-define-config'); module.exports = defineConfig({ root: true, rules: { // rules... }, }); ``` ## Flat Config `eslint.config.js` ```ts // @ts-check const { defineFlatConfig } = require('eslint-define-config'); module.exports = defineFlatConfig([ 'eslint:recommended', { plugins: { // plugins... }, rules: { // rules... }, }, ]); ``` # Why? Improve your eslint configuration experience with: - auto-suggestions - type checking (Use `// @ts-check` at the first line in your `.eslintrc.js` or `eslint.config.js`) - documentation - deprecation warnings Image ## Video _Click on the thumbnail to play the video_ Video ## Want to support your own plugin? :warning: **This feature is very new and requires the support of the respective plugin owners** Add a `declare module` to your plugin package like this: ```ts declare module 'eslint-define-config' { export interface CustomRuleOptions { /** * Require consistently using either `T[]` or `Array` for arrays. * * @see [array-type](https://typescript-eslint.io/rules/array-type) */ '@typescript-eslint/array-type': [ { default?: 'array' | 'generic' | 'array-simple'; readonly?: 'array' | 'generic' | 'array-simple'; }, ]; // ... more Rules } } ``` There are other interfaces that can be extended. - `CustomExtends` - `CustomParserOptions` - `CustomParsers` - `CustomPlugins` - `CustomSettings` # Credits - [Proposal Idea](https://github.com/eslint/eslint/issues/14249) - [Vite](https://github.com/vitejs/vite) and [Evan You](https://github.com/yyx990803) for the idea - [@antfu](https://github.com/antfu) and his [tweet](https://twitter.com/antfu7/status/1365907188338753536)