Gee*_*rts 8 jasmine angularjs eslint
我试图使用角度,eslint:推荐和茉莉花插件推荐设置lint我的角度代码.但是我得到的不是茉莉花的错误.我的eslint文件看起来像这样:
{
"plugins": ["jasmine"],
"extends": ["angular", "eslint:recommended",
"plugin:jasmine/recommended"],
"rules": {
"quotes": [ 2, "single"],
"strict": [2, "global"],
"semi": ["error", "always"],
"angular/on-watch": "warn"
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
3:1错误'describe'未定义no-undef
4:5错误'it'未定义no-undef
5:9错误'expect'未定义no-undef
7:5错误'it'未定义no-undef
8:9错误'expect'未定义no-undef
而在我的package.json
我有版本2.3.0
的eslint
和1.8.1
为eslint-plugin-jasmine
.我也有0.5.0
for eslint-config-angular
和1.0.0
for的版本eslint-plugin-angular
.
我也试过没有"plugins": ["jasmine"]
在我的eslint
文件中指定,但后来我得到一个错误,告诉我茉莉花规则没有定义(例如Definition for rule 'jasmine/no-focused-tests' was not found
).
Gee*_*rts 23
添加
"env": {
"jasmine": true
}
Run Code Online (Sandbox Code Playgroud)
解决了这个问题.这是我通过eslint jasmine插件的github页面的建议.
我发现为所有 Jasmine 函数配置验证并在一个地方执行它,但在“非规范”文件中使用它们时仍然标记它们的方法如下。
在配置级别定义通用配置。然后,对于那些特定配置(例如 Typescript 或 Jasmin)进行覆盖。这样,“全局配置”仅应用于特定文件。
{
"env": {
"jasmine": true
},
"files": ["**/*.spec.js"]
}
Run Code Online (Sandbox Code Playgroud)
片段.eslintrc.js
:
/**
* @type {import("eslint").Linter.Config}
*/
module.exports = {
"env": {...},
"extends": [
"eslint:recommended"
],
"overrides": [
{
"extends": [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"files": ["**/*.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"tsconfigRootDir": __dirname
},
"plugins": [
"@typescript-eslint"
]
},
// This is the important part
{
"env": {
"jasmine": true
},
"files": ["**/*.spec.js"]
}
],
"root": true,
"rules": {...}
};
Run Code Online (Sandbox Code Playgroud)
使用此规则集,任何未显式声明的变量都会导致警告。您可以在规范文件的顶部设置:
/* global describe it expect */
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6769 次 |
最近记录: |