Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Ruby 2.4 support #9648

Merged
merged 3 commits into from Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 1 addition & 30 deletions .circleci/config.yml
Expand Up @@ -46,29 +46,6 @@ rubocop_steps: &rubocop_steps

jobs:

# Ruby 2.4
ruby-2.4-spec:
docker:
- image: circleci/ruby:2.4
environment:
<<: *common_env
steps:
*spec_steps
ruby-2.4-ascii_spec:
docker:
- image: circleci/ruby:2.4
environment:
<<: *common_env
steps:
*ascii_spec_steps
ruby-2.4-rubocop:
docker:
- image: circleci/ruby:2.4
environment:
<<: *common_env
steps:
*rubocop_steps

# Ruby 2.5
ruby-2.5-spec:
docker:
Expand Down Expand Up @@ -242,7 +219,7 @@ jobs:
- run:
name: Upload coverage results to Code Climate
command: |
./tmp/cc-test-reporter sum-coverage tmp/codeclimate.*.json --parts 6 --output tmp/codeclimate.total.json
./tmp/cc-test-reporter sum-coverage tmp/codeclimate.*.json --parts 5 --output tmp/codeclimate.total.json
./tmp/cc-test-reporter upload-coverage --input tmp/codeclimate.total.json

# Miscellaneous tasks
Expand All @@ -264,11 +241,6 @@ workflows:
jobs:
- documentation-checks
- cc-setup
- ruby-2.4-spec:
requires:
- cc-setup
- ruby-2.4-ascii_spec
- ruby-2.4-rubocop
- ruby-2.5-spec:
requires:
- cc-setup
Expand Down Expand Up @@ -302,7 +274,6 @@ workflows:

- cc-upload-coverage:
requires:
- ruby-2.4-spec
- ruby-2.5-spec
- ruby-2.6-spec
- ruby-2.7-spec
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rubocop.yml
Expand Up @@ -21,7 +21,7 @@ jobs:
matrix:
# [ ubuntu, macos, windows ]
os: [ windows ]
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0', 'head' ]
ruby: [ '2.5', '2.6', '2.7', '3.0', 'head' ]
include:
- { os: windows, ruby: mingw }
exclude:
Expand Down
4 changes: 0 additions & 4 deletions .mergify.yml
Expand Up @@ -8,7 +8,6 @@ pull_request_rules:
- label=auto-merge
- "#review-requested=0"
- "#changes-requested-reviews-by=0"
- "status-success=windows 2.4"
- "status-success=windows 2.5"
- "status-success=windows 2.6"
- "status-success=windows 2.7"
Expand All @@ -20,9 +19,6 @@ pull_request_rules:
- "status-success=ci/circleci: jruby-9.2-ascii_spec"
- "status-success=ci/circleci: jruby-9.2-rubocop"
- "status-success=ci/circleci: jruby-9.2-spec"
- "status-success=ci/circleci: ruby-2.4-ascii_spec"
- "status-success=ci/circleci: ruby-2.4-rubocop"
- "status-success=ci/circleci: ruby-2.4-spec"
- "status-success=ci/circleci: ruby-2.5-ascii_spec"
- "status-success=ci/circleci: ruby-2.5-rubocop"
- "status-success=ci/circleci: ruby-2.5-spec"
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -14,7 +14,7 @@ AllCops:
- 'tmp/**/*'
- '.git/**/*'
- 'bin/*'
TargetRubyVersion: 2.4
TargetRubyVersion: 2.5
SuggestExtensions: false

Naming/PredicateName:
Expand Down
8 changes: 1 addition & 7 deletions Gemfile
Expand Up @@ -5,13 +5,7 @@ source 'https://rubygems.org'
gemspec

