Skip to content

Commit

Permalink
[Fix #6945] Drop support for Ruby 2.2
Browse files Browse the repository at this point in the history
Fixes #6945.

By convention, a year after Ruby became an EOL, it seems that the old
Ruby version support has been dropped. I'm not sure if it's good to drop
Ruby 2.3 support, but it's good time to drop Ruby 2.2 support.
  • Loading branch information
koic authored and bbatsov committed May 8, 2019
1 parent 0e6eb31 commit d22907d
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 42 deletions.
4 changes: 2 additions & 2 deletions lib/rubocop/ast/node.rb
Expand Up @@ -464,11 +464,11 @@ def call_type?
end

def chained?
parent && parent.call_type? && eql?(parent.receiver)
parent&.call_type? && eql?(parent.receiver)
end

def argument?
parent && parent.send_type? && parent.arguments.include?(self)
parent&.send_type? && parent.arguments.include?(self)
end

def numeric_type?
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/ast/node/array_node.rb
Expand Up @@ -22,7 +22,7 @@ def values
#
# @return [Boolean] whether the array is enclosed in square brackets
def square_brackets?
loc.begin && loc.begin.is?('[')
loc.begin&.is?('[')
end

# Checks whether the `array` literal is delimited by percent brackets.
Expand All @@ -40,7 +40,7 @@ def percent_literal?(type = nil)
if type
loc.begin && loc.begin.source =~ PERCENT_LITERAL_TYPES[type]
else
loc.begin && loc.begin.source.start_with?('%')
loc.begin&.source&.start_with?('%')
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/ast/node/block_node.rb
Expand Up @@ -50,14 +50,14 @@ def arguments?
#
# @return [Boolean] whether the `block` literal is enclosed in braces
def braces?
loc.end && loc.end.is?('}')
loc.end&.is?('}')
end

# Checks whether the `block` literal is delimited by `do`-`end` keywords.
#
# @return [Boolean] whether the `block` literal is enclosed in `do`-`end`
def keywords?
loc.end && loc.end.is?('end')
loc.end&.is?('end')
end

# The delimiters for this `block` literal.
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/for_node.rb
Expand Up @@ -17,7 +17,7 @@ def keyword
#
# @return [Boolean] whether the `for` node has a `do` keyword
def do?
loc.begin && loc.begin.is?('do')
loc.begin&.is?('do')
end

# Checks whether this node body is a void context.
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/hash_node.rb
Expand Up @@ -102,7 +102,7 @@ def mixed_delimiters?
#
# @return [Boolean] whether the `hash` literal is enclosed in braces
def braces?
loc.end && loc.end.is?('}')
loc.end&.is?('}')
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/if_node.rb
Expand Up @@ -103,7 +103,7 @@ def nested_conditional?
#
# @return [Boolean] whether the `if` node has at least one `elsif` branch
def elsif_conditional?
else_branch && else_branch.if_type? && else_branch.elsif?
else_branch&.if_type? && else_branch&.elsif?
end

# Returns the branch of the `if` node that gets evaluated when its
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/keyword_splat_node.rb
Expand Up @@ -8,7 +8,7 @@ module AST
class KeywordSplatNode < Node
include HashElementNode

DOUBLE_SPLAT = '**'.freeze
DOUBLE_SPLAT = '**'

# This is used for duck typing with `pair` nodes which also appear as
# `hash` elements.
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Expand Up @@ -116,7 +116,7 @@ def double_colon?
#
# @return [Boolean] whether the receiver of this method dispatch is `self`
def self_receiver?
receiver && receiver.self_type?
receiver&.self_type?
end

# Checks whether the *explicit* receiver of this method dispatch is a
Expand All @@ -125,7 +125,7 @@ def self_receiver?
# @return [Boolean] whether the receiver of this method dispatch
# is a `const` node
def const_receiver?
receiver && receiver.const_type?
receiver&.const_type?
end

# Checks whether the method dispatch is the implicit form of `#call`,
Expand All @@ -140,7 +140,7 @@ def implicit_call?
#
# @return [Boolean] whether the dispatched method has a block
def block_literal?
parent && parent.block_type? && eql?(parent.send_node)
parent&.block_type? && eql?(parent.send_node)
end

# Checks whether this node is an arithmetic operation
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/ast/node/mixin/method_identifier_predicates.rb
Expand Up @@ -79,14 +79,14 @@ def camel_case_method?
#
# @return [Boolean] whether the receiver of this node is `self`
def self_receiver?
receiver && receiver.self_type?
receiver&.self_type?
end

# Checks whether the *explicit* receiver of node is a `const` node.
#
# @return [Boolean] whether the receiver of this node is a `const` node
def const_receiver?
receiver && receiver.const_type?
receiver&.const_type?
end

# Checks whether this is a negation method, i.e. `!` or keyword `not`.
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/mixin/parameterized_node.rb
Expand Up @@ -10,7 +10,7 @@ module ParameterizedNode
# @return [Boolean] whether this node's arguments are
# wrapped in parentheses
def parenthesized?
loc.end && loc.end.is?(')')
loc.end&.is?(')')
end

# A shorthand for getting the first argument of the node.
Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/ast/node/mixin/predicate_operator_node.rb
Expand Up @@ -5,10 +5,10 @@ module AST
# Common functionality for nodes that are predicates:
# `or`, `and` ...
module PredicateOperatorNode
LOGICAL_AND = '&&'.freeze
SEMANTIC_AND = 'and'.freeze
LOGICAL_OR = '||'.freeze
SEMANTIC_OR = 'or'.freeze
LOGICAL_AND = '&&'
SEMANTIC_AND = 'and'
LOGICAL_OR = '||'
SEMANTIC_OR = 'or'

# Returns the operator as a string.
#
Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/ast/node/pair_node.rb
Expand Up @@ -8,10 +8,10 @@ module AST
class PairNode < Node
include HashElementNode

HASH_ROCKET = '=>'.freeze
SPACED_HASH_ROCKET = ' => '.freeze
COLON = ':'.freeze
SPACED_COLON = ': '.freeze
HASH_ROCKET = '=>'
SPACED_HASH_ROCKET = ' => '
COLON = ':'
SPACED_COLON = ': '

# Checks whether the `pair` uses a hash rocket delimiter.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/until_node.rb
Expand Up @@ -28,7 +28,7 @@ def inverse_keyword
#
# @return [Boolean] whether the `until` node has a `do` keyword
def do?
loc.begin && loc.begin.is?('do')
loc.begin&.is?('do')
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/when_node.rb
Expand Up @@ -39,7 +39,7 @@ def branch_index
#
# @return [Boolean] whether the `when` node has a `then` keyword
def then?
loc.begin && loc.begin.is?('then')
loc.begin&.is?('then')
end

# Returns the body of the `when` node.
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/while_node.rb
Expand Up @@ -28,7 +28,7 @@ def inverse_keyword
#
# @return [Boolean] whether the `until` node has a `do` keyword
def do?
loc.begin && loc.begin.is?('do')
loc.begin&.is?('do')
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/rubocop/node_pattern.rb
Expand Up @@ -127,18 +127,18 @@ class Compiler
PARAM = /\A#{PARAM_NUMBER}\Z/.freeze
CLOSING = /\A(?:\)|\}|\])\Z/.freeze

