Skip to content

Commit a8a8095

Browse files
SCANPY-164 Allow the use of kebab cases for all properties in pyproject.toml
1 parent 12f7bd0 commit a8a8095

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
@@ -62,7 +62,10 @@ def __read_sonar_properties(toml_dict) -> Dict[str, str]:
6262
python_name: prop.name for prop in properties.PROPERTIES for python_name in prop.python_names()
6363
}
6464
flattened_sonar_config = TomlConfigurationLoader.__flatten_config_dict(sonar_config, prefix="sonar.")
65-
return {python_to_java_names.get(key, key): value for key, value in flattened_sonar_config.items()}
65+
return {
66+
python_to_java_names.get(key, TomlConfigurationLoader.__kebab_to_camel_case(key)): value
67+
for key, value in flattened_sonar_config.items()
68+
}
6669
return {}
6770

6871
@staticmethod
@@ -103,3 +106,8 @@ def __convert_arrays_to_string(property) -> str:
103106
return ",".join(str(item) for item in property)
104107
else:
105108
return property
109+
110+
@staticmethod
111+
def __kebab_to_camel_case(key: str) -> str:
112+
parts = key.split("-")
113+
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
@@ -72,6 +72,22 @@ def test_load_toml_file_kebab_case(self):
7272
self.assertEqual(properties.sonar_properties.get("sonar.projectKey"), "my-project")
7373
self.assertEqual(properties.sonar_properties.get("sonar.projectName"), "My Project")
7474

75+
def test_load_toml_file_kebab_case_unknown_properties(self):
76+
self.fs.create_file(
77+
"pyproject.toml",
78+
contents="""
79+
[tool.sonar]
80+
coverage-report-paths = "coverage.xml"
81+
some-unknown-property = "some-value"
82+
nested-property.some-nested-key = "nested-value"
83+
""",
84+
)
85+
properties = TomlConfigurationLoader.load(Path("."))
86+
87+
self.assertEqual(properties.sonar_properties.get("sonar.coverageReportPaths"), "coverage.xml")
88+
self.assertEqual(properties.sonar_properties.get("sonar.someUnknownProperty"), "some-value")
89+
self.assertEqual(properties.sonar_properties.get("sonar.nestedProperty.someNestedKey"), "nested-value")
90+
7591
def test_load_toml_file_without_sonar_section(self):
7692
self.fs.create_file(
7793
"pyproject.toml",

0 commit comments

Comments
 (0)