1. eslint-define-config
Provide a defineConfig function for .eslintrc.js files
eslint-define-config
Package: eslint-define-config
Created by: eslint-types
Last modified: Wed, 27 Dec 2023 10:32:39 GMT
Version: 2.1.0
License: MIT
Downloads: 290,104
Repository: https://github.com/eslint-types/eslint-define-config

Install

npm install eslint-define-config
yarn add eslint-define-config

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.

Installation

 # 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

By default only eslint's rules are supported. To activate auto-suggestions for Rules of specific plugins, you need to install the respective types for that plugin.
Plugins can either support their own types, or they could be supported by the community in the @eslint-types repository.

A list of community supported plugins can be found here.

.eslintrc.js

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

/// <reference types="@eslint-types/typescript-eslint" />

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

Flat Config

eslint.config.js

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

/// <reference types="@eslint-types/typescript-eslint" />

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:

 declare module 'eslint-define-config' {
  export interface CustomRuleOptions {
    /**
     * Require consistently using either `T[]` or `Array<T>` 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

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin