Skip to content

Commit af66d93

Browse files
SCANPY-164 Allow the use of kebab cases for all properties in pyproject.toml (#181)
1 parent db5fb86 commit af66d93

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/pysonar_scanner/configuration/pyproject_toml.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ def __read_sonar_properties(toml_dict) -> Dict[str, str]:
6363
sonar_config = toml_dict["tool"]["sonar"]
6464
python_to_java_names = {prop.python_name(): prop.name for prop in properties.PROPERTIES}
6565
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+
}
6770
return {}
6871

6972
@staticmethod
@@ -104,3 +107,12 @@ def __convert_arrays_to_string(property) -> str:
104107
return ",".join(str(item) for item in property)
105108
else:
106109
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

tests/unit/test_pyproject_toml.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,33 @@ def test_load_toml_file_kebab_case(self):
6565
self.assertEqual(properties.sonar_properties.get("sonar.projectKey"), "my-project")
6666
self.assertEqual(properties.sonar_properties.get("sonar.projectName"), "My Project")
6767

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+
6895
def test_load_toml_file_without_sonar_section(self):
6996
self.fs.create_file(
7097
"pyproject.toml",

0 commit comments

Comments
 (0)