File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
src/pysonar_scanner/configuration Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,10 @@ def __read_sonar_properties(toml_dict) -> Dict[str, str]:
63
63
sonar_config = toml_dict ["tool" ]["sonar" ]
64
64
python_to_java_names = {prop .python_name (): prop .name for prop in properties .PROPERTIES }
65
65
flattened_sonar_config = TomlConfigurationLoader .__flatten_config_dict (sonar_config , prefix = "sonar." )
66
- return {python_to_java_names .get (key , key ): value for key , value in flattened_sonar_config .items ()}
66
+ return {
67
+ python_to_java_names .get (key , TomlConfigurationLoader .__kebab_to_camel_case (key )): value
68
+ for key , value in flattened_sonar_config .items ()
69
+ }
67
70
return {}
68
71
69
72
@staticmethod
@@ -104,3 +107,12 @@ def __convert_arrays_to_string(property) -> str:
104
107
return "," .join (str (item ) for item in property )
105
108
else :
106
109
return property
110
+
111
+ @staticmethod
112
+ def __kebab_to_camel_case (key : str ) -> str :
113
+ if "-" in key :
114
+ parts = key .split ("-" )
115
+ result = parts [0 ] + "" .join (word .capitalize () for word in parts [1 :])
116
+ logging .debug (f"Converting kebab-case property '{ key } ' to camelCase: '{ result } '" )
117
+ return result
118
+ return key
Original file line number Diff line number Diff line change @@ -65,6 +65,33 @@ def test_load_toml_file_kebab_case(self):
65
65
self .assertEqual (properties .sonar_properties .get ("sonar.projectKey" ), "my-project" )
66
66
self .assertEqual (properties .sonar_properties .get ("sonar.projectName" ), "My Project" )
67
67
68
+ @patch ("pysonar_scanner.configuration.pyproject_toml.logging" )
69
+ def test_load_toml_file_kebab_case_unknown_properties (self , mock_logging ):
70
+ self .fs .create_file (
71
+ "pyproject.toml" ,
72
+ contents = """
73
+ [tool.sonar]
74
+ coverage-report-paths = "coverage.xml"
75
+ some-unknown-property = "some-value"
76
+ nested-property.some-nested-key = "nested-value"
77
+ """ ,
78
+ )
79
+ properties = TomlConfigurationLoader .load (Path ("." ))
80
+
81
+ self .assertEqual (properties .sonar_properties .get ("sonar.coverageReportPaths" ), "coverage.xml" )
82
+ self .assertEqual (properties .sonar_properties .get ("sonar.someUnknownProperty" ), "some-value" )
83
+ self .assertEqual (properties .sonar_properties .get ("sonar.nestedProperty.someNestedKey" ), "nested-value" )
84
+
85
+ mock_logging .debug .assert_any_call (
86
+ "Converting kebab-case property 'sonar.coverage-report-paths' to camelCase: 'sonar.coverageReportPaths'"
87
+ )
88
+ mock_logging .debug .assert_any_call (
89
+ "Converting kebab-case property 'sonar.some-unknown-property' to camelCase: 'sonar.someUnknownProperty'"
90
+ )
91
+ mock_logging .debug .assert_any_call (
92
+ "Converting kebab-case property 'sonar.nested-property.some-nested-key' to camelCase: 'sonar.nestedProperty.someNestedKey'"
93
+ )
94
+
68
95
def test_load_toml_file_without_sonar_section (self ):
69
96
self .fs .create_file (
70
97
"pyproject.toml" ,
You can’t perform that action at this time.
0 commit comments