There's answered question which in my opinion doesn't actually answers the question, on the difference between extends: []
vs plugins: []
in ESLint.
In my case, i just used extends section:
extends: [
'plugin:@typescript-eslint/recommended',
],
plugins: [],
rules: {
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
},
],
}
As you can see, i just used predefined config from plugin:@typescript-eslint/recommended
and also overwritten @typescript-eslint/explicit-function-return-type
rule in rules: {}
section. But why do we need this PLUGINS section then? If everything works without it? What do i miss?
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.
ESLint handles such a named code block as a child file of the original file. You can specify additional configurations for named code blocks in the overrides section of the config. For example, the following disables the strict rule for the named code blocks which end with . js in markdown files.
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.
The ESLint configuration is in the ./node_modules/@spm/eslint-config/index. js file. To check the code for ESLint violations, run the following command in the application root directory.
You have done it correctly.
For your example, there are 2 ways to do add typescript-eslint
...
{
parser: "@typescript-eslint/parser",
parserOptions: { sourceType: "module" },
plugins: ["@typescript-eslint"],
extends: [],
rules: {
"@typescript-eslint/explicit-function-return-type": [
"error",
{
allowExpressions: true
}
]
}
}
{
plugins: [],
extends: ["plugin:@typescript-eslint/recommended"],
rules: {
"@typescript-eslint/explicit-function-return-type": [
"error",
{
allowExpressions: true
}
]
}
}
The difference is...
parser
, parserOptions
and plugins
are manually added,@typescript-eslint/explicit-function-return-type
is enforced.plugin:@typescript-eslint/recommended
has automatically added parser
, parserOptions
and plugins
.@typescript-eslint/explicit-function-return-type
is augmented and enforced.This is why when you use plugin:@typescript-eslint/recommended
, things work normally even if plugins
is empty. A well-written plugins/configs allows that to happen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With