Skip to content

WPS366: forbid useless bool expressions#3605

Merged
sobolevn merged 4 commits intowemake-services:masterfrom
j2cry:issue-3593-2
Feb 23, 2026
Merged

WPS366: forbid useless bool expressions#3605
sobolevn merged 4 commits intowemake-services:masterfrom
j2cry:issue-3593-2

Conversation

@j2cry
Copy link
Copy Markdown
Contributor

@j2cry j2cry commented Feb 22, 2026

I have made things!

This adds a new rule WPS366 which disallows useless boolean operations.
It partially coincides with the ruff's SIM223, but complements it.

Checklist

  • I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
  • I have created at least one test case for the changes I have made
  • I have updated the documentation for the changes I have made
  • I have added my changes to the CHANGELOG.md

Related issues

Closes #3593

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (bf05af9) to head (e76fe3a).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #3605   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          368       369    +1     
  Lines        12291     12335   +44     
  Branches       853       858    +5     
=========================================
+ Hits         12291     12335   +44     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Forbid meaningless boolean operations.

Reasoning:
Some parts of a boolean expression may be redundant,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please, describe what parts are redundant and why :)

if is_zero_division:
self.add_violation(consistency.ZeroDivisionViolation(number))

def _check_useless_bool_operator( # noqa: WPS210
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please, do not ignore complexity violations. Refactor this function into several helper ones

Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Awesome, let's try it out!

@sobolevn sobolevn merged commit f13e702 into wemake-services:master Feb 23, 2026
10 checks passed
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.

Useless logical and bitwise operations

2 participants