我试图使用angular,eslint:推荐和jasmine插件推荐的设置来提示我的角度代码。但是我得到的不是茉莉花的错误。 我的eslint文件如下所示:
{
"plugins": ["jasmine"],
"extends": ["angular", "eslint:recommended",
"plugin:jasmine/recommended"],
"rules": {
"quotes": [ 2, "single"],
"strict": [2, "global"],
"semi": ["error", "always"],
"angular/on-watch": "warn"
}
}
我收到以下错误:
3:1错误'描述'未定义no-undef
4:5错误'它'未定义no-undef
5:9错误'期待'未定义no-undef
7:5错误'它'未定义no-undef
8:9错误'期待'未定义no-undef
我的package.json
2.3.0
版本eslint
和1.8.1
版本eslint-plugin-jasmine
。我的0.5.0
版本eslint-config-angular
和1.0.0
版本eslint-plugin-angular
。
我也试过没有在我的"plugins": ["jasmine"]
文件中指定eslint
,但后来我收到错误告诉我茉莉花规则没有定义(例如Definition for rule 'jasmine/no-focused-tests' was not found
)。
答案 0 :(得分:20)
添加
static
解决了这个问题。这是我通过eslint jasmine插件的github页面的建议。
答案 1 :(得分:2)
设置this rule后,任何非显式声明的变量都会引发警告。 您可以设置在规范文件的顶部:
/* global describe it expect */
答案 2 :(得分:0)
您可以将/* eslint-env jasmine */
添加到.spec.ts
文件的顶部。该解决方案与Geert提出的解决方案基本相同,但具有按文件的解决方案。细微的区别是,在非测试文件中使用一些describe()
和it()
这样的全局定义的测试方法仍然是错误的。
(设置ESLint的方法可能很聪明,因此您不必将此行添加到所有.spec.ts
文件中。)
答案 3 :(得分:0)
我发现为所有 Jasmine 函数配置验证并在一个地方完成,但在“非规范”文件中使用它们时仍然标记它们的方法如下。
在配置级别定义通用配置。然后,对于那些特定的配置(例如 Typescript 或 Jasmin)进行覆盖。这样,“全局配置”仅适用于特定文件。
{
"env": {
"jasmine": true
},
"files": ["**/*.spec.js"]
}
.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": {...}
};