-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New way to define SonarCodemod and filter_by_result behavior change
- Loading branch information
1 parent
ce5785a
commit 9afb1ed
Showing
9 changed files
with
59 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,15 @@ | ||
import libcst as cst | ||
from codemodder.codemods.base_codemod import Reference | ||
from codemodder.codemods.libcst_transformer import ( | ||
LibcstTransformerPipeline, | ||
) | ||
from codemodder.codemods.sonar import SonarDetector | ||
from codemodder.codemods.sonar import SonarCodemod | ||
|
||
from core_codemods.api import Metadata | ||
from core_codemods.numpy_nan_equality import ( | ||
NumpyNanEquality, | ||
NumpyNanEqualityTransformer, | ||
) | ||
|
||
|
||
class SonarNumpyNanEqualityTransformer(NumpyNanEqualityTransformer): | ||
def leave_Comparison( | ||
self, original_node: cst.Comparison, updated_node: cst.Comparison | ||
) -> cst.BaseExpression: | ||
if self.filter_by_result(self.node_position(original_node)): | ||
return super().leave_Comparison(original_node, updated_node) | ||
return updated_node | ||
|
||
|
||
rules = ["python:S6725"] | ||
|
||
SonarNumpyNanEquality = SonarCodemod( | ||
metadata=Metadata( | ||
name="numpy-nan-equality-S6725", | ||
summary="Sonar: " + NumpyNanEquality.summary, | ||
review_guidance=NumpyNanEquality._metadata.review_guidance, # pylint: disable=protected-access | ||
references=NumpyNanEquality.references | ||
+ [ | ||
Reference(url="https://rules.sonarsource.com/python/type/Bug/RSPEC-6725/"), | ||
], | ||
description=f"This codemod acts upon the following Sonar rules: {str(rules)[1:-1]}.\n\n" | ||
+ NumpyNanEquality.description, | ||
), | ||
transformer=LibcstTransformerPipeline(SonarNumpyNanEqualityTransformer), | ||
detector=SonarDetector(), | ||
requested_rules=rules, | ||
SonarNumpyNanEquality = SonarCodemod.from_core_codemod( | ||
name="numpy-nan-equality-S6725", | ||
other=NumpyNanEquality, | ||
rules=["python:S6725"], | ||
new_references=[ | ||
Reference(url="https://rules.sonarsource.com/python/type/Bug/RSPEC-6725/"), | ||
], | ||
) |