Skip to content

Commit

Permalink
add sonar fix or missing self or cls codemod
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Mar 12, 2024
1 parent 1d764f4 commit 672d9ee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/core_codemods/fix_missing_self_or_cls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import libcst as cst

from codemodder.codemods.libcst_transformer import (
LibcstResultTransformer,
LibcstTransformerPipeline,
)
from codemodder.codemods.utils_mixin import NameResolutionMixin
from core_codemods.api import Metadata, ReviewGuidance, SimpleCodemod
from core_codemods.api import Metadata, ReviewGuidance
from core_codemods.api.core_codemod import CoreCodemod


class FixMissingSelfOrCls(SimpleCodemod, NameResolutionMixin):
metadata = Metadata(
name="fix-missing-self-or-cls",
review_guidance=ReviewGuidance.MERGE_WITHOUT_REVIEW,
summary="Fix Missing Positional Parameter for Instance and Class Methods",
references=[],
)

class FixMissingSelfOrClsTransformer(LibcstResultTransformer, NameResolutionMixin):
change_description = "Add `self` or `cls` parameter to instance or class method."

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -76,3 +74,15 @@ def has_no_args(self, node: cst.FunctionDef) -> bool:
node.params.posonly_params,
)
)


FixMissingSelfOrCls = CoreCodemod(
metadata=Metadata(
name="fix-missing-self-or-cls",
review_guidance=ReviewGuidance.MERGE_WITHOUT_REVIEW,
summary="Fix Missing Positional Parameter for Instance and Class Methods",
references=[],
),
transformer=LibcstTransformerPipeline(FixMissingSelfOrClsTransformer),
detector=None,
)
12 changes: 12 additions & 0 deletions src/core_codemods/sonar/sonar_fix_missing_self_or_cls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from codemodder.codemods.base_codemod import Reference
from codemodder.codemods.sonar import SonarCodemod
from core_codemods.fix_missing_self_or_cls import FixMissingSelfOrCls

SonarNumpyNanEquality = SonarCodemod.from_core_codemod(
name="fix-missing-self-or-cls-S5719",
other=FixMissingSelfOrCls,
rules=["python:S5719"],
new_references=[
Reference(url="https://rules.sonarsource.com/python/RSPEC-5719/"),
],
)

0 comments on commit 672d9ee

Please sign in to comment.