diff --git a/src/codemodder/codemods/xml_transformer.py b/src/codemodder/codemods/xml_transformer.py index 5ecc6c58..11a94b7a 100644 --- a/src/codemodder/codemods/xml_transformer.py +++ b/src/codemodder/codemods/xml_transformer.py @@ -95,7 +95,7 @@ def add_change(self, line): self.changes.append( Change( lineNumber=line, - description=self.change_description, + description=self.change_description or None, findings=self.file_context.get_findings_for_location(line), ) ) diff --git a/src/codemodder/codetf.py b/src/codemodder/codetf.py index ce14cf1b..579accc4 100644 --- a/src/codemodder/codetf.py +++ b/src/codemodder/codetf.py @@ -60,6 +60,12 @@ def validate_lineNumber(self): raise ValueError("lineNumber must be greater than 0") return self + @model_validator(mode="after") + def validate_description(self): + if self.description is not None and not self.description: + raise ValueError("description must not be empty") + return self + class AIMetadata(BaseModel): provider: Optional[str] = None diff --git a/tests/test_codetf.py b/tests/test_codetf.py index 4f4bb28f..0bf7ed22 100644 --- a/tests/test_codetf.py +++ b/tests/test_codetf.py @@ -63,6 +63,15 @@ def test_change_invalid_line_number(): Change(lineNumber=0, description="Change 1 to 2") +def test_change_empty_description(): + with pytest.raises(ValueError): + Change(lineNumber=1, description="") + + +def test_change_description_optional(): + Change(lineNumber=1, description=None) + + def test_write_codetf(tmpdir, mocker, codetf_schema): path = tmpdir / "test.codetf.json"