gem 'bump', require: false
# memory_profiler 1.0.0 requires Ruby 2.5.0 or higher.
# Please remove this branch when dropping support for Ruby 2.4.
if RUBY_VERSION >= '2.5.0'
gem 'memory_profiler', platform: :mri
else
gem 'memory_profiler', '<= 1.0.0', platform: :mri
end
gem 'memory_profiler', platform: :mri
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.7'
gem 'rubocop-performance', '~> 1.10.0'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -73,7 +73,7 @@ You can read a lot more about RuboCop in its [official docs](https://docs.ruboco

RuboCop officially supports the following Ruby implementations:

* MRI 2.4+
* MRI 2.5+
* JRuby 9.2+

See the [compatibility documentation](https://docs.rubocop.org/rubocop/compatibility.html) for further details.
Expand Down
50 changes: 24 additions & 26 deletions Rakefile
Expand Up @@ -103,32 +103,30 @@ task documentation_syntax_check: :yard_for_generate_documentation do
end

examples.each do |example|
begin
buffer = Parser::Source::Buffer.new('<code>', 1)
buffer.source = example.text

# Ruby 2.6 or higher does not support a syntax used in
# `Lint/UselessElseWithoutRescue` cop's example.
parser = if cop == RuboCop::Cop::Lint::UselessElseWithoutRescue
Parser::Ruby25.new(RuboCop::AST::Builder.new)
# Ruby 2.7 raises a syntax error in
# `Lint/CircularArgumentReference` cop's example.
elsif cop == RuboCop::Cop::Lint::CircularArgumentReference
Parser::Ruby26.new(RuboCop::AST::Builder.new)
# Ruby 3.0 raises a syntax error in
# `Lint/NumberedParameterAssignment` cop's example.
elsif cop == RuboCop::Cop::Lint::NumberedParameterAssignment
Parser::Ruby27.new(RuboCop::AST::Builder.new)
else
Parser::Ruby30.new(RuboCop::AST::Builder.new)
end
parser.diagnostics.all_errors_are_fatal = true
parser.parse(buffer)
rescue Parser::SyntaxError => e
path = example.object.file
puts "#{path}: Syntax Error in an example. #{e}"
ok = false
end
buffer = Parser::Source::Buffer.new('<code>', 1)
buffer.source = example.text

# Ruby 2.6 or higher does not support a syntax used in
# `Lint/UselessElseWithoutRescue` cop's example.
parser = if cop == RuboCop::Cop::Lint::UselessElseWithoutRescue
Parser::Ruby25.new(RuboCop::AST::Builder.new)
# Ruby 2.7 raises a syntax error in
# `Lint/CircularArgumentReference` cop's example.
elsif cop == RuboCop::Cop::Lint::CircularArgumentReference
Parser::Ruby26.new(RuboCop::AST::Builder.new)
# Ruby 3.0 raises a syntax error in
# `Lint/NumberedParameterAssignment` cop's example.
elsif cop == RuboCop::Cop::Lint::NumberedParameterAssignment
Parser::Ruby27.new(RuboCop::AST::Builder.new)
else
Parser::Ruby30.new(RuboCop::AST::Builder.new)
end
parser.diagnostics.all_errors_are_fatal = true
parser.parse(buffer)
rescue Parser::SyntaxError => e
path = example.object.file
puts "#{path}: Syntax Error in an example. #{e}"
ok = false
end
end
abort unless ok
Expand Down
1 change: 1 addition & 0 deletions changelog/change_drop_ruby_24.md
@@ -0,0 +1 @@
* [#9647](https://github.com/rubocop/rubocop/pull/9647): Drop support for Ruby 2.4. ([@koic][])
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/compatibility.adoc
@@ -1,10 +1,10 @@
= Compatibility

RuboCop targets Ruby 2.4+.footnote:[As defined by its reference implementation MRI.]
RuboCop targets Ruby 2.5+.footnote:[As defined by its reference implementation MRI.]

RuboCop officially supports MRI (a.k.a. CRuby) and JRuby.

- MRI 2.4+
- MRI 2.5+
- JRuby 9.2+

The oldest supported JRuby version is derived from the oldest compatible MRI version.
Expand All @@ -14,7 +14,7 @@ NOTE: RuboCop might be working with other Ruby implementations as well, but it's
== Support Matrix

RuboCop generally aims to follow MRI's own support policy - meaning RuboCop would support all officially supported MRI releases.footnote:[Typically the last 3 releases.] To give people extra time for a smooth transition, we've customarily provided support for about one year after EOL of MRI version.
This means that if Ruby 2.4 reaches its EOL in Spring 2020, it would be supported by RuboCop (at least) until Spring 2021.footnote:[At the core team's discretion this policy might be waived aside for MRI releases causing significant maintenance overhead.]
This means that if Ruby 2.5 reaches its EOL in Spring 2021, it would be supported by RuboCop (at least) until Spring 2022.footnote:[At the core team's discretion this policy might be waived aside for MRI releases causing significant maintenance overhead.]

The following table is the support matrix.

Expand All @@ -26,7 +26,7 @@ The following table is the support matrix.
| 2.1 | 0.57
| 2.2 | 0.68
| 2.3 | 0.81
| 2.4 | -
| 2.4 | 1.12
| 2.5 | -
| 2.6 | -
| 2.7 | -
Expand Down
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/formatters.adoc
Expand Up @@ -205,11 +205,11 @@ The JSON structure is like the following example:
----
{
"metadata": {
"rubocop_version": "0.50.0",
"rubocop_version": "1.12.0",
"ruby_engine": "ruby",
"ruby_version": "2.4.2",
"ruby_patchlevel": "198",
"ruby_platform": "x86_64-darwin12.3.0"
"ruby_version": "3.0.0",
"ruby_patchlevel": "0",
"ruby_platform": "x86_64-darwin19"
},
"files": [{
"path": "lib/foo.rb",
Expand Down
1 change: 0 additions & 1 deletion lib/rubocop.rb
Expand Up @@ -18,7 +18,6 @@
require_relative 'rubocop/ext/regexp_parser'

require_relative 'rubocop/core_ext/string'
require_relative 'rubocop/core_ext/hash'
require_relative 'rubocop/ext/processed_source'

require_relative 'rubocop/path_util'
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/comment_config.rb
Expand Up @@ -32,9 +32,7 @@ def extra_enabled_comments
end

def comment_only_line?(line_number)
non_comment_token_line_numbers.none? do |non_comment_line_number|
non_comment_line_number == line_number
end
non_comment_token_line_numbers.none?(line_number)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have a cop for this and any? already?

Copy link
Member Author

Choose a reason for hiding this comment

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

end

private
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/generator/require_file_injector.rb
Expand Up @@ -29,9 +29,7 @@ def inject
attr_reader :require_entries, :root_file_path, :source_path, :output

def require_exists?
require_entries.any? do |entry|
entry == injectable_require_directive
end
require_entries.any?(injectable_require_directive)
end

def updated_directives
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/cop/lint/shadowed_exception.rb
Expand Up @@ -111,6 +111,9 @@ def evaluate_exceptions(group)

if rescued_exceptions.any?
rescued_exceptions.each_with_object([]) do |exception, converted|
# FIXME: Workaround `rubocop:disable` comment for JRuby.
# https://github.com/jruby/jruby/issues/6642
# rubocop:disable Style/RedundantBegin
begin
RuboCop::Util.silence_warnings do
# Avoid printing deprecation warnings about constants
Expand All @@ -119,6 +122,7 @@ def evaluate_exceptions(group)
rescue NameError
converted << nil
end
# rubocop:enable Style/RedundantBegin
end
else
# treat an empty `rescue` as `rescue StandardError`
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/symbol_conversion.rb
Expand Up @@ -152,7 +152,7 @@ def correct_hash_key(node)
# will be ignored.
return unless node.value.to_s.match?(/\A[a-z0-9_]/i)

correction = node.value.inspect.gsub(/\A:/, '')
correction = node.value.inspect.delete_prefix(':')
return if properly_quoted?(node.source, correction)

register_offense(
Expand Down
3 changes: 1 addition & 2 deletions lib/rubocop/cop/mixin/method_preference.rb
Expand Up @@ -18,8 +18,7 @@ def preferred_methods
default = default_cop_config['PreferredMethods']
merged = cop_config['PreferredMethods']
overrides = merged.values - default.values
merged.reject { |key, _| overrides.include?(key) }
.map { |k, v| [k.to_sym, v] }.to_h
merged.reject { |key, _| overrides.include?(key) }.transform_keys(&:to_sym)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/naming/memoized_instance_variable_name.rb
Expand Up @@ -260,7 +260,7 @@ def suggested_var(method_name)
end

def variable_name_candidates(method_name)
no_underscore = method_name.sub(/\A_/, '')
no_underscore = method_name.delete_prefix('_')
with_underscore = "_#{method_name}"
case style
when :required
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/hash_syntax.rb
Expand Up @@ -137,7 +137,7 @@ def word_symbol_pair?(pair)
end

def acceptable_19_syntax_symbol?(sym_name)
sym_name.sub!(/\A:/, '')
sym_name.delete_prefix!(':')

if cop_config['PreferHashRocketsForNonAlnumEndingSymbols'] &&
# Prefer { :production? => false } over { production?: false } and
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/multiple_comparison.rb
Expand Up @@ -142,7 +142,7 @@ def root_of_or_node(or_node)
def switch_comparison?(node)
return true if @last_comparison.nil?

@last_comparison.descendants.none? { |descendant| descendant == node }
@last_comparison.descendants.none?(node)
end

def reset_comparison
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/nested_ternary_operator.rb
Expand Up @@ -51,7 +51,7 @@ def if_node(node)
def remove_parentheses(source)
return source unless source.start_with?('(')

source.gsub(/\A\(/, '').gsub(/\)\z/, '')
source.delete_prefix('(').delete_suffix(')')
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/cop/style/parallel_assignment.rb
Expand Up @@ -164,9 +164,12 @@ def dependency?(lhs, rhs)
# Does `rhs` access the same value which is assigned by `lhs`?
def accesses?(rhs, lhs)
if lhs.method?(:[]=)
# FIXME: Workaround `rubocop:disable` comment for JRuby.
# rubocop:disable Performance/RedundantEqualityComparisonBlock
matching_calls(rhs, lhs.receiver, :[]).any? do |args|
args == lhs.arguments
end
# rubocop:enable Performance/RedundantEqualityComparisonBlock
else
access_method = lhs.method_name.to_s.chop.to_sym
matching_calls(rhs, lhs.receiver, access_method).any?
Expand Down
3 changes: 0 additions & 3 deletions lib/rubocop/cop/style/redundant_begin.rb
Expand Up @@ -36,7 +36,6 @@ module Style
# do_something
#
# # bad
# # When using Ruby 2.5 or later.
# do_something do
# begin
# something
Expand Down Expand Up @@ -76,8 +75,6 @@ def on_def(node)
alias on_defs on_def

def on_block(node)
return if target_ruby_version < 2.5

return if node.send_node.lambda_literal?
return if node.braces?
return unless node.body&.kwbegin_type?
Expand Down
Expand Up @@ -40,7 +40,7 @@ def on_send(node)
return unless name_node.value.end_with?('.rb')

add_offense(name_node) do |corrector|
correction = name_node.value.sub(/\.rb\z/, '')
correction = name_node.value.delete_suffix('.rb')

corrector.replace(name_node, "'#{correction}'")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/redundant_return.rb
Expand Up @@ -73,7 +73,7 @@ def correct_with_arguments(return_node, corrector)
end
if return_node.splat_argument?
first_argument = return_node.first_argument
corrector.replace(first_argument, first_argument.source.gsub(/\A\*/, ''))
corrector.replace(first_argument, first_argument.source.delete_prefix('*'))
end

keyword = range_with_surrounding_space(range: return_node.loc.keyword,
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/style/unless_logical_operators.rb
Expand Up @@ -90,14 +90,14 @@ def mixed_precedence_and?(node)
and_sources = node.condition.each_descendant(:and).map(&:operator)
and_sources << node.condition.operator if node.condition.and_type?

!(and_sources.all? { |s| s == '&&' } || and_sources.all? { |s| s == 'and' })
!(and_sources.all?('&&') || and_sources.all?('and'))
end

def mixed_precedence_or?(node)
or_sources = node.condition.each_descendant(:or).map(&:operator)
or_sources << node.condition.operator if node.condition.or_type?

!(or_sources.all? { |s| s == '||' } || or_sources.all? { |s| s == 'or' })
!(or_sources.all?('||') || or_sources.all?('or'))
end
end
end
Expand Down