Skip to content

Commit 60662b1

Browse files
SCANPY-164 Allow the use of kebab cases for all properties in pyproject.toml
1 parent 7289d73 commit 60662b1

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/pysonar_scanner/configuration/pyproject_toml.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ def __read_sonar_properties(toml_dict) -> Dict[str, str]:
6060
sonar_config = toml_dict["tool"]["sonar"]
6161
python_to_java_names = {prop.python_name(): prop.name for prop in properties.PROPERTIES}
6262
flattened_sonar_config = TomlConfigurationLoader.__flatten_config_dict(sonar_config, prefix="sonar.")
63-
return {python_to_java_names.get(key, key): value for key, value in flattened_sonar_config.items()}
63+
return {
64+
python_to_java_names.get(key, TomlConfigurationLoader.__kebab_to_camel_case(key)): value
65+
for key, value in flattened_sonar_config.items()
66+
}
6467
return {}
6568

6669
@staticmethod
@@ -101,3 +104,8 @@ def __convert_arrays_to_string(property) -> str:
101104
return ",".join(str(item) for item in property)
102105
else:
103106
return property
107+
108+
@staticmethod
109+
def __kebab_to_camel_case(key: str) -> str:
110+
parts = key.split("-")
111+
return parts[0] + "".join(word.capitalize() for word in parts[1:])

tests/unit/test_pyproject_toml.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ def test_load_toml_file_kebab_case(self):
6363
self.assertEqual(properties.sonar_properties.get("sonar.projectKey"), "my-project")
6464
self.assertEqual(properties.sonar_properties.get("sonar.projectName"), "My Project")
6565

66+
def test_load_toml_file_kebab_case_unknown_properties(self):
67+
self.fs.create_file(
68+
"pyproject.toml",
69+
contents="""
70+
[tool.sonar]
71+
coverage-report-paths = "coverage.xml"
72+
some-unknown-property = "some-value"
73+
nested-property.some-nested-key = "nested-value"
74+
""",
75+
)
76+
properties = TomlConfigurationLoader.load(Path("."))
77+
78+
self.assertEqual(properties.sonar_properties.get("sonar.coverageReportPaths"), "coverage.xml")
79+
self.assertEqual(properties.sonar_properties.get("sonar.someUnknownProperty"), "some-value")
80+
self.assertEqual(properties.sonar_properties.get("sonar.nestedProperty.someNestedKey"), "nested-value")
81+
6682
def test_load_toml_file_without_sonar_section(self):
6783
self.fs.create_file(
6884
"pyproject.toml",

0 commit comments

Comments
 (0)