Skip to content

style: enable lots more Ruff lints, apply lint suggestions#1127

Merged
RoyalOughtness merged 5 commits intosecureblue:livefrom
HastD:ruff-lints
Jun 25, 2025
Merged

style: enable lots more Ruff lints, apply lint suggestions#1127
RoyalOughtness merged 5 commits intosecureblue:livefrom
HastD:ruff-lints

Conversation

@HastD
Copy link
Copy Markdown
Collaborator

@HastD HastD commented Jun 16, 2025

The enabled lints include many of the lints from Flake8, Pylint, Bandit, Pyupgrade, and mccabe (a cyclomatic complexity checker). Also simplified parse_config and factored out part of the parsing logic of the function parse_flatpak_permissions to reduce cyclomatic complexity of several functions, and fixed a small grammar issue with PermissionCheck.

@HastD HastD requested a review from RoyalOughtness as a code owner June 16, 2025 16:58
@HastD
Copy link
Copy Markdown
Collaborator Author

HastD commented Jun 19, 2025

I think it might make sense to disable Lizard in Codacy, as the mccabe cyclomatic complexity lint enabled by this PR seems to be computing complexity of Python code in a more sensible way. For example, Lizard is currently flagging parse_flatpak_permissions for supposedly having cyclomatic complexity 13—however, this is because it's counting list comprehensions as if they were for loops with a conditional inside them. If I were to replace

perms.session_bus_talk = [key for key, value in lines.items() if value == "talk"]

with the equivalent but much less readable

perms.session_bus_talk = list(map(lambda x: x[0], filter(lambda x: x[1] == "talk", lines.items())))

and likewise for the other similar list comprehensions in that function, its cyclomatic complexity as measured by Lizard would drop to 3.

@RoyalOughtness
Copy link
Copy Markdown
Collaborator

@HastD makes sense, as long as we're checking for it somewhere, that's fine by me

RoyalOughtness
RoyalOughtness previously approved these changes Jun 22, 2025
HastD added 4 commits June 23, 2025 08:14
The enabled lints include many of the lints from Flake8, Pylint, Bandit,
and Pyupgrade. Also factored out part of the parsing logic of the function
`parse_flatpak_permissions` to reduce cyclomatic complexity.

Signed-off-by: Daniel Hast <[email protected]>
This simplifies its usage and reduces complexity of several functions.
...and simplify audit_hardened_malloc so it passes the check.
"has" for single flatpaks, "have" when referring to multiple flatpaks
@RoyalOughtness RoyalOughtness merged commit 701f603 into secureblue:live Jun 25, 2025
17 of 18 checks passed
@HastD HastD deleted the ruff-lints branch June 25, 2025 22:50
RoyalOughtness pushed a commit to RoyalOughtness/secureblue-dev that referenced this pull request Aug 4, 2025
…e#1127)

* style: enable lots more Ruff lints, apply lint suggestions

The enabled lints include many of the lints from Flake8, Pylint, Bandit,
and Pyupgrade. Also factored out part of the parsing logic of the function
`parse_flatpak_permissions` to reduce cyclomatic complexity.

Signed-off-by: Daniel Hast <[email protected]>

* refactor: make parse_config return dict instead of generator

This simplifies its usage and reduces complexity of several functions.

* style: enable cyclomatic complexity checking in Ruff

...and simplify audit_hardened_malloc so it passes the check.

* fix: grammar issue in flatpak permissions checks

"has" for single flatpaks, "have" when referring to multiple flatpaks

---------

Signed-off-by: Daniel Hast <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants