Skip to content

Commit

Permalink
[fixes rubocop#22] Use Sets instead of Arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Jun 7, 2020
1 parent bf04f35 commit 4fd84e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
38 changes: 19 additions & 19 deletions lib/rubocop/ast/node.rb
Expand Up @@ -23,36 +23,36 @@ class Node < Parser::AST::Node # rubocop:disable Metrics/ClassLength
extend NodePattern::Macros

# <=> isn't included here, because it doesn't return a boolean.
COMPARISON_OPERATORS = %i[== === != <= >= > <].freeze
COMPARISON_OPERATORS = %i[== === != <= >= > <].to_set.freeze

TRUTHY_LITERALS = %i[str dstr xstr int float sym dsym array
hash regexp true irange erange complex
rational regopt].freeze
FALSEY_LITERALS = %i[false nil].freeze
LITERALS = (TRUTHY_LITERALS + FALSEY_LITERALS).freeze
rational regopt].to_set.freeze
FALSEY_LITERALS = %i[false nil].to_set.freeze
LITERALS = (TRUTHY_LITERALS + FALSEY_LITERALS).to_set.freeze
COMPOSITE_LITERALS = %i[dstr xstr dsym array hash irange
erange regexp].freeze
BASIC_LITERALS = (LITERALS - COMPOSITE_LITERALS).freeze
erange regexp].to_set.freeze
BASIC_LITERALS = (LITERALS - COMPOSITE_LITERALS).to_set.freeze
MUTABLE_LITERALS = %i[str dstr xstr array hash
regexp irange erange].freeze
IMMUTABLE_LITERALS = (LITERALS - MUTABLE_LITERALS).freeze
regexp irange erange].to_set.freeze
IMMUTABLE_LITERALS = (LITERALS - MUTABLE_LITERALS).to_set.freeze

EQUALS_ASSIGNMENTS = %i[lvasgn ivasgn cvasgn gvasgn
casgn masgn].freeze
SHORTHAND_ASSIGNMENTS = %i[op_asgn or_asgn and_asgn].freeze
ASSIGNMENTS = (EQUALS_ASSIGNMENTS + SHORTHAND_ASSIGNMENTS).freeze

BASIC_CONDITIONALS = %i[if while until].freeze
CONDITIONALS = [*BASIC_CONDITIONALS, :case].freeze
VARIABLES = %i[ivar gvar cvar lvar].freeze
REFERENCES = %i[nth_ref back_ref].freeze
casgn masgn].to_set.freeze
SHORTHAND_ASSIGNMENTS = %i[op_asgn or_asgn and_asgn].to_set.freeze
ASSIGNMENTS = (EQUALS_ASSIGNMENTS + SHORTHAND_ASSIGNMENTS).to_set.freeze

BASIC_CONDITIONALS = %i[if while until].to_set.freeze
CONDITIONALS = [*BASIC_CONDITIONALS, :case].to_set.freeze
VARIABLES = %i[ivar gvar cvar lvar].to_set.freeze
REFERENCES = %i[nth_ref back_ref].to_set.freeze
KEYWORDS = %i[alias and break case class def defs defined?
kwbegin do else ensure for if module next
not or postexe redo rescue retry return self
super zsuper then undef until when while
yield].freeze
OPERATOR_KEYWORDS = %i[and or].freeze
SPECIAL_KEYWORDS = %w[__FILE__ __LINE__ __ENCODING__].freeze
yield].to_set.freeze
OPERATOR_KEYWORDS = %i[and or].to_set.freeze
SPECIAL_KEYWORDS = %w[__FILE__ __LINE__ __ENCODING__].to_set.freeze

# @see https://www.rubydoc.info/gems/ast/AST/Node:initialize
def initialize(type, children = [], properties = {})
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
Expand Up @@ -10,11 +10,11 @@ module MethodIdentifierPredicates
ENUMERATOR_METHODS = %i[collect collect_concat detect downto each
find find_all find_index inject loop map!
map reduce reject reject! reverse_each select
select! times upto].freeze
select! times upto].to_set.freeze

# http://phrogz.net/programmingruby/language.html#table_18.4
OPERATOR_METHODS = %i[| ^ & <=> == === =~ > >= < <= << >> + - * /
% ** ~ +@ -@ !@ ~@ [] []= ! != !~ `].freeze
% ** ~ +@ -@ !@ ~@ [] []= ! != !~ `].to_set.freeze

# Checks whether the method name matches the argument.
#
Expand Down

0 comments on commit 4fd84e5

Please sign in to comment.