diff --git a/src/pysonar_scanner/configuration/pyproject_toml.py b/src/pysonar_scanner/configuration/pyproject_toml.py index 6da7223e..8536f8a7 100644 --- a/src/pysonar_scanner/configuration/pyproject_toml.py +++ b/src/pysonar_scanner/configuration/pyproject_toml.py @@ -64,7 +64,10 @@ def __read_sonar_properties(toml_dict) -> Dict[str, str]: sonar_config = toml_dict["tool"]["sonar"] python_to_java_names = {prop.python_name(): prop.name for prop in properties.PROPERTIES} flattened_sonar_config = TomlConfigurationLoader.__flatten_config_dict(sonar_config, prefix="sonar.") - return {python_to_java_names.get(key, key): value for key, value in flattened_sonar_config.items()} + return { + python_to_java_names.get(key, TomlConfigurationLoader.__kebab_to_camel_case(key)): value + for key, value in flattened_sonar_config.items() + } return {} @staticmethod @@ -105,3 +108,12 @@ def __convert_arrays_to_string(property) -> str: return ",".join(str(item) for item in property) else: return property + + @staticmethod + def __kebab_to_camel_case(key: str) -> str: + if "-" in key: + parts = key.split("-") + result = parts[0] + "".join(word.capitalize() for word in parts[1:]) + logging.debug(f"Converting kebab-case property '{key}' to camelCase: '{result}'") + return result + return key diff --git a/tests/unit/test_pyproject_toml.py b/tests/unit/test_pyproject_toml.py index f56ee967..6eab4f7a 100644 --- a/tests/unit/test_pyproject_toml.py +++ b/tests/unit/test_pyproject_toml.py @@ -65,6 +65,33 @@ def test_load_toml_file_kebab_case(self): self.assertEqual(properties.sonar_properties.get("sonar.projectKey"), "my-project") self.assertEqual(properties.sonar_properties.get("sonar.projectName"), "My Project") + @patch("pysonar_scanner.configuration.pyproject_toml.logging") + def test_load_toml_file_kebab_case_unknown_properties(self, mock_logging): + self.fs.create_file( + "pyproject.toml", + contents=""" + [tool.sonar] + coverage-report-paths = "coverage.xml" + some-unknown-property = "some-value" + nested-property.some-nested-key = "nested-value" + """, + ) + properties = TomlConfigurationLoader.load(Path(".")) + + self.assertEqual(properties.sonar_properties.get("sonar.coverageReportPaths"), "coverage.xml") + self.assertEqual(properties.sonar_properties.get("sonar.someUnknownProperty"), "some-value") + self.assertEqual(properties.sonar_properties.get("sonar.nestedProperty.someNestedKey"), "nested-value") + + mock_logging.debug.assert_any_call( + "Converting kebab-case property 'sonar.coverage-report-paths' to camelCase: 'sonar.coverageReportPaths'" + ) + mock_logging.debug.assert_any_call( + "Converting kebab-case property 'sonar.some-unknown-property' to camelCase: 'sonar.someUnknownProperty'" + ) + mock_logging.debug.assert_any_call( + "Converting kebab-case property 'sonar.nested-property.some-nested-key' to camelCase: 'sonar.nestedProperty.someNestedKey'" + ) + def test_load_toml_file_without_sonar_section(self): self.fs.create_file( "pyproject.toml",