1111from enum import Enum
1212from typing import TYPE_CHECKING , Optional
1313
14- from pydantic import BaseModel , ConfigDict , model_validator
14+ from pydantic import BaseModel , model_validator
1515
1616from codemodder import __version__
1717
18- from ..common import CaseInsensitiveEnum , CodeTFWriter
18+ from ..common import (
19+ CaseInsensitiveEnum ,
20+ )
21+ from ..common import Change as CommonChange
22+ from ..common import (
23+ CodeTFWriter ,
24+ )
25+ from ..common import Finding as CommonFinding
26+ from ..common import (
27+ Rule ,
28+ )
1929
2030if TYPE_CHECKING :
2131 from codemodder .context import CodemodExecutionContext
@@ -46,10 +56,6 @@ class PackageAction(BaseModel):
4656class Change (BaseModel ):
4757 lineNumber : int
4858 description : Optional [str ]
49- # All of our changes are currently treated as additive, so it makes sense
50- # for the comments to appear on the RIGHT side of the split diff. Eventually we
51- # may want to differentiate between LEFT and RIGHT, but for now we'll just
52- # default to RIGHT.
5359 diffSide : DiffSide = DiffSide .RIGHT
5460 properties : Optional [dict ] = None
5561 packageActions : Optional [list [PackageAction ]] = None
@@ -77,6 +83,15 @@ def with_findings(self, findings: list[Finding] | None) -> Change:
7783 fixedFindings = findings ,
7884 )
7985
86+ def to_common (self ) -> CommonChange :
87+ return CommonChange (
88+ lineNumber = self .lineNumber ,
89+ description = self .description ,
90+ diffSide = self .diffSide ,
91+ properties = self .properties ,
92+ packageActions = self .packageActions ,
93+ )
94+
8095
8196class AIMetadata (BaseModel ):
8297 provider : Optional [str ] = None
@@ -138,20 +153,7 @@ def validate_description(self):
138153 return self
139154
140155
141- class Rule (BaseModel ):
142- id : str
143- name : str
144- url : Optional [str ] = None
145-
146- model_config = ConfigDict (frozen = True )
147-
148-
149- class Finding (BaseModel ):
150- id : Optional [str ] = None
151- rule : Rule
152-
153- model_config = ConfigDict (frozen = True )
154-
156+ class Finding (CommonFinding ):
155157 def to_unfixed_finding (
156158 self ,
157159 * ,
@@ -170,7 +172,7 @@ def to_unfixed_finding(
170172 def with_rule (self , name : str , url : Optional [str ]) -> Finding :
171173 return Finding (
172174 id = self .id ,
173- rule = Rule (id = self .rule .id , name = name , url = url ),
175+ rule = Rule (id = self .rule .id , name = name , url = url ) if self . rule else None ,
174176 )
175177
176178
0 commit comments