Enable Style/UnlessLogicalOperators RuboCop rule
Description of the proposal
Checks for the use of logical operators in an unless condition. It discourages such code, as the condition becomes more difficult to read and understand.
Ref to the docs to read more about this cop https://docs.rubocop.org/rubocop/cops_style.html#styleunlesslogicaloperators.
Examples
🅰️ EnforcedStyle: forbid_mixed_logical_operators
# bad
return unless a || b && c
return unless a && b || c
return unless a && b and c
return unless a || b or c
return unless a && b or c
return unless a || b and c
# good
return unless a && b && c
return unless a || b || c
return unless a and b and c
return unless a or b or c
return unless a?
🅱️ EnforcedStyle: forbid_logical_operators
# bad
return unless a || b
return unless a && b
return unless a or b
return unless a and b
# good
return unless a
return unless a?
Impact on gitlab-org/gitlab
# With EnforcedStyle: forbid_mixed_logical_operators
rubocop --only Style/UnlessLogicalOperators
46289 files inspected, 22 offenses detected
# With EnforcedStyle: forbid_logical_operators
rubocop --only Style/UnlessLogicalOperators
46289 files inspected, 1517 offenses detected
Check-list
-
Mention this proposal in the relevant Slack channels (e.g. #development
,#backend
,#frontend
) -
If there is a choice to make between two potential styles, set up an emoji vote in the MR: - CHOICE_A:
🅰️ - CHOICE_B:
🅱️ - Vote yourself for both choices so that people know these are the choices
- CHOICE_A:
-
The MR doesn't have significant objections, and is getting a majority of 👍 vs👎 (remember that we don't need to reach a consensus) -
(If applicable) One style is getting a majority of vote (compared to the other choice) -
(If applicable) Update the MR with the chosen style -
Follow the review process as usual
@gitlab-org/maintainers/rails-backend you can vote for choice
Edited by David Dieulivol