Author:admin

Date:2014-06-12T22:36:54.000000Z


git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@1380 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
jfiat
2014-06-17 12:58:13 +00:00
parent f77c35d8ea
commit 1da2dd1bf7
11 changed files with 439 additions and 6 deletions

View File

@@ -0,0 +1,61 @@
[[Property:title|CA013 - Exported creation procedure]]
[[Property:link_title|CA013]]
[[Property:weight|0]]
[[Property:uuid|26455914-3b04-cacc-67bb-cd8e083ce947]]
__NOTOC__
=Description=
If acreation procedure is exported then it may be called by clients after the object has been created. Usually, this is not intended. A client might, for example, by accident call <e>x.make</e> instead of <e>create x.make</e>, possibly causing a class invariant or postcondition to not hold anymore.
:{| class="doctable"
|-
| '''Scope'''
| class
|-
| '''Status'''
| Enabled
|-
| '''Severity'''
| Warning
|-
| '''Applicability'''
| All
|-
| '''Score'''
| 50
|}
=Example of violation=
<e>class TEST
create
make
feature -- Initialization
make
-- Initialize Current
do
end
update
do
end
end
</e>
=Recommendation=
Make sure to export the creation procedure to NONE.
In the example, add the export to NONE after the feature clause:
<e>class TEST
create
make
feature {NONE} -- Initialization
make
-- Initialize Current
do
end
feature -- Initialization
update
do
end
end
</e>

View File

@@ -0,0 +1,40 @@
[[Property:title|CA017 - Empty conditional]]
[[Property:link_title|CA017]]
[[Property:weight|0]]
[[Property:uuid|4616cef3-6eaf-1ab6-6071-d629443dfbf0]]
__NOTOC__
=Description=
An empty conditional instruction is useless and should be removed.
:{| class="doctable"
|-
| '''Scope'''
| Instruction
|-
| '''Status'''
| Enabled
|-
| '''Severity'''
| Warning
|-
| '''Applicability'''
| All
|-
| '''Score'''
| 50
|}
=Example of violation=
<e>if x and y then
end
do_something_else
</e>
=Recommendation=
Remove the useless conditional.
In the example, simply keep:
<e>
do_something_else</e>

View File

@@ -0,0 +1,54 @@
[[Property:title|CA020 - Variable not read after assignment]]
[[Property:link_title|CA020]]
[[Property:weight|0]]
[[Property:uuid|8de22b33-be9c-b946-ce39-709cf42f01c5]]
__NOTOC__
=Description=
An assignment to a local variable has not effect at all if the variable is not read after the assignment, or reassigned.
{| class="doctable"
|-
| '''Scope'''
| Instruction
|-
| '''Status'''
| Enabled
|-
| '''Severity'''
| Warning
|-
| '''Applicability'''
| All
|-
| '''Score'''
| 70
|}
=Example of violation=
<e>
local
x, y: INTEGER
do
x := 3
y := some_height_query
x := some_width_query
...
end
</e>
=Recommendation=
Remove the assignment without effect.
In the example, remove the first assignment to <e>x</e>:
<e>
local
x, y: INTEGER
do
y := some_height_query
x := some_width_query
...
end
</e>
{{SeeAlso | [[CA071 - Self-comparison]]}}

View File

@@ -0,0 +1,43 @@
[[Property:title|CA023 - Unneeded parentheses]]
[[Property:link_title|CA023]]
[[Property:weight|0]]
[[Property:uuid|9af7b35f-7e74-2bd1-8680-b59ab81d6791]]
__NOTOC__
=Description=
Parentheses that are not needed should be removed. This helps enforcing a consistent coding style
:{| class="doctable"
|-
| '''Scope'''
| Instruction
|-
| '''Status'''
| Enabled
|-
| '''Severity'''
| Suggestion
|-
| '''Applicability'''
| All
|-
| '''Score'''
| 30
|}
=Example of violation=
<e>if (z > 3) then
z := (z - 5)
end
</e>
=Recommendation=
Remove the parenthesis that are not needed.
In the example, it simply becomes:
<e>if z > 3 then
z := z - 5
end
</e>

View File

@@ -0,0 +1,45 @@
[[Property:title|CA024 - Use across loop]]
[[Property:link_title|CA024]]
[[Property:weight|0]]
[[Property:uuid|d24ebe87-3a57-105e-7900-e77608cac47c]]
__NOTOC__
=Description=
When iterating on an instance of <e>ITERABLE</e> with a traditional <e>from ... until ... loop ...end</e> from beginning to end you should use an across loop to avoid forgetting to advance the cursor.
:{| class="doctable"
|-
| '''Scope'''
| Instruction
|-
| '''Status'''
| Enabled
|-
| '''Severity'''
| Suggestion
|-
| '''Applicability'''
| All
|-
| '''Score'''
| 30
|}
=Example of violation=
<e>from
list.start
until
list.after
loop
...
list.forth
end
</e>
=Recommendation=
Replace with an across loop. In the example it becomes:
<e>across list as l loop
...
end
</e>

