Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between plugins and extends in eslint?

I don't understand why we have plugins and extends. What is the difference between them and do I need one or the other?

like image 828
jingteng Avatar asked Nov 07 '18 12:11

jingteng


People also ask

What is ESLint plugin react?

Basically, it is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. It analyzes your code quickly, finds any problems in your code, and even fixes them automatically. In this article, we are going to explore four essential ESLint plugins you will need in your React setup.

What is ESLint plugin prettier?

Runs Prettier as an ESLint rule and reports differences as individual ESLint issues. If your desired formatting does not match Prettier's output, you should use a different tool such as prettier-eslint instead. Please read Integrating with linters before installing.

How many ESLint rules are there?

Keep in mind that we have over 200 rules, and that is daunting both for end users and the ESLint team (who has to maintain them).

How are ESLint rules set?

There are two primary ways to configure ESLint: Configuration Comments - use JavaScript comments to embed configuration information directly into a file. Configuration Files - use a JavaScript, JSON, or YAML file to specify configuration information for an entire directory and all of its subdirectories.


1 Answers

extends uses a config file which applies set of rules when you add that to the extends options. A plugin on the other hand provides you with a set of rules that you can individually apply depending on your need. Just having a plugin does not enforce any rule. You have to choose which rules you need. A plugin may provide you with zero, one, or more configuration files. If the plugin provides configuration file, then you can load that in your extends section after adding the plugin in the plugins section.

So essentially, plugins given you some rules that have been coded and you can choose which ones are relevant. It may also provide config files to apply rules that the authors think are logically grouped/relevant but providing a config file is not mandatory for a plugin. extends, on the other hand, provides you the ability to apply rules in bulk based on config file specifications.

Example Plugin - eslint-plugin-react:

"plugins": [   "react" ], "extends": [   "eslint:recommended",   "plugin:react/recommended" ] 

Example Config - eslint-config-google:

"extends": [   "google" ] 

Good Luck...

like image 195
shmit Avatar answered Oct 02 '22 18:10

shmit