Search code examples
javascripttypescripteslintlinttypescript-eslint

What "plugins" property in .eslintrc does?


module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint'],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
  ],
};

Whenever I add or remove this line: plugins: ['@typescript-eslint'] eslint seems to behave the same. What exactly plugins property does and when using it is required?


Solution

  • This question is pretty straight forward if you think about what a plugin is. The docs don't really do a good job of just out-right saying what an ESLint plugin is, though if you read through the docs (https://eslint.org/docs/user-guide/configuring), then it's pretty trivial to figure out:

    ESLint supports the use of third-party plugins

    When using rules, environments or configs defined by plugins. Before using the plugin, you have to install it using npm.

    So a plugin is a 3rd party module that can define rules, environments, or configs.

    So to answer your question:

    What exactly plugins property does [sic]

    the plugins property tells ESLint what plugins you want to use

    and when using it is required? [sic]

    when you use something from a plugin, you must first tell ESLint about it with the plugins property.


    Plugins seem to work anyway when this field is omitted

    If you use the extends option with the syntax plugin:<plugin>/<config>, then ESLint will load a specific file from the plugin ahead of time.

    Why? Because this allows a plugin to provide a config and reduce the amount of config you need. A plugin's config can provide the plugins option for you, meaning you don't need to do it yourself.