diff --git a/components/collector/tests/source_collectors/sonarqube/test_commented_out_code.py b/components/collector/tests/source_collectors/sonarqube/test_commented_out_code.py index e6267477b0..c33639583f 100644 --- a/components/collector/tests/source_collectors/sonarqube/test_commented_out_code.py +++ b/components/collector/tests/source_collectors/sonarqube/test_commented_out_code.py @@ -1,5 +1,7 @@ """Unit tests for the SonarQube commented-out code collector.""" +from shared_data_model import DATA_MODEL + from .base import SonarQubeTestCase @@ -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}", ) diff --git a/components/collector/tests/source_collectors/sonarqube/test_complex_units.py b/components/collector/tests/source_collectors/sonarqube/test_complex_units.py index 4105bd20e5..4e7f08094c 100644 --- a/components/collector/tests/source_collectors/sonarqube/test_complex_units.py +++ b/components/collector/tests/source_collectors/sonarqube/test_complex_units.py @@ -1,5 +1,7 @@ """Unit tests for the SonarQube complex units collector.""" +from shared_data_model import DATA_MODEL + from .base import SonarQubeTestCase @@ -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}", ) diff --git a/components/collector/tests/source_collectors/sonarqube/test_long_units.py b/components/collector/tests/source_collectors/sonarqube/test_long_units.py index 64c3b06e61..f9d197178d 100644 --- a/components/collector/tests/source_collectors/sonarqube/test_long_units.py +++ b/components/collector/tests/source_collectors/sonarqube/test_long_units.py @@ -1,5 +1,7 @@ """Unit tests for the SonarQube long units collector.""" +from shared_data_model import DATA_MODEL + from .base import SonarQubeTestCase @@ -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}", ) diff --git a/components/collector/tests/source_collectors/sonarqube/test_many_parameters.py b/components/collector/tests/source_collectors/sonarqube/test_many_parameters.py index 112c9481dc..dcae57a2da 100644 --- a/components/collector/tests/source_collectors/sonarqube/test_many_parameters.py +++ b/components/collector/tests/source_collectors/sonarqube/test_many_parameters.py @@ -1,5 +1,7 @@ """Unit tests for the SonarQube many parameters collector.""" +from shared_data_model import DATA_MODEL + from .base import SonarQubeTestCase @@ -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}", ) diff --git a/components/shared_code/src/shared_data_model/sources/sonarqube.py b/components/shared_code/src/shared_data_model/sources/sonarqube.py index 5ed781ae9b..c576768904 100644 --- a/components/shared_code/src/shared_data_model/sources/sonarqube.py +++ b/components/shared_code/src/shared_data_model/sources/sonarqube.py @@ -90,11 +90,13 @@ 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", @@ -102,10 +104,8 @@ def violation_entity_attributes( "plsql:S125", "python:S125", "scala:S125", - "java:S125", "swift:S125", "typescript:S125", - "Web:AvoidCommentedOutCodeCheck", "xml:S125", ], }, @@ -116,9 +116,11 @@ 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", @@ -126,8 +128,7 @@ def violation_entity_attributes( "python:S3776", "ruby:S3776", "scala:S3776", - "java:S1541", - "java:S3776", + "swift:S1541", "typescript:S1541", "typescript:S3776", "vbnet:S1541", @@ -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", ], @@ -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", @@ -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", @@ -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", ], }, }, diff --git a/docs/src/changelog.md b/docs/src/changelog.md index 66d34b63c5..e8542a11df 100644 --- a/docs/src/changelog.md +++ b/docs/src/changelog.md @@ -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