Skip to content

Ruff: Add and fix PERF402 #12372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions docker/install_chrome_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ def ldd(file_path):
missing_packages = []
for d in missing_deps:
all_packages = find_packages(d)
packages = [
missing_packages = [
p
for p in all_packages
if not any(
p.endswith(suffix) for suffix in ["-dbg", "-test", "tests", "-dev", "-mesa"]
)
]
for p in packages:
missing_packages.append(p)
logger.info("missing_packages: " + (" ".join(missing_packages)))
2 changes: 1 addition & 1 deletion dojo/notes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
multiple_note_types = Note_Type.objects.filter(is_single=False, is_active=True).values_list("id", flat=True)
available_note_types = []
for note_type_id in multiple_note_types:
available_note_types.append(note_type_id)
available_note_types.append(note_type_id) # TODO: Is it possible to write this nicer?

Check failure on line 187 in dojo/notes/views.py

View workflow job for this annotation

GitHub Actions / ruff-linting

Ruff (PERF402)

dojo/notes/views.py:187:9: PERF402 Use `list` or `list.copy` to create a copy of a list
for note_type_id in single_note_types:
for note in notes:
if note_type_id == note.note_type_id:
Expand Down
5 changes: 1 addition & 4 deletions dojo/templatetags/display_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,10 +814,7 @@ def first_vulnerability_id(finding):
def additional_vulnerability_ids(finding):
vulnerability_ids = finding.vulnerability_ids
if vulnerability_ids and len(vulnerability_ids) > 1:
references = []
for vulnerability_id in vulnerability_ids[1:]:
references.append(vulnerability_id)
return references
return vulnerability_ids[1:]
return None


Expand Down
6 changes: 1 addition & 5 deletions dojo/tools/bugcrowd/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ def get_findings(self, filename, test):
reader = csv.DictReader(
io.StringIO(content), delimiter=",", quotechar='"',
)
csvarray = []

for row in reader:
csvarray.append(row)

dupes = {}
for row in csvarray:
for row in reader:
finding = Finding(test=test)

url = row.get("bug_url", None)
Expand Down
3 changes: 1 addition & 2 deletions dojo/tools/cargo_audit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ def get_findings(self, filename, test):
)
date = advisory.get("date")

for alias in advisory.get("aliases", []):
vulnerability_ids.append(alias)
vulnerability_ids = advisory.get("aliases", [])

package_name = item.get("package").get("name")
package_version = item.get("package").get("version")
Expand Down
3 changes: 1 addition & 2 deletions dojo/tools/clair/clairklar_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def set_items_for_severity(self, tree, test, severity):
items = []
tree_severity = tree.get(severity)
if tree_severity:
for data in self.get_items_clairklar(tree_severity, test):
items.append(data)
items = self.get_items_clairklar(tree_severity, test)
logger.debug("Appended findings for severity " + severity)
else:
logger.debug("No findings for severity " + severity)
Expand Down
6 changes: 1 addition & 5 deletions dojo/tools/kiuwan/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ def get_findings(self, filename, test):
reader = csv.DictReader(
io.StringIO(content), delimiter=",", quotechar='"',
)
csvarray = []

for row in reader:
csvarray.append(row)

dupes = {}
for row in csvarray:
for row in reader:
finding = Finding(test=test)
findingdict = {}
severityfilter = Severityfilter()
Expand Down
4 changes: 1 addition & 3 deletions dojo/tools/ms_defender/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def get_findings(self, file, test):
vulnerabilities = []
machines = {}
for vulnerabilityfile in vulnerabilityfiles:
output = json.loads(zipdata[vulnerabilityfile].decode("ascii"))["value"]
for data in output:
vulnerabilities.append(data)
vulnerabilities = json.loads(zipdata[vulnerabilityfile].decode("ascii"))["value"]
for machinefile in machinefiles:
output = json.loads(zipdata[machinefile].decode("ascii"))["value"]
for data in output:
Expand Down
4 changes: 1 addition & 3 deletions dojo/tools/nuclei/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def get_findings(self, filename, test):
if filecontent == "" or len(filecontent) == 0:
return []
if filecontent[0] == "[":
content = json.loads(filecontent)
for template in content:
data.append(template)
data = json.loads(filecontent)
elif filecontent[0] == "{":
file = filecontent.split("\n")
for line in file:
Expand Down
6 changes: 1 addition & 5 deletions dojo/tools/solar_appscreener/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ def get_findings(self, filename, test):
reader = csv.DictReader(
io.StringIO(content), delimiter=",", quotechar='"',
)
csvarray = []

for row in reader:
csvarray.append(row)

items = []
for row in csvarray:
for row in reader:
finding = Finding(test=test)
finding.title = row.get("Vulnerability", "")
finding.description = row.get("Description", "")
Expand Down
6 changes: 1 addition & 5 deletions dojo/tools/veracode_sca/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,9 @@ def get_findings_csv(self, file, test):
reader = csv.DictReader(
io.StringIO(content), delimiter=",", quotechar='"',
)
csvarray = []

for row in reader:
csvarray.append(row)

findings = []
for row in csvarray:
for row in reader:
if row.get("Issue type") != "Vulnerability":
continue

Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ select = [
"DOC202", "DOC403", "DOC502",
"RUF",
"B00", "B010", "B011", "B012", "B013", "B014", "B015", "B016", "B017", "B018", "B019", "B020", "B021", "B022", "B023", "B025", "B028", "B029", "B03", "B901", "B903", "B905", "B911",
"PERF1", "PERF2", "PERF403",
"PERF1", "PERF2", "PERF402", "PERF403",
]
ignore = [
"E501",
Expand Down
Loading