REST = '...'.freeze
CAPTURED_REST = '$...'.freeze
REST = '...'
CAPTURED_REST = '$...'

attr_reader :match_code, :tokens, :captures

SEQ_HEAD_INDEX = -1

# Placeholders while compiling, see with_..._context methods
CUR_PLACEHOLDER = '@@@cur'.freeze
CUR_NODE = "#{CUR_PLACEHOLDER} node@@@".freeze
CUR_ELEMENT = "#{CUR_PLACEHOLDER} element@@@".freeze
SEQ_HEAD_GUARD = '@@@seq guard head@@@'.freeze
CUR_PLACEHOLDER = '@@@cur'
CUR_NODE = "#{CUR_PLACEHOLDER} node@@@"
CUR_ELEMENT = "#{CUR_PLACEHOLDER} element@@@"
SEQ_HEAD_GUARD = '@@@seq guard head@@@'

line = __LINE__
ANY_ORDER_TEMPLATE = ERB.new <<-RUBY.strip_indent.gsub("-%>\n", '%>')
Expand Down Expand Up @@ -176,7 +176,7 @@ def run(node_var)

@match_code = with_context(compile_expr, node_var, use_temp_node: false)
@match_code.prepend("(captures = Array.new(#{@captures})) && ") \
if @captures > 0
if @captures.positive?

fail_due_to('unbalanced pattern') unless tokens.empty?
end
Expand Down Expand Up @@ -334,7 +334,7 @@ def compile_variadic_term
def variadic_arity
return unless @variadic_index

first = @variadic_index > 0 ? first_terms_arity : SEQ_HEAD_INDEX
first = @variadic_index.positive? ? first_terms_arity : SEQ_HEAD_INDEX
yield first..-last_terms_arity - 1
end
end
Expand Down
8 changes: 3 additions & 5 deletions lib/rubocop/processed_source.rb
Expand Up @@ -7,7 +7,7 @@ module RuboCop
# and other information such as disabled lines for cops.
# It also provides a convenient way to access source lines.
class ProcessedSource
STRING_SOURCE_NAME = '(string)'.freeze
STRING_SOURCE_NAME = '(string)'

attr_reader :path, :buffer, :ast, :comments, :tokens, :diagnostics,
:parser_error, :raw_source, :ruby_version
Expand Down Expand Up @@ -157,7 +157,8 @@ def parse(source, ruby_version)
def tokenize(parser)
begin
ast, comments, tokens = parser.tokenize(@buffer)
ast.complete! if ast

ast.respond_to?(:complete!) && ast.complete!

This comment has been minimized.

Copy link
@marcandre

marcandre Jul 22, 2020

Contributor

Note: The fact that ast can be false is a bug due to an error in racc... Accept no compromise 😅

rescue Parser::SyntaxError # rubocop:disable Lint/HandleExceptions
# All errors are in diagnostics. No need to handle exception.
end
Expand All @@ -170,9 +171,6 @@ def tokenize(parser)
# rubocop:disable Metrics/MethodLength
def parser_class(ruby_version)
case ruby_version
when 2.2
require 'parser/ruby22'
Parser::Ruby22
when 2.3
require 'parser/ruby23'
Parser::Ruby23
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/node_pattern_spec.rb
Expand Up @@ -512,7 +512,7 @@
end

context 'on a node which meets all requirements of the second []' do
let(:ruby) { '2.2' }
let(:ruby) { '2.3' }

it_behaves_like 'matching'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/processed_source_spec.rb
Expand Up @@ -98,7 +98,7 @@ def some_method
# lacking an encoding comment will default to the external encoding,
# which could for example be US-ASCII if the LC_ALL environment
# variable is set to "C".
'号码 = 3'.dup.force_encoding('US-ASCII')
(+'号码 = 3').force_encoding('US-ASCII')
end

it 'is nil' do
Expand Down

0 comments on commit d22907d

Please sign in to comment.