gpt4 book ai didi

tslint - `Tslint --fix` 不会自动修复,而是生成 lint 问题作为控制台错误

转载 作者:行者123 更新时间:2023-12-03 16:25:44 27 4
gpt4 key购买 nike

我正在使用 the Angular starter kit

我正在尝试让 tslint 使用 --fix 标志自动修复我所有的 lint 问题。

我正在运行脚本:npm run tslint --fix src/**/*.ts
它只是产生与我在 tslint 中已经被告知的相同的错误。而不是自动修复它:

控制台输出:

ERROR: src/app/app-routing.module.ts[10, 5]: comment must start with a space
ERROR: src/app/app-routing.module.ts[2, 20]: Too many spaces before 'from'

我是否缺少允许它实现更改的东西?

我的版本是:
"tslint": "^5.6.0"  
"codelyzer": "^3.1.2"

问题:如何让 tslint 对我的 lint 错误实现自动修复?

最佳答案

不幸的是,并非所有的 linting 违规都可以自动修复。你可以看到which rules are auto-fixable here通过寻找 Has Fixer标签。

我的猜测是“评论必须以空格开头”由 comment-format rule 控制。 ,这是不可自动修复的。

我不确定哪个规则导致了您的第二个错误,但它很可能也无法自动修复。

这是您可以运行的片段 tslint --fix反对验证某些违规行为已修复,而其他违规行为未修复。

//no var keyword (comment does not start with space)
var x: string = 'x';
console.log(x);

// array-type
let y: String[] = [];
console.log(y);

// ban-single-arg-parens
['1', '2'].filter((arg) => {
console.log(arg);
});

// semicolon
let z: string = ''
console.log(z);

// no unused variable
let a: string = '';

// trailing comma
let list = ['1', '2', ];

// missing trailing comma
let obj = [
1,
2
];

对上述文件进行 linting 时要包含的规则:
"semicolon": [true, "always"],
"trailing-comma": [true, {"multiline": "always", "singleline": "never"}],
"array-type": [true, "array-generic"],
"arrow-parens": [true, "ban-single-arg-parens"],

人们很容易认为所有的空白错误都是可以自动修复的,也许它们应该是。可悲的是,他们不是。

关于tslint - `Tslint --fix` 不会自动修复,而是生成 lint 问题作为控制台错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45687039/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com