Skip to content

Ruff rules SIM for simplification #337

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

Merged
merged 1 commit into from
Mar 15, 2025

Conversation

cclauss
Copy link
Member

@cclauss cclauss commented Mar 12, 2025

@cclauss cclauss force-pushed the ruff-rules-SIM-for-simplification branch from f6df434 to 3cd4953 Compare March 12, 2025 21:06
Comment on lines -4764 to +4763
if keyword := re.search(
r"\b(else if|if|while|for|switch)" # These have parens
r"\s*\(.*\)\s*(?:\[\[(?:un)?likely\]\]\s*)?{\s*[^\s\\};]",
line,
):
error(
filename,
linenum,
"whitespace/newline",
5,
f"Controlled statements inside brackets of {keyword.group(1)} clause"
" should be on a separate line",
if (
keyword := re.search(
r"\b(else if|if|while|for|switch)" # These have parens
r"\s*\(.*\)\s*(?:\[\[(?:un)?likely\]\]\s*)?{\s*[^\s\\};]",
line,
)
) or (
keyword := re.search(
r"\b(else|do|try)" # These don't have parens
r"\s*(?:\[\[(?:un)?likely\]\]\s*)?{\s*[^\s\\}]",
line,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why it put everything in brackets...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment Operator may require parentheses. Also there is a RUF rule that adds parens to clarify precedence between and, or, not.

@aaronliu0130 aaronliu0130 merged commit af30092 into develop Mar 15, 2025
10 checks passed
@cclauss cclauss deleted the ruff-rules-SIM-for-simplification branch March 15, 2025 05:49
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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy