Modify rule S3776: LaYC format (#2215)
This commit is contained in:
parent
f7f5c521b6
commit
c6e12bbf8d
@ -1,4 +1,6 @@
|
|||||||
include::../rule.adoc[]
|
include::../why.adoc[]
|
||||||
|
include::../resources.adoc[]
|
||||||
|
|
||||||
ifdef::env-github,rspecator-view[]
|
ifdef::env-github,rspecator-view[]
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
@ -1,14 +1,3 @@
|
|||||||
include::../rule.adoc[]
|
include::../why.adoc[]
|
||||||
ifdef::env-github,rspecator-view[]
|
include::../resources.adoc[]
|
||||||
|
include::../rspecator.adoc[]
|
||||||
'''
|
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
include::../message.adoc[]
|
|
||||||
|
|
||||||
include::../parameters.adoc[]
|
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
include::../rule.adoc[]
|
include::../why.adoc[]
|
||||||
|
include::../resources.adoc[]
|
||||||
|
|
||||||
ifdef::env-github,rspecator-view[]
|
ifdef::env-github,rspecator-view[]
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
@ -3,5 +3,6 @@
|
|||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant\/Issue",
|
"func": "Constant\/Issue",
|
||||||
"constantCost": "10min"
|
"constantCost": "10min"
|
||||||
}
|
},
|
||||||
|
"quickfix": "infeasible"
|
||||||
}
|
}
|
||||||
|
@ -1,44 +1,51 @@
|
|||||||
== Why is this an issue?
|
== Why is this an issue?
|
||||||
|
|
||||||
Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.
|
https://www.sonarsource.com/docs/CognitiveComplexity.pdf[Cognitive Complexity] Complexity is a measure of how hard the control flow of a method is to understand.
|
||||||
|
|
||||||
include::../see.adoc[]
|
Methods with high Cognitive Complexity will be difficult to maintain.
|
||||||
ifdef::env-github,rspecator-view[]
|
|
||||||
|
|
||||||
'''
|
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
=== Message
|
|
||||||
|
|
||||||
Refactor this {0} to reduce its Cognitive Complexity from {1} to the {2} allowed.
|
|
||||||
|
|
||||||
|
|
||||||
Where {0} is the name of the syntax being analyzed, {1} the cognitive complexity and {2} the maximum authorized complexity.
|
|
||||||
|
|
||||||
|
|
||||||
=== Parameters
|
|
||||||
|
|
||||||
.threshold
|
|
||||||
****
|
|
||||||
|
|
||||||
|
[source,csharp,diff-id=1,diff-type=noncompliant]
|
||||||
----
|
----
|
||||||
15
|
int Abs(int n) // Noncompliant: cognitive complexity = 5
|
||||||
|
{
|
||||||
|
if (n >= 0) // +1
|
||||||
|
{
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
else // +2, due to nesting
|
||||||
|
{
|
||||||
|
if (n == int.MinValue) // +1
|
||||||
|
{
|
||||||
|
throw new ArgumentException("The absolute value of int.MinValue is outside of int boundaries");
|
||||||
|
}
|
||||||
|
else // +1
|
||||||
|
{
|
||||||
|
return -n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
The maximum authorized complexity.
|
They should be refactored to have lower complexity:
|
||||||
****
|
|
||||||
.propertyThreshold
|
|
||||||
****
|
|
||||||
|
|
||||||
|
[source,csharp,diff-id=1,diff-type=compliant]
|
||||||
----
|
----
|
||||||
3
|
int Abs(int n) // Compliant: cognitive complexity = 3
|
||||||
|
{
|
||||||
|
if (n == int.MinValue) // +1
|
||||||
|
{
|
||||||
|
throw new ArgumentException("The absolute value of int.MinValue is outside of int boundaries");
|
||||||
|
}
|
||||||
|
else if (n >= 0) // +1
|
||||||
|
{
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
else // +1
|
||||||
|
{
|
||||||
|
return -n;
|
||||||
|
}
|
||||||
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
The maximum authorized complexity in a property.
|
include::../resources.adoc[]
|
||||||
****
|
include::../rspecator-dotnet.adoc[]
|
||||||
|
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
|
@ -1,14 +1,3 @@
|
|||||||
include::../rule.adoc[]
|
include::../why.adoc[]
|
||||||
ifdef::env-github,rspecator-view[]
|
include::../resources.adoc[]
|
||||||
|
include::../rspecator.adoc[]
|
||||||
'''
|
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
include::../message.adoc[]
|
|
||||||
|
|
||||||
include::../parameters.adoc[]
|
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
|
@ -4,19 +4,7 @@ Cognitive Complexity is a measure of how hard the control flow of a method is to
|
|||||||
|
|
||||||
=== Exceptions
|
=== Exceptions
|
||||||
|
|
||||||
``++equals++`` and ``++hashCode++`` methods are ignored because they might be automatically generated and might end up being difficult to understand, especially in presence of many fields.
|
`equals` and `hashCode` methods are ignored because they might be automatically generated and might end up being difficult to understand, especially in the presence of many fields.
|
||||||
|
|
||||||
include::../see.adoc[]
|
include::../resources.adoc[]
|
||||||
ifdef::env-github,rspecator-view[]
|
include::../rspecator.adoc[]
|
||||||
|
|
||||||
'''
|
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
include::../message.adoc[]
|
|
||||||
|
|
||||||
include::../parameters.adoc[]
|
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
|
||||||
|
@ -1,14 +1,3 @@
|
|||||||
include::../rule.adoc[]
|
include::../why.adoc[]
|
||||||
ifdef::env-github,rspecator-view[]
|
include::../resources.adoc[]
|
||||||
|
include::../rspecator.adoc[]
|
||||||
'''
|
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
include::../message.adoc[]
|
|
||||||
|
|
||||||
include::../parameters.adoc[]
|
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
|
@ -1,14 +1,3 @@
|
|||||||
include::../rule.adoc[]
|
include::../why.adoc[]
|
||||||
ifdef::env-github,rspecator-view[]
|
include::../resources.adoc[]
|
||||||
|
include::../rspecator.adoc[]
|
||||||
'''
|
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
include::../message.adoc[]
|
|
||||||
|
|
||||||
include::../parameters.adoc[]
|
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
|
@ -1,14 +1,3 @@
|
|||||||
include::../rule.adoc[]
|
include::../why.adoc[]
|
||||||
ifdef::env-github,rspecator-view[]
|
include::../resources.adoc[]
|
||||||
|
include::../rspecator.adoc[]
|
||||||
'''
|
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
include::../message.adoc[]
|
|
||||||
|
|
||||||
include::../parameters.adoc[]
|
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
|
@ -1,14 +1,3 @@
|
|||||||
include::../rule.adoc[]
|
include::../why.adoc[]
|
||||||
ifdef::env-github,rspecator-view[]
|
include::../resources.adoc[]
|
||||||
|
include::../rspecator.adoc[]
|
||||||
'''
|
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
include::../message.adoc[]
|
|
||||||
|
|
||||||
include::../parameters.adoc[]
|
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
|
@ -1,3 +1,6 @@
|
|||||||
== Resources
|
== Resources
|
||||||
|
|
||||||
* https://www.sonarsource.com/docs/CognitiveComplexity.pdf[Cognitive Complexity]
|
=== Documentation
|
||||||
|
|
||||||
|
* https://www.sonarsource.com/docs/CognitiveComplexity.pdf[Cognitive Complexity]
|
||||||
|
|
36
rules/S3776/rspecator-dotnet.adoc
Normal file
36
rules/S3776/rspecator-dotnet.adoc
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
ifdef::env-github,rspecator-view[]
|
||||||
|
|
||||||
|
'''
|
||||||
|
== Implementation Specification
|
||||||
|
(visible only on this page)
|
||||||
|
|
||||||
|
=== Message
|
||||||
|
|
||||||
|
Refactor this {0} to reduce its Cognitive Complexity from {1} to the {2} allowed.
|
||||||
|
|
||||||
|
Where {0} is the name of the syntax being analyzed, {1} is the cognitive complexity and {2} is the maximum authorized complexity.
|
||||||
|
|
||||||
|
=== Parameters
|
||||||
|
|
||||||
|
.threshold
|
||||||
|
****
|
||||||
|
|
||||||
|
----
|
||||||
|
15
|
||||||
|
----
|
||||||
|
|
||||||
|
The maximum authorized complexity.
|
||||||
|
****
|
||||||
|
.propertyThreshold
|
||||||
|
****
|
||||||
|
|
||||||
|
----
|
||||||
|
3
|
||||||
|
----
|
||||||
|
|
||||||
|
The maximum authorized complexity in a property.
|
||||||
|
****
|
||||||
|
|
||||||
|
include::highlighting.adoc[]
|
||||||
|
|
||||||
|
endif::env-github,rspecator-view[]
|
13
rules/S3776/rspecator.adoc
Normal file
13
rules/S3776/rspecator.adoc
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
ifdef::env-github,rspecator-view[]
|
||||||
|
|
||||||
|
'''
|
||||||
|
== Implementation Specification
|
||||||
|
(visible only on this page)
|
||||||
|
|
||||||
|
include::message.adoc[]
|
||||||
|
|
||||||
|
include::parameters.adoc[]
|
||||||
|
|
||||||
|
include::highlighting.adoc[]
|
||||||
|
|
||||||
|
endif::env-github,rspecator-view[]
|
@ -1,14 +1,3 @@
|
|||||||
include::../rule.adoc[]
|
include::../why.adoc[]
|
||||||
ifdef::env-github,rspecator-view[]
|
include::../resources.adoc[]
|
||||||
|
include::../rspecator.adoc[]
|
||||||
'''
|
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
include::../message.adoc[]
|
|
||||||
|
|
||||||
include::../parameters.adoc[]
|
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
|
@ -1,6 +0,0 @@
|
|||||||
== Why is this an issue?
|
|
||||||
|
|
||||||
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
|
|
||||||
|
|
||||||
|
|
||||||
include::see.adoc[]
|
|
@ -1,14 +1,3 @@
|
|||||||
include::../rule.adoc[]
|
include::../why.adoc[]
|
||||||
ifdef::env-github,rspecator-view[]
|
include::../resources.adoc[]
|
||||||
|
include::../rspecator.adoc[]
|
||||||
'''
|
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
include::../message.adoc[]
|
|
||||||
|
|
||||||
include::../parameters.adoc[]
|
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
|
@ -1,14 +1,3 @@
|
|||||||
include::../rule.adoc[]
|
include::../why.adoc[]
|
||||||
ifdef::env-github,rspecator-view[]
|
include::../resources.adoc[]
|
||||||
|
include::../rspecator.adoc[]
|
||||||
'''
|
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
include::../message.adoc[]
|
|
||||||
|
|
||||||
include::../parameters.adoc[]
|
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
|
@ -1,3 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
"title": "Cognitive Complexity of methods should not be too high",
|
||||||
|
"remediation": {
|
||||||
|
"func": "Constant\/Issue",
|
||||||
|
"constantCost": "10min"
|
||||||
|
},
|
||||||
|
"quickfix": "infeasible"
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,38 @@
|
|||||||
include::../rule.adoc[]
|
== Why is this an issue?
|
||||||
ifdef::env-github,rspecator-view[]
|
|
||||||
|
|
||||||
'''
|
https://www.sonarsource.com/docs/CognitiveComplexity.pdf[Cognitive Complexity] Complexity is a measure of how hard the control flow of a method is to understand.
|
||||||
== Implementation Specification
|
|
||||||
(visible only on this page)
|
|
||||||
|
|
||||||
include::../message.adoc[]
|
Methods with high Cognitive Complexity will be difficult to maintain.
|
||||||
|
|
||||||
include::../parameters.adoc[]
|
[source,vbnet,diff-id=1,diff-type=noncompliant]
|
||||||
|
----
|
||||||
|
Function Abs(ByVal n As Integer) As Integer ' Noncompliant: cognitive complexity = 5
|
||||||
|
If n >= 0 Then ' +1
|
||||||
|
Return n
|
||||||
|
Else ' +2, due to nesting
|
||||||
|
If n = Integer.MinValue Then ' +1
|
||||||
|
Throw New ArgumentException("The absolute value of int.MinValue is outside of int boundaries")
|
||||||
|
Else ' +1
|
||||||
|
Return -n
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
End Function
|
||||||
|
----
|
||||||
|
|
||||||
include::../highlighting.adoc[]
|
They should be refactored to have lower complexity:
|
||||||
|
|
||||||
endif::env-github,rspecator-view[]
|
[source,vbnet,diff-id=1,diff-type=compliant]
|
||||||
|
----
|
||||||
|
Function Abs(ByVal n As Integer) As Integer ' Compliant: cognitive complexity = 3
|
||||||
|
If n = Integer.MinValue Then ' +1
|
||||||
|
Throw New ArgumentException("The absolute value of int.MinValue is outside of int boundaries")
|
||||||
|
Else If n >= 0 Then ' +1
|
||||||
|
Return n
|
||||||
|
Else ' +1
|
||||||
|
Return -n
|
||||||
|
End If
|
||||||
|
End Function
|
||||||
|
----
|
||||||
|
|
||||||
|
include::../resources.adoc[]
|
||||||
|
include::../rspecator-dotnet.adoc[]
|
3
rules/S3776/why.adoc
Normal file
3
rules/S3776/why.adoc
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
== Why is this an issue?
|
||||||
|
|
||||||
|
https://www.sonarsource.com/docs/CognitiveComplexity.pdf[Cognitive Complexity] Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
|
@ -19,7 +19,6 @@ public class Rectangle {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
{outro}
|
{outro}
|
||||||
|
|
||||||
[source,java,diff-id=1,diff-type=compliant]
|
[source,java,diff-id=1,diff-type=compliant]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user