Skip to content

Commit

Permalink
remove -ID from sonar codemod n (#704)
Browse files Browse the repository at this point in the history
ames
  • Loading branch information
clavedeluna authored Jul 10, 2024
1 parent c5b471c commit 897a0d6
Show file tree
Hide file tree
Showing 42 changed files with 63 additions and 71 deletions.
46 changes: 22 additions & 24 deletions src/codemodder/scripts/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,33 +290,31 @@ class DocMetadata:
}

SONAR_CODEMOD_NAMES = [
"numpy-nan-equality-S6725",
"literal-or-new-object-identity-S5796",
"django-receiver-on-top-S6552",
"exception-without-raise-S3984",
"fix-assert-tuple-S5905",
"remove-assertion-in-pytest-raises-S5915",
"flask-json-response-type-S5131",
"django-json-response-type-S5131",
"jwt-decode-verify-S5659",
"fix-missing-self-or-cls-S5719",
"secure-tempfile-S5445",
"secure-random-S2245",
"enable-jinja2-autoescape-S5247",
"url-sandbox-S5144",
"fix-float-equality-S1244",
"fix-math-isclose-S6727",
"sql-parameterization-S3649",
"django-model-without-dunder-str-S6554",
"break-or-continue-out-of-loop-S1716",
"disable-graphql-introspection-S6786",
"numpy-nan-equality",
"literal-or-new-object-identity",
"django-receiver-on-top",
"exception-without-raise",
"fix-assert-tuple",
"remove-assertion-in-pytest-raises",
"flask-json-response-type",
"django-json-response-type",
"jwt-decode-verify",
"fix-missing-self-or-cls",
"secure-tempfile",
"secure-random",
"enable-jinja2-autoescape",
"url-sandbox",
"fix-float-equality",
"fix-math-isclose",
"sql-parameterization",
"django-model-without-dunder-str",
"break-or-continue-out-of-loop",
"disable-graphql-introspection",
]
SONAR_CODEMODS = {
name: DocMetadata(
importance=CORE_CODEMODS[
core_codemod_name := "-".join(name.split("-")[:-1])
].importance,
guidance_explained=CORE_CODEMODS[core_codemod_name].guidance_explained,
importance=CORE_CODEMODS[name].importance,
guidance_explained=CORE_CODEMODS[name].guidance_explained,
need_sarif="Yes (Sonar)",
)
for name in SONAR_CODEMOD_NAMES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarBreakOrContinueOutOfLoop = SonarCodemod.from_core_codemod(
name="break-or-continue-out-of-loop-S1716",
name="break-or-continue-out-of-loop",
other=BreakOrContinueOutOfLoop,
rule_id="python:S1716",
rule_name='"break" and "continue" should not be used outside a loop',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarDisableGraphQLIntrospection = SonarCodemod.from_core_codemod(
name="disable-graphql-introspection-S6786",
name="disable-graphql-introspection",
other=DisableGraphQLIntrospection,
rule_id="python:S6786",
rule_name="GraphQL introspection should be disabled in production",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_django_json_response_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarDjangoJsonResponseType = SonarCodemod.from_core_codemod(
name="django-json-response-type-S5131",
name="django-json-response-type",
other=DjangoJsonResponseType,
rule_id="pythonsecurity:S5131",
rule_name="Endpoints should not be vulnerable to reflected XSS attacks (Django)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarDjangoModelWithoutDunderStr = SonarCodemod.from_core_codemod(
name="django-model-without-dunder-str-S6554",
name="django-model-without-dunder-str",
other=DjangoModelWithoutDunderStr,
rule_id="python:S6554",
rule_name='Django models should define a "__str__" method',
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_django_receiver_on_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarDjangoReceiverOnTop = SonarCodemod.from_core_codemod(
name="django-receiver-on-top-S6552",
name="django-receiver-on-top",
other=DjangoReceiverOnTop,
rule_id="python:S6552",
rule_name="Django signal handler functions should have the `@receiver` decorator on top of all other decorators",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_enable_jinja2_autoescape.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarEnableJinja2Autoescape = SonarCodemod.from_core_codemod(
name="enable-jinja2-autoescape-S5247",
name="enable-jinja2-autoescape",
other=EnableJinja2Autoescape,
rule_id="python:S5247",
rule_name="Disabling auto-escaping in template engines is security-sensitive",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_exception_without_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarExceptionWithoutRaise = SonarCodemod.from_core_codemod(
name="exception-without-raise-S3984",
name="exception-without-raise",
other=ExceptionWithoutRaise,
rule_id="python:S3984",
rule_name="Exceptions should not be created without being raised",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_fix_assert_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarFixAssertTuple = SonarCodemod.from_core_codemod(
name="fix-assert-tuple-S5905",
name="fix-assert-tuple",
other=FixAssertTuple,
rule_id="python:S5905",
rule_name="Assert should not be called on a tuple literal",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_fix_float_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarFixFloatEquality = SonarCodemod.from_core_codemod(
name="fix-float-equality-S1244",
name="fix-float-equality",
other=FixFloatEquality,
rule_id="python:S1244",
rule_name="Floating point numbers should not be tested for equality",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_fix_math_isclose.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def match_location(self, pos, result):


SonarFixMathIsClose = SonarCodemod.from_core_codemod(
name="fix-math-isclose-S6727",
name="fix-math-isclose",
other=FixMathIsClose,
rule_id="python:S6727",
rule_name="The abs_tol parameter should be provided when using math.isclose to compare values to 0",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_fix_missing_self_or_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarFixMissingSelfOrCls = SonarCodemod.from_core_codemod(
name="fix-missing-self-or-cls-S5719",
name="fix-missing-self-or-cls",
other=FixMissingSelfOrCls,
rule_id="python:S5719",
rule_name="Instance and class methods should have at least one positional parameter",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_flask_json_response_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarFlaskJsonResponseType = SonarCodemod.from_core_codemod(
name="flask-json-response-type-S5131",
name="flask-json-response-type",
other=FlaskJsonResponseType,
rule_id="pythonsecurity:S5131",
rule_name="Endpoints should not be vulnerable to reflected XSS attacks (Flask)",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_jwt_decode_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarJwtDecodeVerify = SonarCodemod.from_core_codemod(
name="jwt-decode-verify-S5659",
name="jwt-decode-verify",
other=JwtDecodeVerify,
rule_id="python:S5659",
rule_name="JWT should be signed and verified",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarLiteralOrNewObjectIdentity = SonarCodemod.from_core_codemod(
name="literal-or-new-object-identity-S5796",
name="literal-or-new-object-identity",
other=LiteralOrNewObjectIdentity,
rule_id="python:S5796",
rule_name="New objects should not be created only to check their identity",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_numpy_nan_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarNumpyNanEquality = SonarCodemod.from_core_codemod(
name="numpy-nan-equality-S6725",
name="numpy-nan-equality",
other=NumpyNanEquality,
rule_id="python:S6725",
rule_name="Equality checks should not be made against `numpy.nan`",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarRemoveAssertionInPytestRaises = SonarCodemod.from_core_codemod(
name="remove-assertion-in-pytest-raises-S5915",
name="remove-assertion-in-pytest-raises",
other=RemoveAssertionInPytestRaises,
rule_id="python:S5915",
rule_name="Assertions should not be made at the end of blocks expecting an exception",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_secure_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sonar.api import SonarCodemod

SonarSecureRandom = SonarCodemod.from_core_codemod(
name="secure-random-S2245",
name="secure-random",
other=SecureRandom,
rule_id="python:S2245",
rule_name="Using pseudorandom number generators (PRNGs) is security-sensitive",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_sql_parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.sql_parameterization import SQLQueryParameterization

SonarSQLParameterization = SonarCodemod.from_core_codemod(
name="sql-parameterization-S3649",
name="sql-parameterization",
other=SQLQueryParameterization,
rule_id="pythonsecurity:S3649",
rule_name="Database queries should not be vulnerable to injection attacks",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_tempfile_mktemp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.tempfile_mktemp import TempfileMktemp

SonarTempfileMktemp = SonarCodemod.from_core_codemod(
name="secure-tempfile-S5445",
name="secure-tempfile",
other=TempfileMktemp,
rule_id="python:S5445",
rule_name="Insecure temporary file creation methods should not be used",
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/sonar_url_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from core_codemods.url_sandbox import UrlSandbox

SonarUrlSandbox = SonarCodemod.from_core_codemod(
name="url-sandbox-S5144",
name="url-sandbox",
other=UrlSandbox,
rule_id="pythonsecurity:S5144",
rule_name="Server-side requests should not be vulnerable to forging attacks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestSonarSQLParameterization(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "break-or-continue-out-of-loop-S1716"
assert self.codemod.name == "break-or-continue-out-of-loop"

def test_simple(self, tmpdir):
input_code = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestSonarDisableGraphQLIntrospection(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "disable-graphql-introspection-S6786"
assert self.codemod.name == "disable-graphql-introspection"

def test_simple(self, tmpdir):
input_code = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestDjangoJsonResponseType(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "django-json-response-type-S5131"
assert self.codemod.name == "django-json-response-type"

def test_simple(self, tmpdir):
rule_id = "pythonsecurity:S5131"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class TestSonarDjangoModelWithoutDunderStr(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "django-model-without-dunder-str-S6554"
assert self.codemod.id == "sonar:python/django-model-without-dunder-str-S6554"
assert self.codemod.name == "django-model-without-dunder-str"
assert self.codemod.id == "sonar:python/django-model-without-dunder-str"

def test_simple(self, tmpdir):
input_code = """
Expand Down
2 changes: 1 addition & 1 deletion tests/codemods/sonar/test_sonar_django_receiver_on_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestSonarDjangoReceiverOnTop(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "django-receiver-on-top-S6552"
assert self.codemod.name == "django-receiver-on-top"

def test_simple(self, tmpdir):
input_code = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestEnableJinja2Autoescape(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "enable-jinja2-autoescape-S5247"
assert self.codemod.name == "enable-jinja2-autoescape"

def test_simple(self, tmpdir):
input_code = """
Expand Down
2 changes: 1 addition & 1 deletion tests/codemods/sonar/test_sonar_exception_without_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestSonarExceptionWithoutRaise(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "exception-without-raise-S3984"
assert self.codemod.name == "exception-without-raise"

def test_simple(self, tmpdir):
input_code = """
Expand Down
2 changes: 1 addition & 1 deletion tests/codemods/sonar/test_sonar_fix_assert_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestSonarFixAssertTuple(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "fix-assert-tuple-S5905"
assert self.codemod.name == "fix-assert-tuple"

def test_simple(self, tmpdir):
input_code = """
Expand Down
2 changes: 1 addition & 1 deletion tests/codemods/sonar/test_sonar_fix_float_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestSonarFixFloatEquality(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "fix-float-equality-S1244"
assert self.codemod.name == "fix-float-equality"

def test_simple(self, tmpdir):
input_code = """
Expand Down
2 changes: 1 addition & 1 deletion tests/codemods/sonar/test_sonar_fix_math_isclose.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestSonarFixMathIsClose(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "fix-math-isclose-S6727"
assert self.codemod.name == "fix-math-isclose"

def test_simple(self, tmpdir):
input_code = """
Expand Down
2 changes: 1 addition & 1 deletion tests/codemods/sonar/test_sonar_fix_missing_self_or_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestSonarFixMissingSelfOrCls(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "fix-missing-self-or-cls-S5719"
assert self.codemod.name == "fix-missing-self-or-cls"

def test_simple(self, tmpdir):
input_code = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestSonarFlaskJsonResponseType(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "flask-json-response-type-S5131"
assert self.codemod.name == "flask-json-response-type"

def test_simple(self, tmpdir):
input_code = """
Expand Down
2 changes: 1 addition & 1 deletion tests/codemods/sonar/test_sonar_jwt_decode_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestSonarJwtDecodeVerify(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "jwt-decode-verify-S5659"
assert self.codemod.name == "jwt-decode-verify"

def test_simple(self, tmpdir):
input_code = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestSonarLiteralOrNewObjectIdentity(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "literal-or-new-object-identity-S5796"
assert self.codemod.name == "literal-or-new-object-identity"

def test_list(self, tmpdir):
input_code = """
Expand Down
2 changes: 1 addition & 1 deletion tests/codemods/sonar/test_sonar_numpy_nan_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestSonarNumpyNanEquality(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "numpy-nan-equality-S6725"
assert self.codemod.name == "numpy-nan-equality"

def test_simple(self, tmpdir):
input_code = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestRemoveAssertionInPytestRaises(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "remove-assertion-in-pytest-raises-S5915"
assert self.codemod.name == "remove-assertion-in-pytest-raises"

def test_simple(self, tmpdir):
input_code = """
Expand Down
2 changes: 1 addition & 1 deletion tests/codemods/sonar/test_sonar_secure_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestSonarSecureRandom(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "secure-random-S2245"
assert self.codemod.name == "secure-random"

def test_simple(self, tmpdir):
input_code = """
Expand Down
2 changes: 1 addition & 1 deletion tests/codemods/sonar/test_sonar_sql_parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TestSonarSQLParameterization(BaseSASTCodemodTest):
tool = "sonar"

def test_name(self):
assert self.codemod.name == "sql-parameterization-S3649"
assert self.codemod.name == "sql-parameterization"

def test_simple(self, tmpdir):
input_code = """
Expand Down
Loading

0 comments on commit 897a0d6

Please sign in to comment.