如何自动修复 vuejs 中的 tslint 错误
How can I auto fix tslint errors in vuejs
我 运行 vue-cli-service lint --fix
在我的 vuejs/typescript 项目中。正如预期的那样,大多数 linting errors/warning 都会自动修复。
但是有特定的 tslint 规则("semicolon": [true, "always", "ignore-interfaces"]
) 我想用这个命令自动修复。假设我的打字稿界面看起来像这样(预期的 lint 结果)。
interface component {
type: "input" | "dropdown" | "checkbox",
hidden?: boolean
}
在 运行 lint 之后,它会像这样格式化。消息是 [eslint] Replace
,with
;(prettier/prettier)
interface component {
type: "input" | "dropdown" | "checkbox";
hidden?: boolean;
}
我已将此规则 "semicolon": [true, "always", "ignore-interfaces"]
添加到 tslint 文件中,但它不会更改结果。
控制台消息 ([eslint] Replace , with ; (prettier/prettier)
) 表明您在使用 Vue CLI 生成项目时选择了 ESLint + Prettier
选项;但是 ESLint 不支持开箱即用的 tslint.json
(需要 plugin,但是 YMMV)。
另一种方法是切换到 TSLint,并编辑生成的 tslint.json
以包含您想要的 semicolon
规则。
我 运行 vue-cli-service lint --fix
在我的 vuejs/typescript 项目中。正如预期的那样,大多数 linting errors/warning 都会自动修复。
但是有特定的 tslint 规则("semicolon": [true, "always", "ignore-interfaces"]
) 我想用这个命令自动修复。假设我的打字稿界面看起来像这样(预期的 lint 结果)。
interface component {
type: "input" | "dropdown" | "checkbox",
hidden?: boolean
}
在 运行 lint 之后,它会像这样格式化。消息是 [eslint] Replace
,with
;(prettier/prettier)
interface component {
type: "input" | "dropdown" | "checkbox";
hidden?: boolean;
}
我已将此规则 "semicolon": [true, "always", "ignore-interfaces"]
添加到 tslint 文件中,但它不会更改结果。
控制台消息 ([eslint] Replace , with ; (prettier/prettier)
) 表明您在使用 Vue CLI 生成项目时选择了 ESLint + Prettier
选项;但是 ESLint 不支持开箱即用的 tslint.json
(需要 plugin,但是 YMMV)。
另一种方法是切换到 TSLint,并编辑生成的 tslint.json
以包含您想要的 semicolon
规则。