【发布时间】:2019-12-03 03:45:30
【问题描述】:
当我运行 ng lint 时,突然出现所有这些错误错误
Forbidden 'var' keyword, use 'let' or 'const' instead
但我知道我没有在这些文件中的任何地方使用var,同样当我运行ng lint --fix 时,它用let so 替换export 中的exp 和function 中的fun export function 变为 letport letction
我不知道这如何开始发生或为什么开始发生
这是我的 tslint 文件
{
"rulesDirectory": ["node_modules/codelyzer"],
"rules": {
"arrow-return-shorthand": true,
"callable-types": true,
"class-name": true,
"comment-format": [true],
"curly": true,
"eofline": true,
"forin": true,
"import-blacklist": [true],
"import-spacing": true,
"interface-over-type-literal": true,
"label-position": true,
"max-line-length": [false],
"member-access": false,
"member-ordering": [
true,
{
"order": ["static-field", "instance-field", "static-method", "instance-method"]
}
],
"no-arg": true,
"no-bitwise": true,
"no-console": [true, "debug", "info", "time", "timeEnd", "trace"],
"no-construct": true,
"no-debugger": true,
"no-duplicate-super": true,
"no-empty": false,
"no-empty-interface": true,
"no-eval": false,
"no-inferrable-types": [true, "ignore-params"],
"no-misused-new": true,
"no-non-null-assertion": true,
"no-shadowed-variable": false,
"no-string-literal": false,
"no-string-throw": true,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unnecessary-initializer": true,
"no-unused-expression": false,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [true, "check-open-brace", "check-catch", "check-else", "check-whitespace"],
"prefer-const": false,
"quotemark": [true, "single"],
"radix": false,
"semicolon": [true, "always"],
"triple-equals": [true, "allow-null-check"],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"unified-signatures": true,
"variable-name": false,
"whitespace": [true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type"],
"directive-selector": [false, "attribute", "app", "camelCase"],
"component-selector": [false, "element", "app", "kebab-case"],
"no-input-rename": true,
"no-output-rename": true,
"use-life-cycle-interface": true,
"use-pipe-transform-interface": true,
"component-class-suffix": true,
"directive-class-suffix": true,
"no-access-missing-member": false
}
}
在我的 package.json 中
"typescript": "3.4.5",
"codelyzer": "^5.1.0",
"tslint": "5.17.0",
我似乎也收到了很多警告,例如
The 'no-arg' rule threw an error in '/angular/src/shared/helpers/FormattedStringValueExtracter.ts':
这就是那个文件
class ExtractionResult {
public IsMatch: boolean;
public Matches: any[];
constructor(isMatch: boolean) {
this.IsMatch = isMatch;
this.Matches = [];
}
}
enum FormatStringTokenType {
ConstantText,
DynamicValue
}
class FormatStringToken {
public Text: string;
public Type: FormatStringTokenType;
constructor(text: string, type: FormatStringTokenType) {
this.Text = text;
this.Type = type;
}
}
class FormatStringTokenizer {
Tokenize(format: string, includeBracketsForDynamicValues: boolean = false): FormatStringToken[] {
const tokens: FormatStringToken[] = [];
let currentText = '';
let inDynamicValue = false;
for (let i = 0; i < format.length; i++) {
const c = format[i];
switch (c) {
case '{':
if (inDynamicValue) {
throw new Error(
'Incorrect syntax at char ' + i + '! format string can not contain nested dynamic value expression!'
);
}
inDynamicValue = true;
if (currentText.length > 0) {
tokens.push(new FormatStringToken(currentText, FormatStringTokenType.ConstantText));
currentText = '';
}
break;
case '}':
if (!inDynamicValue) {
throw new Error(
'Incorrect syntax at char ' + i + '! These is no opening brackets for the closing bracket }.'
);
}
inDynamicValue = false;
if (currentText.length <= 0) {
throw new Error('Incorrect syntax at char ' + i + '! Brackets does not containt any chars.');
}
let dynamicValue = currentText;
if (includeBracketsForDynamicValues) {
dynamicValue = '{' + dynamicValue + '}';
}
tokens.push(new FormatStringToken(dynamicValue, FormatStringTokenType.DynamicValue));
currentText = '';
break;
default:
currentText += c;
break;
}
}
if (inDynamicValue) {
throw new Error('There is no closing } char for an opened { char.');
}
if (currentText.length > 0) {
tokens.push(new FormatStringToken(currentText, FormatStringTokenType.ConstantText));
}
return tokens;
}
}
export class FormattedStringValueExtracter {
Extract(str: string, format: string): ExtractionResult {
if (str === format) {
return new ExtractionResult(true);
}
const formatTokens = new FormatStringTokenizer().Tokenize(format);
if (!formatTokens) {
return new ExtractionResult(str === '');
}
const result = new ExtractionResult(true);
for (let i = 0; i < formatTokens.length; i++) {
const currentToken = formatTokens[i];
const previousToken = i > 0 ? formatTokens[i - 1] : null;
if (currentToken.Type === FormatStringTokenType.ConstantText) {
if (i === 0) {
if (str.indexOf(currentToken.Text) !== 0) {
result.IsMatch = false;
return result;
}
str = str.substr(currentToken.Text.length, str.length - currentToken.Text.length);
} else {
const matchIndex = str.indexOf(currentToken.Text);
if (matchIndex < 0) {
result.IsMatch = false;
return result;
}
result.Matches.push({ name: previousToken.Text, value: str.substr(0, matchIndex) });
str = str.substring(0, matchIndex + currentToken.Text.length);
}
}
}
const lastToken = formatTokens[formatTokens.length - 1];
if (lastToken.Type === FormatStringTokenType.DynamicValue) {
result.Matches.push({ name: lastToken.Text, value: str });
}
return result;
}
IsMatch(str: string, format: string): string[] {
const result = new FormattedStringValueExtracter().Extract(str, format);
if (!result.IsMatch) {
return [];
}
const values = [];
for (let i = 0; i < result.Matches.length; i++) {
values.push(result.Matches[i].value);
}
return values;
}
}
当我查看它说它有问题的任何文件时,没有警告或错误......而当我实际上在文件中但 var 它不再给我任何警告......在问题中VSCODE 中的面板
任何帮助将不胜感激!真的想不通这个!
编辑
我也看到类似
的错误TypeError: Cannot read property 'pos' of undefined
at cb (/node_modules/tslint/lib/rules/oneLineRule.js
好像 tslint 有问题???
编辑
这是我的角度版本
Angular CLI: 8.1.2
Node: 10.16.0OS: linux x64
Angular: 8.1.2
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router, service-worker
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.800.6
@angular-devkit/build-angular 0.800.6
@angular-devkit/build-optimizer 0.800.6
@angular-devkit/build-webpack 0.800.6
@angular-devkit/core 8.1.2
@angular-devkit/schematics 7.3.9
@angular/cdk 7.3.7
@angular/http 7.2.15
@angular/pwa 0.12.4
@ngtools/webpack 8.0.6
@schematics/angular 7.2.4
@schematics/update 0.801.2
rxjs 6.5.2
typescript 3.4.5
【问题讨论】:
-
您是否使用任何其他转译器(除了 TS)?还 - 尝试删除 codelizer 默认规则集
"rulesDirectory": ["node_modules/codelyzer"], -
@c69 我不这么认为.. 我在哪里可以找到?我将从 rulesDirectory 中删除 codelyzer 并更新
-
你执行
ng lint,这听起来像你有NG CLI。尝试运行ng version(请参阅angular.io/cli)以及可选的npm -v、node -v、typescript -v、npm ls、npm audit)以了解您是否拥有最新的所有内容并且没有损坏的依赖项。 -
@c69 我已经用我的角度版本更新了我的问题
-
npm:
6.90,节点:v10.16.0,typescript -v 返回zsh: no command found typescript(这可能是问题吗??)
标签: angular typescript tslint