目前 Angular2 项目内的 TSLint 设置

部分 TSLint 提示对应描述

提示描述
Exceeds maximum line length of 150单行超150字符
expected an assignment or function call缺少赋值或函数调用,三目写成if即可
Identifier ‘p’ is never reassigned; use ‘const’ instead of ‘let’.变量为常量,使用const代替let
!= should be !==判断应精确类型
== should be ===判断应精确类型
comment must start with a space//注释应以空格开头
while statements must be bracedwhile缺少{}
for (… in …) statements must be filtered with an if statementfor in 循环体内应有if判断属性是否存在
Declaration of instance field not allowed after declaration of instance method. Instead, this should come at the beginning of the class/interface.class/interface的属性定义应放在方法前
Declaration of static method not allowed after declaration of instance method. Instead, this should come after instance fields.class/interface的静态方法定义应放在非静态方法前
Shadowed variable变量命名与上级作用域内重名
misplaced ‘else’else可能无法找到匹配的if
missing whitespace少空格
Too many spaces after ‘from’form后有多了个空格
Missing radix parameterparseInt缺少转换基数,直接第二个参数为0即可
Implement lifecycle hook interface AfterViewInit for method ngAfterViewInit in class IndexSideComponent (https实现了一个接口但没有声明要实现该接口
expected nospace before colon in property-declaration:前多了个空格
Too many spaces after ‘import’import后多了个空格
Class name must be in pascal case类命名不满足pascal case命名规则(各个单词首字母要大写)
if statements must be bracedif缺少{}
file should end with a newline文件末尾应有个空行
Unused variable: ‘s’未使用的变量,如需要保留则以双_开头

TSLint 设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"no-import-side-effect": [
false,
{
"ignore-module": "(\\.html|\\.css)$"
}
],
"only-arrow-functions": false,
"prefer-for-of": false,
"ban": [
false,
"$"
],
"import-blacklist": [
false,
"rxjs"
],
"no-console": [
false,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-null-keyword": false,
"no-require-imports": false,
"no-string-literal": false,
"object-literal-sort-keys": false,
"array-type": [
false,
"array",
"generic",
"array-simple"
],
"completed-docs": false,
"file-header": false,
"newline-before-return": false,
"no-parameter-properties": false,
"object-literal-shorthand": false,
"one-variable-per-declaration": false,
"prefer-function-over-method": false,
"prefer-method-signature": false,
"space-before-function-paren": true,
"ordered-imports": true,
"no-unnecessary-initializer": true,
"no-angle-bracket-type-assertion": true,
"new-parens": true,
"interface-name": [true, "never-prefix"],
"arrow-return-shorthand": [true, "multiline"],
"align": [
true,
"parameters",
"statements"
],
"no-mergeable-namespace": true,
"no-default-export": true,
"max-classes-per-file": [
true,
2
],
"cyclomatic-complexity": [
true,
25
],
"linebreak-style": [
true,
"LF"
],
"use-isnan": true,
"switch-default": true,
"no-unsafe-finally": true,
"no-misused-new": true,
"no-invalid-this": true,
"no-duplicate-super": true,
"no-conditional-assignment": true,
"callable-types": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
"eofline": true,
"forin": true,
"import-spacing": true,
"indent": [
true,
"spaces"
],
"interface-over-type-literal": true,
"label-position": true,
"max-line-length": [
true,
150
],
"member-access": false,
"member-ordering": [
true,
"static-before-instance",
"variables-before-functions"
],
"no-arg": true,
"no-bitwise": true,
"no-construct": true,
"no-debugger": true,
"no-duplicate-variable": true,
"no-empty": false,
"no-empty-interface": true,
"no-eval": true,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-shadowed-variable": true,
"no-string-throw": true,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unused-expression": true,
"no-unused-variable": [
true,
{
"ignore-pattern": "^__"
}
],
"no-use-before-declare": true,
"no-var-keyword": true,
"one-line": [
true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"prefer-const": true,
"quotemark": [
true,
"single"
],
"radix": true,
"semicolon": [
"always"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"typeof-compare": true,
"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"
],
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
"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": true,
"templates-use-public": true,
"invoke-injectable": true
}
}