Skip to content

Commit

Permalink
Fix current RuboCop offenses (#350)
Browse files Browse the repository at this point in the history
```
Offenses:

lib/rubocop/ast/node/mixin/predicate_operator_node.rb:28:9: C: [Correctable] Style/MultipleComparison: Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
        operator == LOGICAL_AND || operator == LOGICAL_OR
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/node/mixin/predicate_operator_node.rb:35:9: C: [Correctable] Style/MultipleComparison: Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
        operator == SEMANTIC_AND || operator == SEMANTIC_OR
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/ast/token.rb:86:9: C: [Correctable] Style/MultipleComparison: Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
        type == :tLCURLY || type == :tLAMBEG
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

Although these constants are private, they are referenced in `OrNode` and `AndNode`
  • Loading branch information
Earlopain authored Dec 28, 2024
1 parent 4529384 commit 538dc2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/rubocop/ast/node/mixin/predicate_operator_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ module PredicateOperatorNode
SEMANTIC_OR = 'or'
private_constant :SEMANTIC_OR

LOGICAL_OPERATORS = [LOGICAL_AND, LOGICAL_OR].freeze
private_constant :LOGICAL_OPERATORS
SEMANTIC_OPERATORS = [SEMANTIC_AND, SEMANTIC_OR].freeze
private_constant :SEMANTIC_OPERATORS

# Returns the operator as a string.
#
# @return [String] the operator
Expand All @@ -25,14 +30,14 @@ def operator
#
# @return [Boolean] whether this is a logical operator
def logical_operator?
operator == LOGICAL_AND || operator == LOGICAL_OR
LOGICAL_OPERATORS.include?(operator)
end

# Checks whether this is a semantic operator.
#
# @return [Boolean] whether this is a semantic operator
def semantic_operator?
operator == SEMANTIC_AND || operator == SEMANTIC_OR
SEMANTIC_OPERATORS.include?(operator)
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/ast/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module AST
# A basic wrapper around Parser's tokens.
class Token
LEFT_PAREN_TYPES = %i[tLPAREN tLPAREN2].freeze
LEFT_CURLY_TYPES = %i[tLCURLY tLAMBEG].freeze

attr_reader :pos, :type, :text

Expand Down Expand Up @@ -83,7 +84,7 @@ def left_brace?
end

def left_curly_brace?
type == :tLCURLY || type == :tLAMBEG
LEFT_CURLY_TYPES.include?(type)
end

def right_curly_brace?
Expand Down

0 comments on commit 538dc2b

Please sign in to comment.