Skip to content

Commit df1cd51

Browse files
authored
Ruff: Add and fix RUF021 (#10715)
1 parent b98e182 commit df1cd51

File tree

8 files changed

+17
-16
lines changed

8 files changed

+17
-16
lines changed

dojo/jira_link/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ def get_labels(obj):
553553
if prod_name_label not in labels:
554554
labels.append(prod_name_label)
555555

556-
if system_settings.add_vulnerability_id_to_jira_label or jira_project and jira_project.add_vulnerability_id_to_jira_label:
556+
if system_settings.add_vulnerability_id_to_jira_label or (jira_project and jira_project.add_vulnerability_id_to_jira_label):
557557
if isinstance(obj, Finding) and obj.vulnerability_ids:
558558
for id in obj.vulnerability_ids:
559559
labels.append(id)

dojo/search/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def simple_search(request):
154154
tags = operators["tags"] if "tags" in operators else keywords
155155
not_tag = operators["not-tag"] if "not-tag" in operators else keywords
156156
not_tags = operators["not-tags"] if "not-tags" in operators else keywords
157-
if search_tags and tag or tags or not_tag or not_tags:
157+
if (search_tags and tag) or tags or not_tag or not_tags:
158158
logger.debug("searching tags")
159159

160160
Q1, Q2, Q3, Q4 = Q(), Q(), Q(), Q()

dojo/templatetags/display_tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def datediff_time(date1, date2):
338338
date_str = ""
339339
diff = dateutil.relativedelta.relativedelta(date2, date1)
340340
attrs = ["years", "months", "days"]
341-
human_date = ["%d %s" % (getattr(diff, attr), getattr(diff, attr) > 1 and attr or attr[:-1])
341+
human_date = ["%d %s" % (getattr(diff, attr), (getattr(diff, attr) > 1 and attr) or attr[:-1])
342342
for attr in attrs if getattr(diff, attr)]
343343
for date_part in human_date:
344344
date_str = date_str + date_part + " "

dojo/tools/appcheck_web_application_scanner/engines/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ def parse_cpe(self, cpe_str: str) -> (Optional[str], Optional[str]):
198198
return None, None
199199
cpe_obj = CPE(cpe_str)
200200
return (
201-
cpe_obj.get_product() and cpe_obj.get_product()[0] or None,
202-
cpe_obj.get_version() and cpe_obj.get_version()[0] or None,
201+
(cpe_obj.get_product() and cpe_obj.get_product()[0]) or None,
202+
(cpe_obj.get_version() and cpe_obj.get_version()[0]) or None,
203203
)
204204

205205
def parse_components(self, finding: Finding, value: [str]) -> None:

dojo/tools/detect_secrets/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def get_findings(self, filename, test):
5353
date=find_date,
5454
severity="High",
5555
verified=is_verified,
56-
active="is_secret" in item
57-
and item["is_secret"] is True
56+
active=("is_secret" in item
57+
and item["is_secret"] is True)
5858
or "is_secret" not in item,
5959
file_path=file,
6060
line=line,

dojo/tools/veracode_sca/parser.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ def _get_findings_json(self, file, test):
123123
)
124124
status = issue.get("issue_status")
125125
if (
126-
issue.get("Ignored")
127-
and issue.get("Ignored").capitalize() == "True"
128-
or status
126+
(issue.get("Ignored")
127+
and issue.get("Ignored").capitalize() == "True")
128+
or (status
129129
and (
130130
status.capitalize() == "Resolved"
131131
or status.capitalize() == "Fixed"
132-
)
132+
))
133133
):
134134
finding.is_mitigated = True
135135
finding.mitigated = timezone.now()
@@ -212,10 +212,10 @@ def get_findings_csv(self, file, test):
212212
finding.cvssv3_score = cvss_score
213213

214214
if (
215-
row.get("Ignored")
216-
and row.get("Ignored").capitalize() == "True"
217-
or row.get("Status")
218-
and row.get("Status").capitalize() == "Resolved"
215+
(row.get("Ignored")
216+
and row.get("Ignored").capitalize() == "True")
217+
or (row.get("Status")
218+
and row.get("Status").capitalize() == "Resolved")
219219
):
220220
finding.is_mitigated = True
221221
finding.mitigated = timezone.now()

ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ select = [
7979
"RUF001","RUF002", "RUF003", "RUF005",
8080
"RUF013",
8181
"RUF019",
82+
"RUF021",
8283
"RUF025",
8384
]
8485
ignore = ["E501", "E722"]

unittests/dojo_test_case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def assert_jira_issue_in_epic(self, finding, engagement, issue_in_epic=True):
413413
url = instance.url.strip("/") + "/rest/api/latest/issue/" + issue_id
414414
response = jira._session.get(url).json().get("fields", {})
415415
epic_link = response.get(epic_link_field, None)
416-
if epic_id is None and epic_link is None or issue_in_epic:
416+
if (epic_id is None and epic_link is None) or issue_in_epic:
417417
self.assertEqual(epic_id, epic_link)
418418
else:
419419
self.assertNotEqual(epic_id, epic_link)

0 commit comments

Comments
 (0)