豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Enable additional ruff (linting) rules #686

@MooseTheRebel

Description

@MooseTheRebel

I'm no ruff expert, but I do see some low hanging fruit that can be automatically detected and easily fixed with some very small edits to this section of your pyproject.toml file:

[tool.ruff.lint]
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
# Enable flagging print (T201)
select = ["E", "F", "T201"]

"PERF" rules

If we enable the "PERF" (performance) rules, we can detect the following 1 issue:

PERF401 Use `list.extend` to create a transformed list
  --> src/thunderbird_accounts/core/views.py:79:17
   |
77 |             # Get user's app passwords from Stalwart, excluding internal ones
78 |             for secret in filter_app_passwords(email_user.get('secrets', [])):
79 |                 app_passwords.append(decode_app_password(secret))
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80 |
81 |             # Get user's email addresses from Stalwart
   |
help: Replace for loop with list.extend

Found 1 error.

You can read about this rule here: https://docs.astral.sh/ruff/rules/manual-list-comprehension/

"FURB" rules

Similarly, if we enable the "FURB" rules, you can find 3 issues:

FURB188 Prefer `str.removeprefix()` over conditionally replacing with slice.
   --> docs/conf.py:109:9
    |
108 |           # Depending on where the docs are built from this could be slightly different...
109 | /         if file.startswith('../'):
110 | |             file = file[3:]
    | |___________________________^
111 |
112 |           if not file.startswith('src/thunderbird_accounts'):
    |
help: Use removeprefix instead of assignment conditional upon startswith.

FURB110 Replace ternary `if` expression with `or` operator
   --> src/thunderbird_accounts/authentication/views.py:157:22
    |
155 |         sentry_sdk.capture_exception(ex)
156 |         messages.error(
157 |             request, ex.error_desc if ex.error_desc else _('There was an unknown error, please try again later.')
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
158 |         )
159 |         return HttpResponseRedirect('/sign-up')
    |
help: Replace with `or` operator

FURB110 Replace ternary `if` expression with `or` operator
   --> src/thunderbird_accounts/core/views.py:126:32
    |
124 |             'app_passwords': json.dumps(app_passwords),
125 |             'user_display_name': user_display_name,
126 |             'allowed_domains': settings.ALLOWED_EMAIL_DOMAINS if settings.ALLOWED_EMAIL_DOMAINS else [],
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127 |             'custom_domains': json.dumps(custom_domains),
128 |             'email_addresses': json.dumps(email_addresses),
    |
help: Replace with `or` operator

Found 3 errors.

You can read about these rule here:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions