Skip to content

Commit

Permalink
Ruff: Add and fix FBT002 (+ merge all FBT rules)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Dec 15, 2024
1 parent 1b1a9c6 commit 63754ec
Show file tree
Hide file tree
Showing 45 changed files with 100 additions and 95 deletions.
4 changes: 2 additions & 2 deletions dojo/api_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,7 @@ def process_auto_create_create_context(
# Raise an explicit drf exception here
raise ValidationError(str(e))

def save(self, push_to_jira=False):
def save(self, *, push_to_jira=False):
# Go through the validate method
data = self.validated_data
# Extract the data from the form
Expand Down Expand Up @@ -2499,7 +2499,7 @@ def process_scan(
except ValueError as ve:
raise Exception(ve)

def save(self, push_to_jira=False):
def save(self, *, push_to_jira=False):
# Go through the validate method
data = self.validated_data
# Extract the data from the form
Expand Down
2 changes: 1 addition & 1 deletion dojo/components/sql_group_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Sql_GroupConcat(Aggregate):
allow_distinct = True

def __init__(
self, expression, separator, distinct=False, ordering=None, **extra,
self, expression, separator, *, distinct=False, ordering=None, **extra,
):
self.separator = separator
super().__init__(
Expand Down
2 changes: 1 addition & 1 deletion dojo/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def get_parameter_froms_args_kwargs(args, kwargs, parameter):
return model_or_id


def dojo_ratelimit(key="ip", rate=None, method=UNSAFE, block=False):
def dojo_ratelimit(key="ip", rate=None, method=UNSAFE, *, block=False):
def decorator(fn):
@wraps(fn)
def _wrapped(request, *args, **kw):
Expand Down
4 changes: 2 additions & 2 deletions dojo/endpoint/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
logger = logging.getLogger(__name__)


def process_endpoints_view(request, host_view=False, vulnerable=False):
def process_endpoints_view(request, *, host_view=False, vulnerable=False):

if vulnerable:
endpoints = Endpoint.objects.filter(
Expand Down Expand Up @@ -116,7 +116,7 @@ def vulnerable_endpoint_hosts(request):
return process_endpoints_view(request, host_view=True, vulnerable=True)


def process_endpoint_view(request, eid, host_view=False):
def process_endpoint_view(request, eid, *, host_view=False):
endpoint = get_object_or_404(Endpoint, id=eid)

if host_view:
Expand Down
2 changes: 1 addition & 1 deletion dojo/engagement/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ def edit_risk_acceptance(request, eid, raid):


# will only be called by view_risk_acceptance and edit_risk_acceptance
def view_edit_risk_acceptance(request, eid, raid, edit_mode=False):
def view_edit_risk_acceptance(request, eid, raid, *, edit_mode=False):
risk_acceptance = get_object_or_404(Risk_Acceptance, pk=raid)
eng = get_object_or_404(Engagement, pk=eid)

Expand Down
2 changes: 1 addition & 1 deletion dojo/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def get_tags_label_from_model(model):
return "Tags (Unknown)"


def get_finding_filterset_fields(metrics=False, similar=False, filter_string_matching=False):
def get_finding_filterset_fields(*, metrics=False, similar=False, filter_string_matching=False):
fields = []

if similar:
Expand Down
6 changes: 3 additions & 3 deletions dojo/finding/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def group_findings_by(finds, finding_group_by_option):
return affected_groups, grouped, skipped, groups_created


def add_findings_to_auto_group(name, findings, group_by, create_finding_groups_for_all_findings=True, **kwargs):
def add_findings_to_auto_group(name, findings, group_by, *, create_finding_groups_for_all_findings=True, **kwargs):
if name is not None and findings is not None and len(findings) > 0:
creator = get_current_user()
if not creator:
Expand Down Expand Up @@ -349,8 +349,8 @@ def add_findings_to_auto_group(name, findings, group_by, create_finding_groups_f
@dojo_async_task
@app.task
@dojo_model_from_id
def post_process_finding_save(finding, dedupe_option=True, rules_option=True, product_grading_option=True,
issue_updater_option=True, push_to_jira=False, user=None, *args, **kwargs):
def post_process_finding_save(finding, dedupe_option=True, rules_option=True, product_grading_option=True, # noqa: FBT002
issue_updater_option=True, push_to_jira=False, user=None, *args, **kwargs): # noqa: FBT002 - this is bit hard to fix nice have this universally fixed

system_settings = System_Settings.objects.get()

Expand Down
4 changes: 2 additions & 2 deletions dojo/finding/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
logger = logging.getLogger(__name__)


def prefetch_for_findings(findings, prefetch_type="all", exclude_untouched=True):
def prefetch_for_findings(findings, prefetch_type="all", *, exclude_untouched=True):
prefetched_findings = findings
if isinstance(
findings, QuerySet,
Expand Down Expand Up @@ -2242,7 +2242,7 @@ def export_templates_to_json(request):
return HttpResponse(leads_as_json, content_type="json")


def apply_cwe_mitigation(apply_to_findings, template, update=True):
def apply_cwe_mitigation(apply_to_findings, template, *, update=True):
count = 0
if apply_to_findings and template.template_match and template.cwe is not None:
# Update active, verified findings with the CWE template
Expand Down
2 changes: 1 addition & 1 deletion dojo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class MonthYearWidget(Widget):
month_field = "%s_month"
year_field = "%s_year"

def __init__(self, attrs=None, years=None, required=True):
def __init__(self, attrs=None, years=None, *, required=True):
# years is an optional list/tuple of years to use in the
# "year" select box.
self.attrs = attrs or {}
Expand Down
8 changes: 4 additions & 4 deletions dojo/jira_link/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def can_be_pushed_to_jira(obj, form=None):


# use_inheritance=True means get jira_project config from product if engagement itself has none
def get_jira_project(obj, use_inheritance=True):
def get_jira_project(obj, *, use_inheritance=True):
if not is_jira_enabled():
return None

Expand Down Expand Up @@ -673,7 +673,7 @@ def push_to_jira(obj, *args, **kwargs):
return None


def add_issues_to_epic(jira, obj, epic_id, issue_keys, ignore_epics=True):
def add_issues_to_epic(jira, obj, epic_id, issue_keys, *, ignore_epics=True):
try:
return jira.add_issues_to_epic(epic_id=epic_id, issue_keys=issue_keys, ignore_epics=ignore_epics)
except JIRAError as e:
Expand Down Expand Up @@ -1070,7 +1070,7 @@ def issue_from_jira_is_active(issue_from_jira):
return issue_from_jira.fields.resolution == "None"


def push_status_to_jira(obj, jira_instance, jira, issue, save=False):
def push_status_to_jira(obj, jira_instance, jira, issue, *, save=False):
status_list = obj.status()
issue_closed = False
# check RESOLVED_STATUS first to avoid corner cases with findings that are Inactive, but verified
Expand Down Expand Up @@ -1384,7 +1384,7 @@ def jira_get_issue(jira_project, issue_key):
@app.task
@dojo_model_from_id(model=Notes, parameter=1)
@dojo_model_from_id
def add_comment(obj, note, force_push=False, **kwargs):
def add_comment(obj, note, *, force_push=False, **kwargs):
if not is_jira_configured_and_enabled(obj):
return False

Expand Down
2 changes: 1 addition & 1 deletion dojo/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_from_db(self, *args, **kwargs):
return System_Settings()
return from_db

def get(self, no_cache=False, *args, **kwargs):
def get(self, no_cache=False, *args, **kwargs): # noqa: FBT002 - this is bit hard to fix nice have this universally fixed
if no_cache:
# logger.debug('no_cache specified or cached value found, loading system settings from db')
return self.get_from_db(*args, **kwargs)
Expand Down
6 changes: 3 additions & 3 deletions dojo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class UniqueUploadNameProvider:
the filename extension will be dropped.
"""

def __init__(self, directory=None, keep_basename=False, keep_ext=True):
def __init__(self, directory=None, *, keep_basename=False, keep_ext=True):
self.directory = directory
self.keep_basename = keep_basename
self.keep_ext = keep_ext
Expand Down Expand Up @@ -2625,8 +2625,8 @@ class Meta:
def __str__(self):
return self.title

def save(self, dedupe_option=True, rules_option=True, product_grading_option=True,
issue_updater_option=True, push_to_jira=False, user=None, *args, **kwargs):
def save(self, dedupe_option=True, rules_option=True, product_grading_option=True, # noqa: FBT002
issue_updater_option=True, push_to_jira=False, user=None, *args, **kwargs): # noqa: FBT002 - this is bit hard to fix nice have this universally fixed

from dojo.finding import helper as finding_helper

Expand Down
2 changes: 1 addition & 1 deletion dojo/product/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ def delete_product(request, pid):


@user_is_authorized(Product, Permissions.Engagement_Add, "pid")
def new_eng_for_app(request, pid, cicd=False):
def new_eng_for_app(request, pid, *, cicd=False):
jira_project_form = None
jira_epic_form = None

Expand Down
2 changes: 1 addition & 1 deletion dojo/remote_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PersistentRemoteUserMiddleware(RemoteUserMiddleware):


class RemoteUserBackend(OriginalRemoteUserBackend):
def configure_user(self, request, user, created=True):
def configure_user(self, request, user, *, created=True):
changed = False

if settings.AUTH_REMOTEUSER_EMAIL_HEADER and \
Expand Down
2 changes: 1 addition & 1 deletion dojo/reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def product_endpoint_report(request, pid):
})


def generate_report(request, obj, host_view=False):
def generate_report(request, obj, *, host_view=False):
user = Dojo_User.objects.get(id=request.user.id)
product_type = None
product = None
Expand Down
2 changes: 1 addition & 1 deletion dojo/reports/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def get_option_form(self):
return mark_safe(html)


def report_widget_factory(json_data=None, request=None, user=None, finding_notes=False, finding_images=False,
def report_widget_factory(json_data=None, request=None, user=None, *, finding_notes=False, finding_images=False,
host=None):
selected_widgets = OrderedDict()
widgets = json.loads(json_data)
Expand Down
4 changes: 2 additions & 2 deletions dojo/risk_acceptance/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def prefetch_for_expiration(risk_acceptances):
)


def simple_risk_accept(user: Dojo_User, finding: Finding, perform_save=True) -> None:
def simple_risk_accept(user: Dojo_User, finding: Finding, *, perform_save=True) -> None:
if not finding.test.engagement.product.enable_simple_risk_acceptance:
raise PermissionDenied

Expand All @@ -319,7 +319,7 @@ def simple_risk_accept(user: Dojo_User, finding: Finding, perform_save=True) ->
))


def risk_unaccept(user: Dojo_User, finding: Finding, perform_save=True) -> None:
def risk_unaccept(user: Dojo_User, finding: Finding, *, perform_save=True) -> None:
logger.debug("unaccepting finding %i:%s if it is currently risk accepted", finding.id, finding)
if finding.risk_accepted:
logger.debug("unaccepting finding %i:%s", finding.id, finding)
Expand Down
2 changes: 1 addition & 1 deletion dojo/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def vulnerability_id_fix(keyword):
return keyword


def apply_tag_filters(qs, operators, skip_relations=False):
def apply_tag_filters(qs, operators, *, skip_relations=False):
tag_filters = {"tag": ""}

if qs.model == Finding:
Expand Down
2 changes: 1 addition & 1 deletion dojo/survey/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def view_questionnaire(request, eid, sid):
})


def get_answered_questions(survey=None, read_only=False):
def get_answered_questions(survey=None, *, read_only=False):
if survey is None:
return None

Expand Down
10 changes: 5 additions & 5 deletions dojo/templatetags/display_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,8 @@ def jiraencode_component(value):


@register.filter
def jira_project(obj, use_inheritance=True):
return jira_helper.get_jira_project(obj, use_inheritance)
def jira_project(obj, *, use_inheritance=True):
return jira_helper.get_jira_project(obj, use_inheritance=use_inheritance)


@register.filter
Expand Down Expand Up @@ -906,7 +906,7 @@ def class_name(value):


@register.filter(needs_autoescape=True)
def jira_project_tag(product_or_engagement, autoescape=True):
def jira_project_tag(product_or_engagement, *, autoescape=True):
if autoescape:
esc = conditional_escape
else:
Expand Down Expand Up @@ -961,7 +961,7 @@ def full_name(user):


@register.filter(needs_autoescape=True)
def import_settings_tag(test_import, autoescape=True):
def import_settings_tag(test_import, *, autoescape=True):
if not test_import or not test_import.import_settings:
return ""

Expand Down Expand Up @@ -1003,7 +1003,7 @@ def esc(x):


@register.filter(needs_autoescape=True)
def import_history(finding, autoescape=True):
def import_history(finding, *, autoescape=True):
if not finding or not settings.TRACK_IMPORT_HISTORY:
return ""

Expand Down
4 changes: 2 additions & 2 deletions dojo/templatetags/event_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def _process_field_attributes(field, attr, process):
# decorate field.as_widget method with updated attributes
old_as_widget = field.as_widget

def as_widget(self, widget=None, attrs=None, only_initial=False):
def as_widget(self, widget=None, attrs=None, *, only_initial=False):
attrs = attrs or {}
process(widget or self.field.widget, attrs, attribute, value)
return old_as_widget(widget, attrs, only_initial)
return old_as_widget(widget, attrs, only_initial=only_initial)

bound_method = type(old_as_widget)
try:
Expand Down
2 changes: 1 addition & 1 deletion dojo/templatetags/navigation_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def dojo_sort(request, display="Name", value="title", default=None):


class PaginationNav:
def __init__(self, page_number=None, display=None, is_current=False):
def __init__(self, page_number=None, display=None, *, is_current=False):
self.page_number = page_number
self.is_current = is_current
self.display = display or page_number or ""
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/blackduck_component_risk/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def license_description(self, component, source):
desc += "**Scan:** Unable to find scan in source data."
return desc

def license_mitigation(self, component, violation=True):
def license_mitigation(self, component, *, violation=True):
"""
Uses Component name and Component version name to display the package.
:param component: Dictionary containing all components.
Expand Down
Loading

0 comments on commit 63754ec

Please sign in to comment.