From 6d897be3a48da2af75f5a94f87491e98b5569b46 Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Wed, 21 May 2014 10:30:32 +0200 Subject: [PATCH] SONAR-5237 - Updated searchAction sample response --- .../sonar/server/rule2/ws/example-search.json | 175 ++++++++++++++---- 1 file changed, 134 insertions(+), 41 deletions(-) diff --git a/sonar-server/src/main/resources/org/sonar/server/rule2/ws/example-search.json b/sonar-server/src/main/resources/org/sonar/server/rule2/ws/example-search.json index b627ae5b839..f9cbd2e4c6f 100644 --- a/sonar-server/src/main/resources/org/sonar/server/rule2/ws/example-search.json +++ b/sonar-server/src/main/resources/org/sonar/server/rule2/ws/example-search.json @@ -1,45 +1,138 @@ -{ - "total": 2, - "p": 1, - "ps": 25, - "rules": [ +{"total": 4, "p": 1, "ps": 3, "rules": [ { - "key": "squid:S1067", - "repo": "squid", - "name": "Expressions should not be too complex", - "htmlDesc": "

\nThe complexity of an expression is defined by the number of &&, || and condition ? ifTrue : ifFalse operators it contains.\nA single expression's complexity should not become too high to keep the code readable.\n

\n\n

The following code, with a maximum complexity of 3:

\n\n
\nif (condition1 && condition2 && condition3 && condition4) { /* ... */ } // Non-Compliant\n
\n\n

could be refactored into something like:

\n\n
\nif (relevantMethodName1() && relevantMethodName2()) { /* ... */ } // Compliant\n\n/* ... */\n\nprivate boolean relevantMethodName1() {\n return condition1 && condition2;\n}\n\nprivate boolean relevantMethodName2() {\n return condition3 && condition4;\n}\n
", - "severity": "MAJOR", - "status": "READY", - "internalKey": "S1067", - "template": false, - "tags": [ ], - "sysTags": [ - "brain-overload" - ], - "lang": "java", - "langName": "Java", - "params": [ - { - "key": "max", - "desc": "Maximum number of allowed conditional operators in an expression", - "defaultValue": "3" - } - ] + "key": "squid:S1067", + "repo": "squid", + "name": "Expressions should not be too complex", + "htmlDesc": "

\nThe complexity of an expression is defined by the number of &&, || and condition ? ifTrue : ifFalse operators it contains.\nA single expression's complexity should not become too high to keep the code readable.\n

\n\n

The following code, with a maximum complexity of 3:

\n\n
\nif (condition1 && condition2 && condition3 && condition4) { /* ... */ }  // Non-Compliant\n
\n\n

could be refactored into something like:

\n\n
\nif (relevantMethodName1() && relevantMethodName2()) { /* ... */ }        // Compliant\n\n/* ... */\n\nprivate boolean relevantMethodName1() {\n  return condition1 && condition2;\n}\n\nprivate boolean relevantMethodName2() {\n  return condition3 && condition4;\n}\n
", + "severity": "MAJOR", + "status": "READY", + "internalKey": "S1067", + "template": false, + "tags": [], + "sysTags": ["brain-overload"], + "lang": "java", + "langName": "Java", + "params": [ + { + "key": "max", + "desc": "Maximum number of allowed conditional operators in an expression", + "defaultValue": "3" + } + ] + }, + { + "key": "squid:ClassCyclomaticComplexity", + "repo": "squid", + "name": "Avoid too complex class", + "htmlDesc": "

The Cyclomatic Complexity is measured by the number of (&&, ||)\n\toperators and (if, while, do, for, ?:, catch, switch, case, return,\n\tthrow) statements in the body of a class plus one for each constructor,\n\tmethod (but not getter/setter), static initializer, or instance\n\tinitializer in the class. The last return stament in method, if exists,\n\tis not taken into account.

\n

\n\tEven when the Cyclomatic Complexity of a class is very high, this\n\tcomplexity might be well distributed among all methods. Nevertheless,\n\tmost of the time, a very complex class is a class which breaks the Single\n\t\tResponsibility Principle and which should be re-factored to be split\n\tin several classes.\n

", + "severity": "MAJOR", + "status": "READY", + "internalKey": "ClassCyclomaticComplexity", + "template": false, + "tags": [], + "sysTags": ["brain-overload"], + "lang": "java", + "langName": "Java", + "params": [ + { + "key": "max", + "desc": "Maximum complexity allowed.", + "defaultValue": "200" + } + ] }, { - "key": "squid:S1168", - "repo": "squid", - "name": "Empty arrays and collections should be returned instead of null", - "htmlDesc": "

\nReturning null instead of an actual array or collection forces callers of the method to explicitly test for nullity, making them more complex and less readable.\nMoreover, in many cases, null is used as a synonym for empty.\n

\n\n

The following code:

\n\n
\npublic static Result[] getResults() {\n return null; // Non-Compliant\n}\n\npublic static void main(String[] args) {\n Result[] results = getResults();\n\n if (results != null) { // Nullity test required to prevent NPE\n for (Result result: results) {\n /* ... */\n }\n }\n}\n
\n\n

should be refactored into:

\n\n
\npublic static Result[] getResults() {\n return new Result[0]; // Compliant\n}\n\npublic static void main(String[] args) {\n for (Result result: getResults()) {\n /* ... */\n }\n}\n
\n\n

This rule also applies to collections:

\n\n
\npublic static List<Result> getResults() {\n return null; // Non-Compliant\n}\n
\n\n

should be refactored into:

\n\n
\npublic static List<Result> getResults() {\n return Collections.emptyList(); // Compliant\n}\n
", - "severity": "MAJOR", - "status": "READY", - "internalKey": "S1168", - "template": false, - "tags": [ ], - "sysTags": [ ], - "lang": "java", - "langName": "Java", - "params": [ ] + "key": "squid:MethodCyclomaticComplexity", + "repo": "squid", + "name": "Methods should not be too complex", + "htmlDesc": "

The Cyclomatic Complexity is measured by the number of\n\t(&&, ||) operators and (if, while, do, for, ?:, catch, switch,\n\tcase, return, throw) statements in the body of a class plus one for\n\teach constructor, method (but not getter/setter), static initializer,\n\tor instance initializer in the class. The last return stament in\n\tmethod, if exists, is not taken into account.

\n

\n\tEven when the Cyclomatic Complexity of a class is very high, this\n\tcomplexity might be well distributed among all methods. Nevertheless,\n\tmost of the time, a very complex class is a class which breaks the Single\n\t\tResponsibility Principle and which should be re-factored to be split\n\tin several classes.\n

", + "severity": "MAJOR", + "status": "READY", + "internalKey": "MethodCyclomaticComplexity", + "template": false, + "tags": [], + "sysTags": ["brain-overload"], + "lang": "java", + "langName": "Java", + "params": [ + { + "key": "max", + "desc": "Maximum complexity allowed.", + "defaultValue": "10" + } + ] } - ] -} +], "actives": { + "squid:MethodCyclomaticComplexity": [ + { + "qProfile": "Sonar way with Findbugs:java", + "inherit": "NONE", + "severity": "MAJOR", + "params": [ + { + "key": "max", + "value": "10" + } + ] + }, + { + "qProfile": "Sonar way:java", + "inherit": "NONE", + "severity": "MAJOR", + "params": [ + { + "key": "max", + "value": "10" + } + ] + } + ], + "squid:S1067": [ + { + "qProfile": "Sonar way with Findbugs:java", + "inherit": "NONE", + "severity": "MAJOR", + "params": [ + { + "key": "max", + "value": "3" + } + ] + }, + { + "qProfile": "Sonar way:java", + "inherit": "NONE", + "severity": "MAJOR", + "params": [ + { + "key": "max", + "value": "3" + } + ] + } + ], + "squid:ClassCyclomaticComplexity": [ + { + "qProfile": "Sonar way with Findbugs:java", + "inherit": "NONE", + "severity": "MAJOR", + "params": [ + { + "key": "max", + "value": "200" + } + ] + }, + { + "qProfile": "Sonar way:java", + "inherit": "NONE", + "severity": "MAJOR", + "params": [ + { + "key": "max", + "value": "200" + } + ] + } + ] +}} \ No newline at end of file -- 2.39.5