KEMBAR78
Ruff rules SIM for simplification by cclauss · Pull Request #337 · cpplint/cpplint · GitHub
Skip to content

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