两者,
(逗号)和;
(分号)是有效的语法而宣告打字稿接口例如以下两者都是有效
export interface IUser {
name: string;
email: string;
id: number;
}
export interface IUser {
name: string,
email: string,
id: number
}
以下是我的关注,因为它也是有效的。的混合,
和;
也适用
export interface IUser {
name: string;
email: string,
id: number;
}
现在为了保持一致,我想;
在所有场合都强制使用。即使强制执行了分号规则,我的毛发也仍然可以通过typescript
。任何想法如何实现?
.eslintrc.json
{
"root": true,
"ignorePatterns": [
"projects/**/*"
],
"overrides": [
{
"files": [
"*.ts"
],
"parserOptions": {
"project": [
"tsconfig.json",
"e2e/tsconfig.json"
],
"createDefaultProgram": true
},
"extends": [
"plugin:@angular-eslint/ng-cli-compat",
"plugin:@angular-eslint/ng-cli-compat--formatting-add-on",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
],
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
]
}
},
{
"files": [
"*.html"
],
"extends": [
"plugin:@angular-eslint/template/recommended"
],
"rules": {}
}
]
}
tsconfig.json
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
}
}
在.eslintrc文件中,添加以下提到的规则,
"@typescript-eslint/member-delimiter-style": [
"warn",
{
"multiline": {
"delimiter": "semi",
"requireLast": true
},
"singleline": {
"delimiter": "semi",
"requireLast": false
}
}
]
接受三个值(对于单行,则接受两个):
逗号-每个成员应以逗号(,)分隔。
分号-每个成员应以分号(;)分隔。
无-每个成员之间都不应有任何分隔。
注–这不是单行的选项,因为在单行的成员之间没有定界符是TS中的语法错误。requireLast确定接口/类型中的最后一个成员是否应具有定界符:
参考链接:单击此处
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句