Skip to content

Commit c12e788

Browse files
themohitkhareclaude
andcommitted
style: run ruff format on new rule files
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 93a8ec2 commit c12e788

9 files changed

Lines changed: 52 additions & 35 deletions

File tree

src/pycodegate/rules/celery.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ def _check_broad_autoretry(self, func_node, call: ast.Call, filename: str) -> li
157157
# ------------------------------------------------------------------
158158
# Rule: celery-direct-call
159159
# ------------------------------------------------------------------
160-
def _check_direct_call(self, node: ast.Call, task_names: set[str], filename: str) -> list[Diagnostic]:
160+
def _check_direct_call(
161+
self, node: ast.Call, task_names: set[str], filename: str
162+
) -> list[Diagnostic]:
161163
if isinstance(node.func, ast.Name) and node.func.id in task_names:
162164
return [
163165
Diagnostic(

src/pycodegate/rules/numpy_rules.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ def _compare_has_array(self, node: ast.Compare) -> bool:
5353
return True
5454
return False
5555

56-
def _check_array_equality(
57-
self, node: ast.If | ast.While, filename: str
58-
) -> list[Diagnostic]:
56+
def _check_array_equality(self, node: ast.If | ast.While, filename: str) -> list[Diagnostic]:
5957
test = node.test
6058
flagged: list[ast.AST] = []
6159

@@ -160,7 +158,11 @@ def _is_np_array_literal(node: ast.Call) -> bool:
160158

161159
@staticmethod
162160
def _is_int_literal(elt: ast.expr) -> bool:
163-
return isinstance(elt, ast.Constant) and isinstance(elt.value, int) and not isinstance(elt.value, bool)
161+
return (
162+
isinstance(elt, ast.Constant)
163+
and isinstance(elt.value, int)
164+
and not isinstance(elt.value, bool)
165+
)
164166

165167
@staticmethod
166168
def _is_none_or_nan(elt: ast.expr) -> bool:

src/pycodegate/rules/pandas_rules.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,13 @@ def check(self, source: str, filename: str) -> list[Diagnostic]:
2525
# ------------------------------------------------------------------
2626
# pandas-chained-indexing
2727
# ------------------------------------------------------------------
28-
def _check_chained_indexing(
29-
self, tree: ast.Module, filename: str
30-
) -> list[Diagnostic]:
28+
def _check_chained_indexing(self, tree: ast.Module, filename: str) -> list[Diagnostic]:
3129
results: list[Diagnostic] = []
3230
for node in ast.walk(tree):
3331
if not isinstance(node, ast.Assign):
3432
continue
3533
for target in node.targets:
36-
if (
37-
isinstance(target, ast.Subscript)
38-
and isinstance(target.value, ast.Subscript)
39-
):
34+
if isinstance(target, ast.Subscript) and isinstance(target.value, ast.Subscript):
4035
results.append(
4136
Diagnostic(
4237
file_path=filename,
@@ -55,9 +50,7 @@ def _check_chained_indexing(
5550
# ------------------------------------------------------------------
5651
# pandas-inplace-assignment
5752
# ------------------------------------------------------------------
58-
def _check_inplace_assignment(
59-
self, tree: ast.Module, filename: str
60-
) -> list[Diagnostic]:
53+
def _check_inplace_assignment(self, tree: ast.Module, filename: str) -> list[Diagnostic]:
6154
results: list[Diagnostic] = []
6255
for node in ast.walk(tree):
6356
if not isinstance(node, ast.Assign):
@@ -90,9 +83,7 @@ def _check_inplace_assignment(
9083
# ------------------------------------------------------------------
9184
# pandas-nan-comparison
9285
# ------------------------------------------------------------------
93-
def _check_nan_comparison(
94-
self, tree: ast.Module, filename: str
95-
) -> list[Diagnostic]:
86+
def _check_nan_comparison(self, tree: ast.Module, filename: str) -> list[Diagnostic]:
9687
results: list[Diagnostic] = []
9788
for node in ast.walk(tree):
9889
if not isinstance(node, ast.Compare):

src/pycodegate/rules/pydantic.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
def _is_basemodel_subclass(node: ast.ClassDef) -> bool:
1212
"""Check if any base in node.bases is a Name with id 'BaseModel'."""
13-
return any(
14-
isinstance(base, ast.Name) and base.id == "BaseModel" for base in node.bases
15-
)
13+
return any(isinstance(base, ast.Name) and base.id == "BaseModel" for base in node.bases)
1614

1715

1816
class PydanticRules(BaseRules):
@@ -112,9 +110,17 @@ def _check_validator_no_return(self, cls: ast.ClassDef, filename: str) -> list[D
112110
@staticmethod
113111
def _has_validator_decorator(node: ast.FunctionDef | ast.AsyncFunctionDef) -> bool:
114112
for dec in node.decorator_list:
115-
if isinstance(dec, ast.Name) and dec.id in ("field_validator", "model_validator", "validator"):
113+
if isinstance(dec, ast.Name) and dec.id in (
114+
"field_validator",
115+
"model_validator",
116+
"validator",
117+
):
116118
return True
117-
if isinstance(dec, ast.Call) and isinstance(dec.func, ast.Name) and dec.func.id in ("field_validator", "model_validator", "validator"):
119+
if (
120+
isinstance(dec, ast.Call)
121+
and isinstance(dec.func, ast.Name)
122+
and dec.func.id in ("field_validator", "model_validator", "validator")
123+
):
118124
return True
119125
return False
120126

@@ -277,7 +283,11 @@ def _has_field_validator_decorator(node: ast.FunctionDef | ast.AsyncFunctionDef)
277283
for dec in node.decorator_list:
278284
if isinstance(dec, ast.Name) and dec.id == "field_validator":
279285
return True
280-
if isinstance(dec, ast.Call) and isinstance(dec.func, ast.Name) and dec.func.id == "field_validator":
286+
if (
287+
isinstance(dec, ast.Call)
288+
and isinstance(dec.func, ast.Name)
289+
and dec.func.id == "field_validator"
290+
):
281291
return True
282292
return False
283293

src/pycodegate/rules/pytest_rules.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def _check_assert_tuple(self, tree: ast.Module, filename: str) -> list[Diagnosti
5050
# Rule 2: pytest-raises-instead-of-try
5151
# ------------------------------------------------------------------
5252

53-
def _check_raises_instead_of_try(
54-
self, tree: ast.Module, filename: str
55-
) -> list[Diagnostic]:
53+
def _check_raises_instead_of_try(self, tree: ast.Module, filename: str) -> list[Diagnostic]:
5654
"""Detect try/except anti-patterns in test functions."""
5755
diags: list[Diagnostic] = []
5856
for node in ast.walk(tree):
@@ -147,6 +145,10 @@ def _has_float_eq(node: ast.expr | None) -> bool:
147145
if not isinstance(node, ast.Compare):
148146
return False
149147
for op, comparator in zip(node.ops, node.comparators): # noqa: B905
150-
if isinstance(op, ast.Eq) and isinstance(comparator, ast.Constant) and isinstance(comparator.value, float):
148+
if (
149+
isinstance(op, ast.Eq)
150+
and isinstance(comparator, ast.Constant)
151+
and isinstance(comparator.value, float)
152+
):
151153
return True
152154
return False

src/pycodegate/rules/requests_rules.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ def _is_attr_call(node: ast.Call, attr: str) -> bool:
147147

148148
def _check_verify_disabled(self, node: ast.Call, filename: str) -> list[Diagnostic]:
149149
for kw in node.keywords:
150-
if kw.arg == "verify" and isinstance(kw.value, ast.Constant) and kw.value.value is False:
150+
if (
151+
kw.arg == "verify"
152+
and isinstance(kw.value, ast.Constant)
153+
and kw.value.value is False
154+
):
151155
return [
152156
Diagnostic(
153157
file_path=filename,

tests/rules/test_celery.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def _run(source: str) -> list:
77

88
# -- celery-missing-bind --------------------------------------------------
99

10+
1011
def test_missing_bind():
1112
source = """
1213
from celery import shared_task
@@ -33,6 +34,7 @@ def add(self, x, y):
3334

3435
# -- celery-retry-no-exc --------------------------------------------------
3536

37+
3638
def test_retry_no_exc():
3739
source = """
3840
@app.task(bind=True)
@@ -61,6 +63,7 @@ def fetch(self, url):
6163

6264
# -- celery-broad-autoretry ------------------------------------------------
6365

66+
6467
def test_broad_autoretry():
6568
source = """
6669
@app.task(autoretry_for=(Exception,))
@@ -83,6 +86,7 @@ def process(data):
8386

8487
# -- celery-direct-call ----------------------------------------------------
8588

89+
8690
def test_direct_call():
8791
source = """
8892
@app.task

tests/rules/test_logging_rules.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def _run(source: str, filename: str = "app.py") -> list:
88

99
# --- logging-fstring ---
1010

11+
1112
def test_logging_fstring_detected():
1213
source = "logger.info(f'User {user_id} logged in')"
1314
diags = _run(source)
@@ -24,6 +25,7 @@ def test_logging_percent_style_ok():
2425

2526
# --- logging-root-logger ---
2627

28+
2729
def test_logging_root_logger_detected():
2830
source = "import logging\nlogging.info('starting up')"
2931
diags = _run(source)
@@ -38,13 +40,9 @@ def test_logging_named_logger_ok():
3840

3941
# --- logging-error-no-exc-info ---
4042

43+
4144
def test_logging_error_no_exc_info_detected():
42-
source = (
43-
"try:\n"
44-
" do_something()\n"
45-
"except Exception as e:\n"
46-
" logger.error('failed')\n"
47-
)
45+
source = "try:\n do_something()\nexcept Exception as e:\n logger.error('failed')\n"
4846
diags = _run(source)
4947
assert any(d.rule == "logging-error-no-exc-info" for d in diags)
5048

tests/rules/test_sqlalchemy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def _run(source: str) -> list:
77

88
# -- sqla-sql-injection ------------------------------------------------
99

10+
1011
def test_sql_injection_fstring():
1112
source = """
1213
from sqlalchemy import text
@@ -27,6 +28,7 @@ def test_sql_injection_parameterized_ok():
2728

2829
# -- sqla-identity-compare ---------------------------------------------
2930

31+
3032
def test_identity_compare_is_none():
3133
source = """
3234
session.query(User).filter(User.name is None)
@@ -45,6 +47,7 @@ def test_identity_compare_eq_none_ok():
4547

4648
# -- sqla-mutable-default ----------------------------------------------
4749

50+
4851
def test_mutable_default_list_literal():
4952
source = """
5053
from sqlalchemy import Column, JSON
@@ -65,6 +68,7 @@ def test_mutable_default_callable_ok():
6568

6669
# -- sqla-len-all -------------------------------------------------------
6770

71+
6872
def test_len_all_flagged():
6973
source = """
7074
count = len(session.query(User).all())

0 commit comments

Comments
 (0)