View File

@@ -0,0 +1,40 @@
[[Property:title|CA025 - Use semicolons]]
[[Property:link_title|CA025]]
[[Property:weight|0]]
[[Property:uuid|41ec250b-3967-797e-9843-59eab795f391]]
__NOTOC__
=Description=
Routine arguments should be separated with semicolons. Although this is optional, it is not a recommended style to not put semicolons.
:{| class="doctable"
|-
| '''Scope'''
| feature
|-
| '''Status'''
| Enabled
|-
| '''Severity'''
| Suggestion
|-
| '''Applicability'''
| All
|-
| '''Score'''
| 40
|}
=Example of violation=
<e>f (a: INTEGER b: INTEGER)
do
end
</e>
=Recommendation=
Add the missing semicolons between arguments. In the example, it becomes:
<e>f (a: INTEGER; b: INTEGER)
do
end
</e>

View File

@@ -0,0 +1,39 @@
[[Property:title|CA028 - Combine two if instructions]]
[[Property:link_title|CA028]]
[[Property:weight|0]]
[[Property:uuid|47b9a80f-16d7-82c7-7d23-19f740fb2978]]
__NOTOC__
=Description=
Two nested instructions, both not having an else clause, could be combined into a single if instruction using the <e>and then</e> boolean operator.
:{| class="doctable"
|-
| '''Scope'''
| Instruction
|-
| '''Status'''
| Enabled
|-
| '''Severity'''
| Suggestion
|-
| '''Applicability'''
| All
|-
| '''Score'''
| 40
|}
=Example of violation=
<e>if user /= Void then
if user.age >= 18 then
...
end
end
</e>
=Recommendation=
Combine the nested if instructions using <e>and then</e>. In the example, it becomes:
<e>if user /= Void and then user.age >= 18 then
...
end</e>

View File

@@ -0,0 +1,35 @@
[[Property:title|CA032 - Long routine implementation]]
[[Property:link_title|CA032]]
[[Property:weight|0]]
[[Property:uuid|9edb21ce-ab0c-69ea-c494-a39dc7a26b15]]
__NOTOC__
=Description=
A routine implementation that contains many instructions should be shortened to make it easier to understand.
:{| class="doctable"
|-
| '''Scope'''
| feature
|-
| '''Status'''
| Enabled
|-
| '''Severity'''
| Warning
|-
| '''Applicability'''
| All
|-
| '''Score'''
| 70
|-
| '''Instructions threshold'''
| 70
|}
=Example of violation=
A routine with many lines of code.
=Recommendation=
Decompose the routine by creating new routines that will be used in the original long routine.

View File

@@ -0,0 +1,39 @@
[[Property:title|CA033 - Large class]]
[[Property:link_title|CA033]]
[[Property:weight|0]]
[[Property:uuid|93aaff4c-3406-311e-3760-facad969131e]]
__NOTOC__
=Description=
A large class declaration might not be ideal for readability. Consider moving out features that are not really part of the class.
:{| class="doctable"
|-
| '''Scope'''
| class
|-
| '''Status'''
| Enabled
|-
| '''Severity'''
| Warning
|-
| '''Applicability'''
| All
|-
| '''Score'''
| 60
|-
| '''Features threshold'''
| 20
|-
| '''Instructions threshold'''
| 300
|}
=Example of violation=
A class with too many routines or too many instructions.
=Recommendation=
Refactor the class to reduce the number of routines or instructions.

View File

@@ -0,0 +1,35 @@
[[Property:title|CA034 - High NPATH complexity]]
[[Property:link_title|CA034]]
[[Property:weight|0]]
[[Property:uuid|f6ffe1e0-2b46-66db-60de-0cdd5c42f453]]
__NOTOC__
=Description=
NPATH is the number of acyclic execution paths through a routine. A routine's NPATH complexity should not be too high. In order to reduce the NPATH complexity one can move some functionality to separate routines.
:{| class="doctable"
|-
| '''Scope'''
| Feature
|-
| '''Status'''
| Enabled
|-
| '''Severity'''
| Warning
|-
| '''Applicability'''
| All
|-
| '''Score'''
| 60
|-
| '''NPATH complexity threshold'''
| 200
|}
=Example of violation=
=Recommendation=
Reduce complexity of routine by refactoring parts of the routine into their own routines.