'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 1:[1]

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.

Solution 2:[2]

I was also curious about what is parser and plugin

From documentation

"For example, once this parser successfully produces an AST for the TypeScript source code, it might well contain some information which simply does not exist in a standard JavaScript context, such as the data for a TypeScript-specific construct, like an interface.

The core rules built into ESLint, such as indent have no knowledge of such constructs, so it is impossible to expect them to work out of the box with them.

Instead, you also need to make use of one more plugins which will add or extend rules with TypeScript-specific features."

This helped me to understand it better.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brad Zacher
Solution 2 user269867