在 ESLint 中扩展多个推荐配置
Extending multiple recommended configurations in ESLint
故事:
目前,我们正在扩展推荐的 ESLint 配置:
{
"extends": "eslint:recommended",
...
"plugins": [
"angular",
"jasmine",
"protractor"
],
"rules": {
"no-multiple-empty-lines": 2,
"no-trailing-spaces": 2,
"jasmine/valid-expect": 2
}
}
并且还使用 angular
、jasmine
和 protractor
ESLint 插件,这些插件还附带 他们自己推荐的配置 (默认规则严格级别和默认规则参数)。
问题:
我们如何同时使用所有推荐的配置 - ESLint 和所有使用的插件附带的配置?
尝试了以下方法:
{
"extends": [
"eslint:recommended",
"plugin:protractor/recommended",
"plugin:jasmine/recommended",
"plugin:angular/recommended"
],
...
}
但出现以下错误:
Cannot read property 'recommended' of undefined
How can we use all the recommended configurations at the same time -
the one that ESLint and all the used plugins ship with?
你的语法是正确的,多个扩展是这样加载的:
{
"extends": [
"eslint:recommended",
"plugin:protractor/recommended",
"plugin:jasmine/recommended",
"plugin:angular/recommended"
]
}
但是,这需要相关插件实际上与推荐设置捆绑在一起。 eslint-plugin-angular
does not,还要自己安装:
npm install --save-dev eslint-config-angular
将您的 eslint 设置更改为
{
"extends": [
"eslint:recommended",
"plugin:protractor/recommended",
"plugin:jasmine/recommended",
"angular"
]
}
它应该可以工作。
故事:
目前,我们正在扩展推荐的 ESLint 配置:
{
"extends": "eslint:recommended",
...
"plugins": [
"angular",
"jasmine",
"protractor"
],
"rules": {
"no-multiple-empty-lines": 2,
"no-trailing-spaces": 2,
"jasmine/valid-expect": 2
}
}
并且还使用 angular
、jasmine
和 protractor
ESLint 插件,这些插件还附带 他们自己推荐的配置 (默认规则严格级别和默认规则参数)。
问题:
我们如何同时使用所有推荐的配置 - ESLint 和所有使用的插件附带的配置?
尝试了以下方法:
{
"extends": [
"eslint:recommended",
"plugin:protractor/recommended",
"plugin:jasmine/recommended",
"plugin:angular/recommended"
],
...
}
但出现以下错误:
Cannot read property 'recommended' of undefined
How can we use all the recommended configurations at the same time - the one that ESLint and all the used plugins ship with?
你的语法是正确的,多个扩展是这样加载的:
{
"extends": [
"eslint:recommended",
"plugin:protractor/recommended",
"plugin:jasmine/recommended",
"plugin:angular/recommended"
]
}
但是,这需要相关插件实际上与推荐设置捆绑在一起。 eslint-plugin-angular
does not,还要自己安装:
npm install --save-dev eslint-config-angular
将您的 eslint 设置更改为
{
"extends": [
"eslint:recommended",
"plugin:protractor/recommended",
"plugin:jasmine/recommended",
"angular"
]
}
它应该可以工作。