Skip to content

Commit

Permalink
Make Lint/RedundantRequireStatement mark set as a redundant require i…
Browse files Browse the repository at this point in the history
…n Ruby 3.2+
  • Loading branch information
Drenmi authored and bbatsov committed Oct 27, 2022
1 parent d5d7dc5 commit 3087023
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/new_add_set_to_redundant_require_statement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11126](https://github.com/rubocop/rubocop/pull/11126): Have `Lint/RedundantRequireStatement` mark `set` as a redundant require in Ruby 3.2+. ([@drenmi][])
4 changes: 3 additions & 1 deletion lib/rubocop/cop/lint/redundant_require_statement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Lint
# * 2.5+ ... Add `pp` above
# * 2.7+ ... Add `ruby2_keywords` above
# * 3.1+ ... Add `fiber` above
# * 3.2+ ... `set`
#
# This cop target those features.
#
Expand Down Expand Up @@ -63,7 +64,8 @@ def redundant_feature?(feature_name)
(target_ruby_version >= 2.2 && RUBY_22_LOADED_FEATURES.include?(feature_name)) ||
(target_ruby_version >= 2.5 && feature_name == 'pp') ||
(target_ruby_version >= 2.7 && feature_name == 'ruby2_keywords') ||
(target_ruby_version >= 3.1 && feature_name == 'fiber')
(target_ruby_version >= 3.1 && feature_name == 'fiber') ||
(target_ruby_version >= 3.2 && feature_name == 'set')
end
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
end
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/lint/redundant_require_statement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,19 @@
require 'uri'
RUBY
end

context 'target ruby version >= 3.2', :ruby32 do
it 'registers an offense and corrects when using requiring `set`' do
expect_offense(<<~RUBY)
require 'set'
^^^^^^^^^^^^^ Remove unnecessary `require` statement.
require 'uri'
RUBY

expect_correction(<<~RUBY)
require 'uri'
RUBY
end
end
end
end

0 comments on commit 3087023

Please sign in to comment.