-
Notifications
You must be signed in to change notification settings - Fork 38
/
rules-oclint.xml
518 lines (514 loc) · 23.7 KB
/
rules-oclint.xml
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
<rules>
<rule>
<key>bitwise operator in conditional</key>
<name>Bitwise operator in conditional</name>
<priority>CRITICAL</priority>
<description>Checks for bitwise operations in conditionals. Although being written on purpose in some rare cases, bitwise operations are considered to be too “smart”. Smart code is not easy to understand.</description>
</rule>
<rule>
<key>broken nil check</key>
<name>Broken nil check</name>
<priority>CRITICAL</priority>
<description>The broken nil check in Objective-C in some cases returns just the opposite result.</description>
</rule>
<rule>
<key>broken null check</key>
<name>Broken null check</name>
<priority>CRITICAL</priority>
<description>The broken null check itself will crash the program.</description>
</rule>
<rule>
<key>broken oddness check</key>
<name>Broken oddness check</name>
<priority>CRITICAL</priority>
<description>Checking oddness by x%2==1 won’t work for negative numbers. Use x&1==1, or x%2!=0 instead.</description>
</rule>
<rule>
<key>collapsible if statements</key>
<name>Collapsible if statements</name>
<priority>CRITICAL</priority>
<description>This rule detects instances where the conditions of two consecutive if statements can combined into one in order to increase code cleanness and readability.</description>
</rule>
<rule>
<key>constant conditional operator</key>
<name>Constant conditional operator</name>
<priority>CRITICAL</priority>
<description>conditionaloperator whose conditionals are always true or always false are confusing.</description>
</rule>
<rule>
<key>constant if expression</key>
<name>Constant if expression</name>
<priority>CRITICAL</priority>
<description>if statements whose conditionals are always true or always false are confusing.</description>
</rule>
<rule>
<key>dead code</key>
<name>Dead code</name>
<priority>CRITICAL</priority>
<description>Code after return, break, continue, and throw statements are unreachable and will never be executed.</description>
</rule>
<rule>
<key>double negative</key>
<name>Double negative</name>
<priority>CRITICAL</priority>
<description>There is no point in using a double negative, it is always positive.</description>
</rule>
<rule>
<key>for loop should be while loop</key>
<name>For loop should be while loop</name>
<priority>CRITICAL</priority>
<description>Under certain circumstances, some for loops can be simplified to while loops to make code more concise.</description>
</rule>
<rule>
<key>goto statement</key>
<name>Goto statement</name>
<priority>CRITICAL</priority>
<description>“Go To Statement Considered Harmful”</description>
</rule>
<rule>
<key>misplaced nil check</key>
<name>Misplaced nil check</name>
<priority>CRITICAL</priority>
<description>The nil check is misplaced. In Objective-C, sending a message to a nil pointer simply does nothing. But code readers may be confused about the misplaced nil check.</description>
</rule>
<rule>
<key>misplaced null check</key>
<name>Misplaced null check</name>
<priority>CRITICAL</priority>
<description>The null check is misplaced. In C and C++, sending a message to a null pointer could crash the app. When null is misplaced, either the check is useless or it’s incorrect.</description>
</rule>
<rule>
<key>multiple unary operator</key>
<name>Multiple unary operator</name>
<priority>CRITICAL</priority>
<description>Multiple unary operator can always be confusing and should be simplified.</description>
</rule>
<rule>
<key>return from finally block</key>
<name>Return from finally block</name>
<priority>CRITICAL</priority>
<description>Returning from a finally block is not recommended.</description>
</rule>
<rule>
<key>throw exception from finally block</key>
<name>Throw exception from finally block</name>
<priority>CRITICAL</priority>
<description>Throwing exceptions within a finally block may mask other exceptions or code defects.</description>
</rule>
<rule>
<key>avoid branching statement as last in loop</key>
<name>Avoid branching statement as last in loop</name>
<priority>MAJOR</priority>
<description>Having branching statement as the last statement inside a loop is very confusing, and could largely be forgetting of something and turning into a bug.</description>
</rule>
<rule>
<key>default label not last in switch statement</key>
<name>Default label not last in switch statement</name>
<priority>MAJOR</priority>
<description>It is very confusing when default label is not the last label in a switch statement.</description>
</rule>
<rule>
<key>inverted logic</key>
<name>Inverted logic</name>
<priority>MAJOR</priority>
<description>An inverted logic is hard to understand.</description>
</rule>
<rule>
<key>non case label in switch statement</key>
<name>Non case label in switch statement</name>
<priority>MAJOR</priority>
<description>It is very confusing when default label is not the last label in a switch statement.</description>
</rule>
<rule>
<key>parameter reassignment</key>
<name>Parameter reassignment</name>
<priority>MAJOR</priority>
<description>Reassigning values to parameters is very problematic in most cases.</description>
</rule>
<rule>
<key>switch statements should have default</key>
<name>Switch statements should have default</name>
<priority>MAJOR</priority>
<description>Switch statements should a default statement.</description>
</rule>
<rule>
<key>too few branches in switch statement</key>
<name>Too few branches in switch statement</name>
<priority>MAJOR</priority>
<description>To increase code readability, when a switch consists of only a few branches, it’s much better to use if statement.</description>
</rule>
<rule>
<key>empty catch statement</key>
<name>Empty catch statement</name>
<priority>CRITICAL</priority>
<description>This rule detects instances where an exception is caught, but nothing is done about it.</description>
</rule>
<rule>
<key>empty do/while statement</key>
<name>Empty do while statement</name>
<priority>CRITICAL</priority>
<description>This rule detects instances where a do-while statement does nothing.</description>
</rule>
<rule>
<key>empty else block</key>
<name>Empty else block</name>
<priority>CRITICAL</priority>
<description>This rule detects instances where a else statement does nothing.</description>
</rule>
<rule>
<key>empty finally statement</key>
<name>Empty finally statement</name>
<priority>CRITICAL</priority>
<description>This rule detects instances where a finally statement does nothing.</description>
</rule>
<rule>
<key>empty for statement</key>
<name>Empty for statement</name>
<priority>CRITICAL</priority>
<description>This rule detects instances where a for statement does nothing.</description>
</rule>
<rule>
<key>empty if statement</key>
<name>Empty if statement</name>
<priority>CRITICAL</priority>
<description>This rule detects instances where a condition is checked, but nothing is done about it.</description>
</rule>
<rule>
<key>empty switch statement</key>
<name>Empty switch statement</name>
<priority>CRITICAL</priority>
<description>This rule detects instances where a switch statement does nothing.</description>
</rule>
<rule>
<key>empty try statement</key>
<name>Empty try statement</name>
<priority>CRITICAL</priority>
<description>This rule detects instances where a try statement is empty.</description>
</rule>
<rule>
<key>empty while statement</key>
<name>Empty while statement</name>
<priority>CRITICAL</priority>
<description>This rule detects instances where a while statement does nothing.</description>
</rule>
<rule>
<key>replace with boxed expression</key>
<name>Obj c boxed expressions</name>
<priority>MINOR</priority>
<description>This rule locates the places that can be migrated to the new Objective-C literals with boxed expressions.</description>
</rule>
<rule>
<key>replace with container literal</key>
<name>Obj c container literals</name>
<priority>MINOR</priority>
<description>This rule locates the places that can be migrated to the new Objective-C literals with container literals.</description>
</rule>
<rule>
<key>replace with number literal</key>
<name>Obj cns number literals</name>
<priority>MINOR</priority>
<description>This rule locates the places that can be migrated to the new Objective-C literals with number literals.</description>
</rule>
<rule>
<key>replace with object subscripting</key>
<name>Obj c object subscripting</name>
<priority>MINOR</priority>
<description>This rule locates the places that can be migrated to the new Objective-C literals with object subscripting.</description>
</rule>
<rule>
<key>long variable name</key>
<name>Long variable name</name>
<priority>MAJOR</priority>
<description>Variables with long names harm readability.</description>
</rule>
<rule>
<key>short variable name</key>
<name>Short variable name</name>
<priority>MAJOR</priority>
<description>Variable with a short name is hard to understand what it stands for. Variable with name, but the name has number of characters less than the threshold will be emitted.</description>
</rule>
<rule>
<key>redundant conditional operator</key>
<name>Redundant conditional operator</name>
<priority>MINOR</priority>
<description>This rule detects three types of redundant conditional operators:</description>
</rule>
<rule>
<key>redundant if statement</key>
<name>Redundant if statement</name>
<priority>MINOR</priority>
<description>This rule detects unnecessary if statements.</description>
</rule>
<rule>
<key>redundant local variable</key>
<name>Redundant local variable</name>
<priority>MINOR</priority>
<description>This rule detects cases where a variable declaration immediately followed by a return of that variable.</description>
</rule>
<rule>
<key>redundant nil check</key>
<name>Redundant nil check</name>
<priority>MINOR</priority>
<description>C/C++-style null check in Objective-C like foo!=nil&&[foobar] is redundant, since sending a message to a nil object in this case simply return a false-y value.</description>
</rule>
<rule>
<key>unnecessary else statement</key>
<name>Unnecessary else statement</name>
<priority>MINOR</priority>
<description>When an if statement block ends with a return statement, or all branches in the if statement block end with return statements, then the else statement is unnecessary. The code in the else statement can be run without being in the block.</description>
</rule>
<rule>
<key>useless parentheses</key>
<name>Useless parentheses</name>
<priority>MINOR</priority>
<description>This rule detects useless parentheses.</description>
</rule>
<rule>
<key>high cyclomatic complexity</key>
<name>Cyclomatic complexity</name>
<priority>CRITICAL</priority>
<description>Cyclomatic complexity is determined by the number of linearly independent paths through a program’s source code. In other words, cyclomatic complexity of a method is measured by the number of decision points, like if, while, and for statements, plus one for the method entry.</description>
</rule>
<rule>
<key>long class</key>
<name>Long class</name>
<priority>MAJOR</priority>
<description>Long class generally indicates that this class tries to so many things. Each class should do one thing and one thing well.</description>
</rule>
<rule>
<key>long line</key>
<name>Long line</name>
<priority>MINOR</priority>
<description>When number of characters for one line of code is very long, it largely harm the readability. Break long line of code into multiple lines.</description>
</rule>
<rule>
<key>long method</key>
<name>Long method</name>
<priority>MAJOR</priority>
<description>Long method generally indicates that this method tries to so many things. Each method should do one thing and one thing well.</description>
</rule>
<rule>
<key>high ncss method</key>
<name>Ncss method count</name>
<priority>CRITICAL</priority>
<description>This rule counts number of lines for a method by counting Non Commenting Source Statements (NCSS). NCSS only takes actual statements into consideration, in other words, ignores empty statements, empty blocks, closing brackets or semicolons after closing brackets. Meanwhile, statement that is break into multiple lines contribute only one count.</description>
</rule>
<rule>
<key>deep nested block</key>
<name>Nested block depth</name>
<priority>CRITICAL</priority>
<description>This rule indicates blocks nested more deeply than the upper limit.</description>
</rule>
<rule>
<key>high npath complexity</key>
<name>N path complexity</name>
<priority>CRITICAL</priority>
<description>NPath complexity is determined by the number of execution paths through that method. Compared to cyclomatic complexity, NPath complexity has two outstanding characteristics: first, it distinguish between different kinds of control flow structures; second, it takes the various type of acyclic paths in a flow graph into consideration.</description>
</rule>
<rule>
<key>too many fields</key>
<name>Too many fields</name>
<priority>CRITICAL</priority>
<description>A class with too many fields indicates it does too many things and is lack of proper abstraction. It can be resigned to have fewer fields.</description>
</rule>
<rule>
<key>too many methods</key>
<name>Too many methods</name>
<priority>CRITICAL</priority>
<description>A class with too many methods indicates it does too many things and hard to read and understand. It usually contains complicated code, and should be refactored.</description>
</rule>
<rule>
<key>too many parameters</key>
<name>Too many parameters</name>
<priority>CRITICAL</priority>
<description>Methods with too many parameters are hard to understand and maintain, and are thirsty for refactorings, like Replace Parameter With method, Introduce Parameter Object, or Preserve Whole Object.</description>
</rule>
<rule>
<key>unused local variable</key>
<name>Unused local variable</name>
<priority>INFO</priority>
<description>This rule detects local variables that are declared, but not used.</description>
</rule>
<rule>
<key>unused method parameter</key>
<name>Unused method parameter</name>
<priority>INFO</priority>
<description>This rule detects parameters that are not used in the method.</description>
</rule>
<rule>
<key>feature envy</key>
<name>Feature envy</name>
<priority>CRITICAL</priority>
<description>Feature envy</description>
</rule>
<rule>
<key>ivar assignment outside accessors or init</key>
<name>Ivar assignment outside accessors or init</name>
<priority>MAJOR</priority>
<description>Ivar assignment outside accessors or init</description>
</rule>
<rule>
<key>jumbled incrementer</key>
<name>Jumbled incrementer</name>
<priority>MAJOR</priority>
<description>Jumbled incrementer</description>
</rule>
<rule>
<key>missing break in switch statement</key>
<name>Missing break in switch statement</name>
<priority>MAJOR</priority>
<description>Missing break in switch statement</description>
</rule>
<rule>
<key>must override hash with isEqual</key>
<name>Must override hash with isEqual</name>
<priority>MINOR</priority>
<description>Must override hash with isEqual</description>
</rule>
<rule>
<key>switch statements don't need default when fully covered</key>
<name>Switch statements don't need default when fully covered</name>
<priority>MAJOR</priority>
<description>Switch statements don't need default when fully covered</description>
</rule>
<rule>
<key>use early exits and continue</key>
<name>Use early exits and continue</name>
<priority>MAJOR</priority>
<description>Use early exits and continue</description>
</rule>
<!-- oclint0.11新增 -->
<rule>
<key>missing hash method</key>
<name>ObjC Verify Is Equal Hash</name>
<priority>INFO</priority>
<description>When ``isEqual`` method is overridden, ``hash`` method must be overridden, too.</description>
</rule>
<rule>
<key>missing call to base method</key>
<name>ObjC Verify Must Call Super</name>
<priority>INFO</priority>
<description>"When a method is declared with "
"``__attribute__((annotate(\"oclint:enforce[base method]\")))`` annotation, "
"all of its implementations (including its own and its sub classes) "
"must call the method implementation in super class."</description>
</rule>
<rule>
<key>missing abstract method implementation</key>
<name>ObjC Verify Subclass Must Implement</name>
<priority>INFO</priority>
<description>"Due to the Objective-C language tries to postpone the decision makings "
"to the runtime as much as possible, an abstract method is okay to be declared "
"but without implementations. This rule tries to verify the subclass implement "
"the correct abstract method."</description>
</rule>
<rule>
<key>calling prohibited method</key>
<name>ObjC Verify Prohibited Call</name>
<priority>INFO</priority>
<description>"When a method is declared with "
"``__attribute__((annotate(\"oclint:enforce[prohibited method]\")))`` "
"annotation, all of its usages will be prohibited."</description>
</rule>
<rule>
<key>calling protected method</key>
<name>ObjC Verify Protected Method</name>
<priority>INFO</priority>
<description>"Even though there is no ``protected`` in Objective-C language level, "
"in a design's perspective, we sometimes hope to enforce a method only be used inside "
"the class itself or by its subclass. This rule mimics the ``protected`` behavior, "
"and alerts developers when a method is called outside its access scope."</description>
</rule>
<rule>
<key>base class destructor should be virtual or protected</key>
<name>Base Class Destructor Should BeVirtual Or Protected</name>
<priority>CRITICAL</priority>
<description>Make base class destructor public and virtual, or protected and nonvirtual</description>
</rule>
<rule>
<key>destructor of virtual class</key>
<name>Destructor Of Virtual Class</name>
<priority>CRITICAL</priority>
<description>This rule enforces the destructor of a virtual class must be virtual.</description>
</rule>
<rule>
<key>prefer early exits and continue</key>
<name>Prefer Early Exit</name>
<priority>MAJOR</priority>
<description>"Early exits can reduce the indentation of a block of code, "
"so that reader do not have to remember all the previous decisions, "
"therefore, makes it easier to understand the code."</description>
</rule>
<!-- step1 -->
<rule>
<key>unnecessary default statement in covered switch statement</key>
<name>Covered Switch Statements Dont Need Default</name>
<priority>MAJOR</priority>
<description>"When a switch statement covers all possible cases, "
"a default label is not needed and should be removed. "
"If the switch is not fully covered, "
"the SwitchStatementsShouldHaveDefault rule will report."</description>
</rule>
<rule>
<key>avoid default arguments on virtual methods</key>
<name>Avoid Default Arguments On Virtual Methods</name>
<priority>MAJOR</priority>
<description>"Giving virtual functions default argument initializers tends to "
"defeat polymorphism and introduce unnecessary complexity into a class hierarchy."</description>
</rule>
<rule>
<key>avoid private static members</key>
<name>Avoid Private Static Members</name>
<priority>MAJOR</priority>
<description>Having static members is easier to harm encapsulation.</description>
</rule>
<rule>
<key>use boxed expression</key>
<name>ObjC Boxed Expressions</name>
<priority>MAJOR</priority>
<description>"This rule locates the places that can be migrated to the "
"new Objective-C literals with boxed expressions."</description>
</rule>
<!-- step2 -->
<rule>
<key>use container literal</key>
<name>ObjC Container Literals</name>
<priority>MAJOR</priority>
<description>"This rule locates the places that can be migrated to the "
"new Objective-C literals with container literals."</description>
</rule>
<rule>
<key>use number literal</key>
<name>ObjC NSNumber Literals</name>
<priority>MAJOR</priority>
<description>"This rule locates the places that can be migrated to the "
"new Objective-C literals with number literals."</description>
</rule>
<rule>
<key>use object subscripting</key>
<name>ObjC Object Subscripting</name>
<priority>MAJOR</priority>
<description>"This rule locates the places that can be migrated to the "
"new Objective-C literals with object subscripting."</description>
</rule>
<rule>
<key>unnecessary null check for dealloc</key>
<name>Unnecessary Null Check For CXX Dealloc</name>
<priority>MAJOR</priority>
<description>"``char* p = 0; delete p;`` is valid. "
"This rule locates unnecessary ``if (p)`` checks."</description>
</rule>
<rule>
<key>missing default in switch statements</key>
<name>Switch Statements Should Have Default Rule</name>
<priority>MAJOR</priority>
<description>Switch statements should have a default statement.</description>
</rule>
<rule>
<key>ill-placed default label in switch statement</key>
<name>Switch Statements Misplaced Default Label</name>
<priority>MAJOR</priority>
<description>Switch Statements Misplaced Default Label.</description>
</rule>
<!-- step3 -->
</rules>