Skip to content

Commit

Permalink
Extend Quality-Time with SonarQube Swift rules for complex units, met…
Browse files Browse the repository at this point in the history
…hods with too many lines and functions with too many parameters (#6493)
  • Loading branch information
denniebouman authored and fniessink committed Jul 5, 2023
1 parent 3f5f74f commit 6290155
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Unit tests for the SonarQube commented-out code collector."""

from shared_data_model import DATA_MODEL

from .base import SonarQubeTestCase


Expand All @@ -12,12 +14,10 @@ async def test_commented_out_code(self):
"""Test that the number of lines with commented out code is returned."""
json = {"total": "2"}
response = await self.collect(get_request_json_return_value=json)
expected_rules = ",".join(sorted(DATA_MODEL.sources["sonarqube"].configuration["commented_out_rules"].value))
self.assert_measurement(
response,
value="2",
total="100",
landing_url=f"{self.issues_landing_url}&rules=abap:S125,c:CommentedCode,cpp:CommentedCode,"
"flex:CommentedCode,csharpsquid:S125,javascript:S125,kotlin:S125,"
"objc:CommentedCode,php:S125,plsql:S125,python:S125,scala:S125,"
"java:S125,swift:S125,typescript:S125,Web:AvoidCommentedOutCodeCheck,xml:S125",
landing_url=f"{self.issues_landing_url}&rules={expected_rules}",
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Unit tests for the SonarQube complex units collector."""

from shared_data_model import DATA_MODEL

from .base import SonarQubeTestCase


Expand All @@ -22,13 +24,10 @@ async def test_complex_units(self):
complex_units_json,
],
)
expected_rules = ",".join(sorted(DATA_MODEL.sources["sonarqube"].configuration["complex_unit_rules"].value))
self.assert_measurement(
response,
value="2",
total="4",
landing_url=f"{self.issues_landing_url}&rules=csharpsquid:S1541,csharpsquid:S3776,flex:FunctionComplexity,"
"javascript:S1541,javascript:S3776,go:S3776,kotlin:S3776,"
"php:S1541,php:S3776,python:FunctionComplexity,python:S3776,ruby:S3776,scala:S3776,"
"java:S1541,java:S3776,typescript:S1541,typescript:S3776,"
"vbnet:S1541,vbnet:S3776",
landing_url=f"{self.issues_landing_url}&rules={expected_rules}",
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Unit tests for the SonarQube long units collector."""

from shared_data_model import DATA_MODEL

from .base import SonarQubeTestCase


Expand All @@ -23,14 +25,10 @@ async def test_long_units(self):
long_units_json,
],
)
expected_rules = ",".join(sorted(DATA_MODEL.sources["sonarqube"].configuration["long_unit_rules"].value))
self.assert_measurement(
response,
value="2",
total="4",
landing_url=f"{self.issues_landing_url}&rules=abap:S104,c:FileLoc,cpp:FileLoc,csharpsquid:S104,"
"csharpsquid:S138,flex:S138,go:S104,go:S138,javascript:S104,javascript:S138,kotlin:S104,"
"kotlin:S138,objc:FileLoc,php:S104,php:S138,php:S2042,Pylint:R0915,python:S104,python:S138,"
"ruby:S104,ruby:S138,scala:S104,scala:S138,java:S104,java:S1188,java:S138,java:S2972,"
"swift:S104,typescript:S104,typescript:S138,vbnet:S104,vbnet:S138,Web:FileLengthCheck,"
"Web:LongJavaScriptCheck",
landing_url=f"{self.issues_landing_url}&rules={expected_rules}",
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Unit tests for the SonarQube many parameters collector."""

from shared_data_model import DATA_MODEL

from .base import SonarQubeTestCase


Expand All @@ -23,10 +25,10 @@ async def test_many_parameters(self):
many_parameters_json,
],
)
expected_rules = ",".join(sorted(DATA_MODEL.sources["sonarqube"].configuration["many_parameter_rules"].value))
self.assert_measurement(
response,
value="2",
total="4",
landing_url=f"{self.issues_landing_url}&rules=c:S107,csharpsquid:S107,csharpsquid:S2436,cpp:S107,flex:S107,"
"javascript:S107,kotlin:S107,objc:S107,php:S107,python:S107,java:S107,tsql:S107,typescript:S107",
landing_url=f"{self.issues_landing_url}&rules={expected_rules}",
)
39 changes: 21 additions & 18 deletions components/shared_code/src/shared_data_model/sources/sonarqube.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ def violation_entity_attributes(
"metrics": ["commented_out_code"],
"name": "Rules used to detect commented out code",
"value": [
"Web:AvoidCommentedOutCodeCheck",
"abap:S125",
"c:CommentedCode",
"cpp:CommentedCode",
"flex:CommentedCode",
"csharpsquid:S125",
"flex:CommentedCode",
"java:S125",
"javascript:S125",
"kotlin:S125",
"objc:CommentedCode",
"php:S125",
"plsql:S125",
"python:S125",
"scala:S125",
"java:S125",
"swift:S125",
"typescript:S125",
"Web:AvoidCommentedOutCodeCheck",
"xml:S125",
],
},
Expand All @@ -116,18 +116,19 @@ def violation_entity_attributes(
"csharpsquid:S1541",
"csharpsquid:S3776",
"flex:FunctionComplexity",
"go:S3776",
"java:S1541",
"java:S3776",
"javascript:S1541",
"javascript:S3776",
"go:S3776",
"kotlin:S3776",
"php:S1541",
"php:S3776",
"python:FunctionComplexity",
"python:S3776",
"ruby:S3776",
"scala:S3776",
"java:S1541",
"java:S3776",
"swift:S1541",
"typescript:S1541",
"typescript:S3776",
"vbnet:S1541",
Expand All @@ -139,16 +140,17 @@ def violation_entity_attributes(
"name": "Rules used to detect units with many parameters",
"value": [
"c:S107",
"cpp:S107",
"csharpsquid:S107",
"csharpsquid:S2436",
"cpp:S107",
"flex:S107",
"java:S107",
"javascript:S107",
"kotlin:S107",
"objc:S107",
"php:S107",
"python:S107",
"java:S107",
"swift:S107",
"tsql:S107",
"typescript:S107",
],
Expand All @@ -157,6 +159,9 @@ def violation_entity_attributes(
"metrics": ["long_units"],
"name": "Rules used to detect long units",
"value": [
"Pylint:R0915",
"Web:FileLengthCheck",
"Web:LongJavaScriptCheck",
"abap:S104",
"c:FileLoc",
"cpp:FileLoc",
Expand All @@ -165,6 +170,10 @@ def violation_entity_attributes(
"flex:S138",
"go:S104",
"go:S138",
"java:S104",
"java:S1188",
"java:S138",
"java:S2972",
"javascript:S104",
"javascript:S138",
"kotlin:S104",
Expand All @@ -173,39 +182,33 @@ def violation_entity_attributes(
"php:S104",
"php:S138",
"php:S2042",
"Pylint:R0915",
"python:S104",
"python:S138",
"ruby:S104",
"ruby:S138",
"scala:S104",
"scala:S138",
"java:S104",
"java:S1188",
"java:S138",
"java:S2972",
"swift:S104",
"swift:S138",
"typescript:S104",
"typescript:S138",
"vbnet:S104",
"vbnet:S138",
"Web:FileLengthCheck",
"Web:LongJavaScriptCheck",
],
},
"suppression_rules": {
"metrics": ["suppressed_violations"],
"name": "Rules used to detect suppressed violations",
"value": [
"csharpsquid:S1309",
"php:NoSonar",
"Pylint:I0011",
"Pylint:I0020",
"python:NoSonar",
"csharpsquid:S1309",
"java:NoSonar",
"java:S1309",
"java:S1310",
"java:S1315",
"php:NoSonar",
"python:NoSonar",
],
},
},
Expand Down
1 change: 1 addition & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ If your currently installed *Quality-time* version is v4.10.0 or older, please r

- When changing the status of measurement entities (violations, warnings, issues, etc.) also set the status end date. The default end dates can be changed by expanding the report title and navigating to the 'Desired reaction times' tab. For individual measurement entities, the default can be overridden by first changing the status and then changing or removing the status end date. Closes [#5099](https://github.com/ICTU/quality-time/issues/5099).
- Add support for [Cargo Audit](https://docs.rs/cargo-audit/latest/cargo_audit/), a linter for Rust Cargo.lock files for crates, as source for the 'security warnings' metric. Closes [#6347](https://github.com/ICTU/quality-time/issues/6347).
- Add SonarQube Swift rules for complex units, methods with too many lines and functions with too many parameters. Closes [#6493](https://github.com/ICTU/quality-time/issues/6493).

## v5.0.1 - 2023-06-26

Expand Down

0 comments on commit 6290155

Please sign in to comment.