From 1e143c9093f68bb3443f55e5edae8f766fa68f41 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Wed, 9 Aug 2023 09:35:09 +0300 Subject: [PATCH 01/20] Switch back the docs version --- docs/antora.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/antora.yml b/docs/antora.yml index b4de30cfda13..9c897ea03d1d 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -2,6 +2,6 @@ name: rubocop title: RuboCop # We always provide version without patch here (e.g. 1.1), # as patch versions should not appear in the docs. -version: '1.56' +version: ~ nav: - modules/ROOT/nav.adoc From 1fbfb83c587d467eac30665a9ebadcd4694a0b40 Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Wed, 9 Aug 2023 20:18:48 +0900 Subject: [PATCH 02/20] [Fix: #12109] Fix an error for `Style/ArgumentsForwarding` cop when forwarding kwargs/block arg and an additional arg Fix: https://github.com/rubocop/rubocop/issues/12109 --- ...arding_cop_when_forwarding_kwargs_block.md | 1 + lib/rubocop/cop/style/arguments_forwarding.rb | 7 ++-- .../cop/style/arguments_forwarding_spec.rb | 32 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 changelog/fix_an_error_for_style_arguments_forwarding_cop_when_forwarding_kwargs_block.md diff --git a/changelog/fix_an_error_for_style_arguments_forwarding_cop_when_forwarding_kwargs_block.md b/changelog/fix_an_error_for_style_arguments_forwarding_cop_when_forwarding_kwargs_block.md new file mode 100644 index 000000000000..02ef67ee1c5f --- /dev/null +++ b/changelog/fix_an_error_for_style_arguments_forwarding_cop_when_forwarding_kwargs_block.md @@ -0,0 +1 @@ +* [#12109](https://github.com/rubocop/rubocop/issues/12109): Fix an error for `Style/ArgumentsForwarding` cop when forwarding kwargs/block arg and an additional arg. ([@ydah][]) diff --git a/lib/rubocop/cop/style/arguments_forwarding.rb b/lib/rubocop/cop/style/arguments_forwarding.rb index d53712f1ba0b..fc0d1c66a3b3 100644 --- a/lib/rubocop/cop/style/arguments_forwarding.rb +++ b/lib/rubocop/cop/style/arguments_forwarding.rb @@ -80,6 +80,7 @@ class ArgumentsForwarding < Base minimum_target_ruby_version 2.7 FORWARDING_LVAR_TYPES = %i[splat kwsplat block_pass].freeze + ADDITIONAL_ARG_TYPES = %i[lvar arg].freeze FORWARDING_MSG = 'Use shorthand syntax `...` for arguments forwarding.' ARGS_MSG = 'Use anonymous positional arguments forwarding (`*`).' @@ -212,7 +213,7 @@ def register_forward_all_offense(def_or_send, send_or_arguments, rest_or_splat) end def arguments_range(node, first_node) - arguments = node.arguments + arguments = node.arguments.reject { |arg| ADDITIONAL_ARG_TYPES.include?(arg.type) } start_node = first_node || arguments.first @@ -332,9 +333,9 @@ def target_ruby_version end def no_post_splat_args? - splat_index = arguments.index(forwarded_rest_arg) - arg_after_splat = arguments[splat_index + 1] + return true unless (splat_index = arguments.index(forwarded_rest_arg)) + arg_after_splat = arguments[splat_index + 1] [nil, :hash, :block_pass].include?(arg_after_splat&.type) end diff --git a/spec/rubocop/cop/style/arguments_forwarding_spec.rb b/spec/rubocop/cop/style/arguments_forwarding_spec.rb index 1aeb81abfdcb..9609ade7fc1f 100644 --- a/spec/rubocop/cop/style/arguments_forwarding_spec.rb +++ b/spec/rubocop/cop/style/arguments_forwarding_spec.rb @@ -519,6 +519,38 @@ def self.get(...) end RUBY end + + it 'registers an offense when forwarding kwargs/block arg' do + expect_offense(<<~RUBY) + def foo(**kwargs, &block) + ^^^^^^^^^^^^^^^^ Use shorthand syntax `...` for arguments forwarding. + baz(**kwargs, &block) + ^^^^^^^^^^^^^^^^ Use shorthand syntax `...` for arguments forwarding. + end + RUBY + + expect_correction(<<~RUBY) + def foo(...) + baz(...) + end + RUBY + end + + it 'registers an offense when forwarding kwargs/block arg and an additional arg' do + expect_offense(<<~RUBY) + def foo(x, **kwargs, &block) + ^^^^^^^^^^^^^^^^ Use shorthand syntax `...` for arguments forwarding. + baz(x, **kwargs, &block) + ^^^^^^^^^^^^^^^^ Use shorthand syntax `...` for arguments forwarding. + end + RUBY + + expect_correction(<<~RUBY) + def foo(x, ...) + baz(x, ...) + end + RUBY + end end context 'TargetRubyVersion >= 3.1', :ruby31 do From 7d192907a118cd93d69d364e100632500ca7d92e Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Thu, 10 Aug 2023 20:40:36 +0900 Subject: [PATCH 03/20] [Docs] Update example of `rubocop -V` RuboCop still supports Ruby 2.7 as a runtime, but the Ruby version is EOL. --- .github/ISSUE_TEMPLATE/bug_report.md | 6 +++--- CONTRIBUTING.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 7cd0c16a4515..148881598eb9 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -38,7 +38,7 @@ output by `rubocop -V`, include them as well. Here's an example: ``` $ [bundle exec] rubocop -V -1.56.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux] - - rubocop-performance 1.9.1 - - rubocop-rspec 2.0.0 +1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux] + - rubocop-performance 1.18.0 + - rubocop-rspec 2.23.2 ``` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 74cf9992c266..ca4d4f9fcbeb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,9 +17,9 @@ do so. ```console $ rubocop -V -1.56.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.2) [x86_64-linux] - - rubocop-performance 1.9.1 - - rubocop-rspec 2.0.0 +1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux] + - rubocop-performance 1.18.0 + - rubocop-rspec 2.23.2 ``` * Include any relevant code to the issue summary. From d9219f104bd49a0ec7dcb8ecad815268c0dfe31d Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Thu, 10 Aug 2023 12:02:11 +0900 Subject: [PATCH 04/20] [Fix #12111] Fix an error for `Bundler/DuplicatedGroup` Fixes #12111. This PR fixes an error for `Bundler/DuplicatedGroup` group declaration has keyword option. --- ...x_an_error_for_bundler_duplicated_group.md | 1 + lib/rubocop/cop/bundler/duplicated_group.rb | 29 ++++++--- .../cop/bundler/duplicated_group_spec.rb | 64 ++++++++++++++++++- 3 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 changelog/fix_an_error_for_bundler_duplicated_group.md diff --git a/changelog/fix_an_error_for_bundler_duplicated_group.md b/changelog/fix_an_error_for_bundler_duplicated_group.md new file mode 100644 index 000000000000..3bda40834ad1 --- /dev/null +++ b/changelog/fix_an_error_for_bundler_duplicated_group.md @@ -0,0 +1 @@ +* [#12111](https://github.com/rubocop/rubocop/issues/12111): Fix an error for `Bundler/DuplicatedGroup` group declaration has keyword option. ([@koic][]) diff --git a/lib/rubocop/cop/bundler/duplicated_group.rb b/lib/rubocop/cop/bundler/duplicated_group.rb index a056825dcaa8..dd0fd3696fb9 100644 --- a/lib/rubocop/cop/bundler/duplicated_group.rb +++ b/lib/rubocop/cop/bundler/duplicated_group.rb @@ -43,26 +43,29 @@ class DuplicatedGroup < Base MSG = 'Gem group `%s` already defined on line ' \ '%d of the Gemfile.' + # @!method group_declarations(node) + def_node_search :group_declarations, '(send nil? :group ...)' + def on_new_investigation return if processed_source.blank? duplicated_group_nodes.each do |nodes| nodes[1..].each do |node| - register_offense(node, node.arguments.map(&:value).join(', '), nodes.first.first_line) + group_name = node.arguments.map(&:source).join(', ') + + register_offense(node, group_name, nodes.first.first_line) end end end private - # @!method group_declarations(node) - def_node_search :group_declarations, '(send nil? :group ...)' - def duplicated_group_nodes - group_declarations(processed_source.ast) - .group_by { |node| node.arguments.map(&:value).map(&:to_s).sort } - .values - .select { |nodes| nodes.size > 1 } + groups = group_declarations(processed_source.ast).group_by do |node| + group_attributes(node).sort + end + + groups.values.select { |nodes| nodes.size > 1 } end def register_offense(node, group_name, line_of_first_occurrence) @@ -75,6 +78,16 @@ def register_offense(node, group_name, line_of_first_occurrence) ) add_offense(offense_location, message: message) end + + def group_attributes(node) + node.arguments.map do |argument| + if argument.hash_type? + argument.pairs.map(&:source).sort.join(', ') + else + argument.value.to_s + end + end + end end end end diff --git a/spec/rubocop/cop/bundler/duplicated_group_spec.rb b/spec/rubocop/cop/bundler/duplicated_group_spec.rb index af407fb35667..ceae2b0954ce 100644 --- a/spec/rubocop/cop/bundler/duplicated_group_spec.rb +++ b/spec/rubocop/cop/bundler/duplicated_group_spec.rb @@ -40,7 +40,7 @@ gem 'rubocop' end group :development do - ^^^^^^^^^^^^^^^^^^ Gem group `development` already defined on line 1 of the Gemfile. + ^^^^^^^^^^^^^^^^^^ Gem group `:development` already defined on line 1 of the Gemfile. gem 'rubocop-rails' end RUBY @@ -54,7 +54,7 @@ gem 'rubocop' end group 'development' do - ^^^^^^^^^^^^^^^^^^^ Gem group `development` already defined on line 1 of the Gemfile. + ^^^^^^^^^^^^^^^^^^^ Gem group `'development'` already defined on line 1 of the Gemfile. gem 'rubocop-rails' end RUBY @@ -77,6 +77,64 @@ end end + context 'and same groups with different keyword names' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY, 'Gemfile') + group :test, foo: true do + gem 'activesupport' + end + + group :test, bar: true do + gem 'rspec' + end + RUBY + end + end + + context 'and same groups with different keyword values' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY, 'Gemfile') + group :test, foo: true do + gem 'activesupport' + end + + group :test, foo: false do + gem 'rspec' + end + RUBY + end + end + + context 'and same groups with same keyword option and the option order is the same' do + it 'registers an offense' do + expect_offense(<<~RUBY, 'Gemfile') + group :test, foo: true, bar: true do + gem 'activesupport' + end + + group :test, foo: true, bar: true do + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Gem group `:test, foo: true, bar: true` already defined on line 1 of the Gemfile. + gem 'rspec' + end + RUBY + end + end + + context 'and same groups with same keyword option and the option order is different' do + it 'registers an offense' do + expect_offense(<<~RUBY, 'Gemfile') + group :test, foo: true, bar: true do + gem 'activesupport' + end + + group :test, bar: true, foo: true do + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Gem group `:test, bar: true, foo: true` already defined on line 1 of the Gemfile. + gem 'rspec' + end + RUBY + end + end + context 'and a set of groups is duplicated' do it 'registers an offense' do expect_offense(<<-RUBY, 'Gemfile') @@ -84,7 +142,7 @@ gem 'rubocop' end group :development, :test do - ^^^^^^^^^^^^^^^^^^^^^^^^^ Gem group `development, test` already defined on line 1 of the Gemfile. + ^^^^^^^^^^^^^^^^^^^^^^^^^ Gem group `:development, :test` already defined on line 1 of the Gemfile. gem 'rubocop-rails' end RUBY From d929f688c7d1e68caa1f806ee1b1ca4d55a89fdc Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Fri, 11 Aug 2023 17:22:24 +0900 Subject: [PATCH 05/20] Fix an error for `Style/Lambda` This PR fixes the following error for `Style/Lambda` when using numbered parameter with a multiline `->` call: ```console $ cat example.rb -> { _1.do_something } $ bundle exec rubocop example.rb --only Style/Lambda -d (snip) An error occurred while Style/Lambda cop was inspecting /Users/koic/src/github.com/koic/rubocop-issues/lambda/example.rb:1:0. undefined method `loc' for []:Array /Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb:96:in `arguments_end_pos' ``` --- changelog/fix_an_error_for_style_lambda.md | 1 + .../lambda_literal_to_method_corrector.rb | 11 +++++++---- spec/rubocop/cop/style/lambda_spec.rb | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 changelog/fix_an_error_for_style_lambda.md diff --git a/changelog/fix_an_error_for_style_lambda.md b/changelog/fix_an_error_for_style_lambda.md new file mode 100644 index 000000000000..e20de10547a4 --- /dev/null +++ b/changelog/fix_an_error_for_style_lambda.md @@ -0,0 +1 @@ +* [#12115](https://github.com/rubocop/rubocop/pull/12115): Fix an error for `Style/Lambda` when using numbered parameter with a multiline `->` call. ([@koic][]) diff --git a/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb b/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb index 2ee0b879b2bd..6d690736deb0 100644 --- a/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +++ b/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb @@ -14,12 +14,15 @@ def call(corrector) # Check for unparenthesized args' preceding and trailing whitespaces. remove_unparenthesized_whitespace(corrector) - # Avoid correcting to `lambdado` by inserting whitespace - # if none exists before or after the lambda arguments. - insert_separating_space(corrector) + if block_node.block_type? + # Avoid correcting to `lambdado` by inserting whitespace + # if none exists before or after the lambda arguments. + insert_separating_space(corrector) + + remove_arguments(corrector) + end replace_selector(corrector) - remove_arguments(corrector) replace_delimiters(corrector) diff --git a/spec/rubocop/cop/style/lambda_spec.rb b/spec/rubocop/cop/style/lambda_spec.rb index fd83081c65d1..9a8a8d29ec5a 100644 --- a/spec/rubocop/cop/style/lambda_spec.rb +++ b/spec/rubocop/cop/style/lambda_spec.rb @@ -215,6 +215,23 @@ end end + context 'with a multiline `->` call' do + it 'registers an offense' do + expect_offense(<<~RUBY) + -> { + ^^ Use the `lambda` method for multiline lambdas. + _1.do_something + } + RUBY + + expect_correction(<<~RUBY) + lambda { + _1.do_something + } + RUBY + end + end + context 'with a multiline lambda method call' do it 'does not register an offense' do expect_no_offenses(<<~RUBY) From b6e294fc1ef40bd8a6eb5a0a941456d3d1be4fa3 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 12 Aug 2023 19:35:13 +0900 Subject: [PATCH 06/20] Use `delete_prefix` and `delete_suffix` --- lib/rubocop/cop/lint/useless_assignment.rb | 3 +-- lib/rubocop/cop/naming/file_name.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/rubocop/cop/lint/useless_assignment.rb b/lib/rubocop/cop/lint/useless_assignment.rb index 83902ad65707..fafcf9512a3b 100644 --- a/lib/rubocop/cop/lint/useless_assignment.rb +++ b/lib/rubocop/cop/lint/useless_assignment.rb @@ -96,8 +96,7 @@ def operator_assignment_message(scope, assignment) return_value_node = return_value_node_of_scope(scope) return unless assignment.meta_assignment_node.equal?(return_value_node) - " Use `#{assignment.operator.sub(/=$/, '')}` " \ - "instead of `#{assignment.operator}`." + " Use `#{assignment.operator.delete_suffix('=')}` instead of `#{assignment.operator}`." end def similar_name_message(variable) diff --git a/lib/rubocop/cop/naming/file_name.rb b/lib/rubocop/cop/naming/file_name.rb index 751b6f0fe694..5591199801c0 100644 --- a/lib/rubocop/cop/naming/file_name.rb +++ b/lib/rubocop/cop/naming/file_name.rb @@ -136,7 +136,7 @@ def allowed_acronyms end def filename_good?(basename) - basename = basename.sub(/^\./, '') + basename = basename.delete_prefix('.') basename = basename.sub(/\.[^.]+$/, '') # special handling for Action Pack Variants file names like # some_file.xlsx+mobile.axlsx From 5b9ca710fa172e0725d1c208f33f6d344f76deb6 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sun, 13 Aug 2023 17:36:08 +0900 Subject: [PATCH 07/20] Use RuboCop Performance 1.19 This commit uses RuboCop Performance 1.19 and suppresses the following new offenses: ```console $ bundle exec rubocop (snip) lib/rubocop/cop/layout/line_continuation_spacing.rb:112:20: C: Performance/MapMethodChain: Use map { |x| x.loc.expression } instead of map method chain. comments.map(&:loc).map(&:expression) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/rubocop/cop/layout/redundant_line_break.rb:121:37: C: Performance/MapMethodChain: Use map { |x| x.loc.line } instead of map method chain. processed_source.comments.map(&:loc).map(&:line).any? do |comment_line_number| ^^^^^^^^^^^^^^^^^^^^^^ lib/rubocop/cop/style/concat_array_literals.rb:77:30: C: Performance/MapMethodChain: Use map { |x| x.value.inspect } instead of map method chain. arg.children.map(&:value).map(&:inspect) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1515 files inspected, 3 offenses detected ``` --- Gemfile | 2 +- lib/rubocop/cop/layout/line_continuation_spacing.rb | 2 +- lib/rubocop/cop/layout/redundant_line_break.rb | 4 +++- lib/rubocop/cop/style/concat_array_literals.rb | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 20f3331525ac..5964eb9b0218 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ gem 'bundler', '>= 1.15.0', '< 3.0' gem 'memory_profiler', platform: :mri gem 'rake', '~> 13.0' gem 'rspec', '~> 3.7' -gem 'rubocop-performance', '~> 1.18.0' +gem 'rubocop-performance', '~> 1.19.0' gem 'rubocop-rake', '~> 0.6.0' gem 'rubocop-rspec', '~> 2.23.0' # Workaround for cc-test-reporter with SimpleCov 0.18. diff --git a/lib/rubocop/cop/layout/line_continuation_spacing.rb b/lib/rubocop/cop/layout/line_continuation_spacing.rb index 536b4448fbcd..f400b01bfb47 100644 --- a/lib/rubocop/cop/layout/line_continuation_spacing.rb +++ b/lib/rubocop/cop/layout/line_continuation_spacing.rb @@ -109,7 +109,7 @@ def ignored_literal_ranges(ast) # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def comment_ranges(comments) - comments.map(&:loc).map(&:expression) + comments.map(&:source_range) end def last_line(processed_source) diff --git a/lib/rubocop/cop/layout/redundant_line_break.rb b/lib/rubocop/cop/layout/redundant_line_break.rb index 1d1fc907baf5..e4981cc82451 100644 --- a/lib/rubocop/cop/layout/redundant_line_break.rb +++ b/lib/rubocop/cop/layout/redundant_line_break.rb @@ -118,7 +118,9 @@ def convertible_block?(node) end def comment_within?(node) - processed_source.comments.map(&:loc).map(&:line).any? do |comment_line_number| + comment_line_numbers = processed_source.comments.map { |comment| comment.loc.line } + + comment_line_numbers.any? do |comment_line_number| comment_line_number >= node.first_line && comment_line_number <= node.last_line end end diff --git a/lib/rubocop/cop/style/concat_array_literals.rb b/lib/rubocop/cop/style/concat_array_literals.rb index c4ab3326a76a..d84983f75a5c 100644 --- a/lib/rubocop/cop/style/concat_array_literals.rb +++ b/lib/rubocop/cop/style/concat_array_literals.rb @@ -74,7 +74,7 @@ def preferred_method(node) new_arguments = node.arguments.map do |arg| if arg.percent_literal? - arg.children.map(&:value).map(&:inspect) + arg.children.map { |child| child.value.inspect } else arg.children.map(&:source) end From 62a7cb9932271b386cc4c790278c3442b3438af4 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Sat, 12 Aug 2023 11:42:25 +0100 Subject: [PATCH 08/20] [Fix #12117] Fix `Style/ArgumentsForwarding` when not always forwarding a block --- ...arding_when_not_always_forwarding_block.md | 1 + lib/rubocop/cop/style/arguments_forwarding.rb | 2 +- .../cop/style/arguments_forwarding_spec.rb | 90 +++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_an_error_for_style_arguments_forwarding_when_not_always_forwarding_block.md diff --git a/changelog/fix_an_error_for_style_arguments_forwarding_when_not_always_forwarding_block.md b/changelog/fix_an_error_for_style_arguments_forwarding_when_not_always_forwarding_block.md new file mode 100644 index 000000000000..f04d137b0172 --- /dev/null +++ b/changelog/fix_an_error_for_style_arguments_forwarding_when_not_always_forwarding_block.md @@ -0,0 +1 @@ +* [#12117](https://github.com/rubocop/rubocop/issues/12117): Fix a false positive for `Style/ArgumentsForwarding` cop when not always forwarding block. ([@owst][]) diff --git a/lib/rubocop/cop/style/arguments_forwarding.rb b/lib/rubocop/cop/style/arguments_forwarding.rb index fc0d1c66a3b3..ec971980ece6 100644 --- a/lib/rubocop/cop/style/arguments_forwarding.rb +++ b/lib/rubocop/cop/style/arguments_forwarding.rb @@ -280,7 +280,7 @@ def classification if can_forward_all? :all - elsif target_ruby_version >= 3.2 + else :rest_or_kwrest end end diff --git a/spec/rubocop/cop/style/arguments_forwarding_spec.rb b/spec/rubocop/cop/style/arguments_forwarding_spec.rb index 9609ade7fc1f..3b25c3a09d9b 100644 --- a/spec/rubocop/cop/style/arguments_forwarding_spec.rb +++ b/spec/rubocop/cop/style/arguments_forwarding_spec.rb @@ -240,6 +240,34 @@ def foo(*args, &block) RUBY end + it 'does not register an offense when not always passing the block as well as restarg' do + expect_no_offenses(<<~RUBY) + def foo(*args, &block) + bar(*args, &block) + baz(*args) + end + RUBY + end + + it 'does not register an offense when not always passing the block as well as kwrestarg' do + expect_no_offenses(<<~RUBY) + def foo(**kwargs, &block) + bar(**kwargs, &block) + baz(**kwargs) + end + RUBY + end + + it 'does not register an offense when not always forwarding all' do + expect_no_offenses(<<~RUBY) + def foo(*args, **kwargs, &block) + bar(*args, **kwargs, &block) + bar(*args, &block) + bar(**kwargs, &block) + end + RUBY + end + it 'does not register an offense when body of method definition is empty' do expect_no_offenses(<<~RUBY) def foo(*args, &block) @@ -956,6 +984,68 @@ def foo(*, **, &block) RUBY end + it 'registers an offense when not always passing the block as well as restarg' do + expect_offense(<<~RUBY) + def foo(*args, &block) + ^^^^^ Use anonymous positional arguments forwarding (`*`). + bar(*args, &block) + ^^^^^ Use anonymous positional arguments forwarding (`*`). + baz(*args) + ^^^^^ Use anonymous positional arguments forwarding (`*`). + end + RUBY + + expect_correction(<<~RUBY) + def foo(*, &block) + bar(*, &block) + baz(*) + end + RUBY + end + + it 'registers an offense when not always passing the block as well as kwrestarg' do + expect_offense(<<~RUBY) + def foo(**kwargs, &block) + ^^^^^^^^ Use anonymous keyword arguments forwarding (`**`). + bar(**kwargs, &block) + ^^^^^^^^ Use anonymous keyword arguments forwarding (`**`). + baz(**kwargs) + ^^^^^^^^ Use anonymous keyword arguments forwarding (`**`). + end + RUBY + + expect_correction(<<~RUBY) + def foo(**, &block) + bar(**, &block) + baz(**) + end + RUBY + end + + it 'registers an offense when not always forwarding all' do + expect_offense(<<~RUBY) + def foo(*args, **kwargs, &block) + ^^^^^ Use anonymous positional arguments forwarding (`*`). + ^^^^^^^^ Use anonymous keyword arguments forwarding (`**`). + bar(*args, **kwargs, &block) + ^^^^^ Use anonymous positional arguments forwarding (`*`). + ^^^^^^^^ Use anonymous keyword arguments forwarding (`**`). + bar(*args, &block) + ^^^^^ Use anonymous positional arguments forwarding (`*`). + bar(**kwargs, &block) + ^^^^^^^^ Use anonymous keyword arguments forwarding (`**`). + end + RUBY + + expect_correction(<<~RUBY) + def foo(*, **, &block) + bar(*, **, &block) + bar(*, &block) + bar(**, &block) + end + RUBY + end + it 'registers an offense for restarg when passing block to separate call' do expect_offense(<<~RUBY) def foo(*args, &block) From 89eb905332f627ee56d64a865e5e372a71485575 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Tue, 15 Aug 2023 01:21:57 +0900 Subject: [PATCH 09/20] Fix false positives for `Style/SymbolArray` This PR fixes false positives for `Style/SymbolArray` when `%i` array containing unescaped `[`, `]`, `(`, or `)`. I noticed the following false positive in the RuboCop AST repository: ```console $ cd path/to/rubocop-ast $ bundle exec rubocop --only Style/SymbolArray (snip) spec/rubocop/ast/node_pattern/lexer_spec.rb:36:9: C: [Correctable] Style/SymbolArray: Use [:'(', :array, :sym, :'$', :int, :+, :x, :')'] for an array of symbols. %i[( array sym $ int + x )] ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 163 files inspected, 1 offense detected, 1 offense autocorrectable ``` --- ...fix_false_positives_for_style_symbol_array.md | 1 + lib/rubocop/cop/style/symbol_array.rb | 2 ++ spec/rubocop/cop/style/symbol_array_spec.rb | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 changelog/fix_false_positives_for_style_symbol_array.md diff --git a/changelog/fix_false_positives_for_style_symbol_array.md b/changelog/fix_false_positives_for_style_symbol_array.md new file mode 100644 index 000000000000..e2255a4f1b87 --- /dev/null +++ b/changelog/fix_false_positives_for_style_symbol_array.md @@ -0,0 +1 @@ +* [#12119](https://github.com/rubocop/rubocop/pull/12119): Fix false positives for `Style/SymbolArray` when `%i` array containing unescaped `[`, `]`, `(`, or `)`. ([@koic][]) diff --git a/lib/rubocop/cop/style/symbol_array.rb b/lib/rubocop/cop/style/symbol_array.rb index a01ad7908586..a055ce9486f6 100644 --- a/lib/rubocop/cop/style/symbol_array.rb +++ b/lib/rubocop/cop/style/symbol_array.rb @@ -69,6 +69,8 @@ def on_array(node) def complex_content?(node) node.children.any? do |sym| + return false if DELIMITERS.include?(sym.source) + content = *sym content = content.map { |c| c.is_a?(AST::Node) ? c.source : c }.join content_without_delimiter_pairs = content.gsub(/(\[[^\s\[\]]*\])|(\([^\s\(\)]*\))/, '') diff --git a/spec/rubocop/cop/style/symbol_array_spec.rb b/spec/rubocop/cop/style/symbol_array_spec.rb index 7f4cd2a6b06b..54d139c6d207 100644 --- a/spec/rubocop/cop/style/symbol_array_spec.rb +++ b/spec/rubocop/cop/style/symbol_array_spec.rb @@ -138,7 +138,7 @@ expect(cop.config_to_allow_offenses).to eq('Enabled' => false) end - it 'registers an offense for a %i array containing [ ]' do + it 'registers an offense for a %i array containing escaped [ ]' do expect_offense(<<~'RUBY') %i[one \[ \] two] ^^^^^^^^^^^^^^^^^ Use `[:one, :'[', :']', :two]` for an array of symbols. @@ -149,6 +149,12 @@ RUBY end + it 'does not register an offense for a %i array containing unescaped [ ]' do + expect_no_offenses(<<~RUBY) + %i(one [ ] two) + RUBY + end + it 'registers an offense for a %i array containing whitespace between brackets' do expect_offense(<<~'RUBY') %i[one two \[three\ four\ five\]] @@ -171,7 +177,7 @@ RUBY end - it 'registers an offense for a %i array containing ( )' do + it 'registers an offense for a %i array containing escaped ( )' do expect_offense(<<~'RUBY') %i(one \( \) two) ^^^^^^^^^^^^^^^^^ Use `[:one, :'(', :')', :two]` for an array of symbols. @@ -182,6 +188,12 @@ RUBY end + it 'does not register an offense for a %i array containing unescaped ( )' do + expect_no_offenses(<<~RUBY) + %i[one ( ) two] + RUBY + end + it 'registers an offense for a %i array containing parentheses between parentheses' do expect_offense(<<~'RUBY') %i(one two \(\(\)) From aba88959eea0551cf4c47824fa5a45a7c92ca945 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 16 Aug 2023 00:06:09 +0900 Subject: [PATCH 10/20] Fix a PR number in a changelog entry --- changelog/fix_false_positives_for_style_symbol_array.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/fix_false_positives_for_style_symbol_array.md b/changelog/fix_false_positives_for_style_symbol_array.md index e2255a4f1b87..e82b4d8d8d54 100644 --- a/changelog/fix_false_positives_for_style_symbol_array.md +++ b/changelog/fix_false_positives_for_style_symbol_array.md @@ -1 +1 @@ -* [#12119](https://github.com/rubocop/rubocop/pull/12119): Fix false positives for `Style/SymbolArray` when `%i` array containing unescaped `[`, `]`, `(`, or `)`. ([@koic][]) +* [#12120](https://github.com/rubocop/rubocop/pull/12120): Fix false positives for `Style/SymbolArray` when `%i` array containing unescaped `[`, `]`, `(`, or `)`. ([@koic][]) From dfddfa942e1f4bcea44452dc0e81737c2ce6932d Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 12 Aug 2023 00:04:05 +0900 Subject: [PATCH 11/20] [Fix #12113] Fix a false positive for `Bundler/DuplicatedGroup` Fix #12113. This PR fixes a false positive for `Bundler/DuplicatedGroup` when groups are duplicated but `source`, `git`, `platforms`, or `path` values are different. --- ...e_positive_for_bundler_duplicated_group.md | 1 + lib/rubocop/cop/bundler/duplicated_group.rb | 39 ++++- .../cop/bundler/duplicated_group_spec.rb | 163 ++++++++++++++++++ 3 files changed, 200 insertions(+), 3 deletions(-) create mode 100644 changelog/fix_a_false_positive_for_bundler_duplicated_group.md diff --git a/changelog/fix_a_false_positive_for_bundler_duplicated_group.md b/changelog/fix_a_false_positive_for_bundler_duplicated_group.md new file mode 100644 index 000000000000..3898d83db2bc --- /dev/null +++ b/changelog/fix_a_false_positive_for_bundler_duplicated_group.md @@ -0,0 +1 @@ +* [#12113](https://github.com/rubocop/rubocop/issues/12113): Fix a false positive for `Bundler/DuplicatedGroup` when groups are duplicated but `source`, `git`, `platforms`, or `path` values are different. ([@koic][]) diff --git a/lib/rubocop/cop/bundler/duplicated_group.rb b/lib/rubocop/cop/bundler/duplicated_group.rb index dd0fd3696fb9..b4a0cfcfe202 100644 --- a/lib/rubocop/cop/bundler/duplicated_group.rb +++ b/lib/rubocop/cop/bundler/duplicated_group.rb @@ -5,6 +5,24 @@ module Cop module Bundler # A Gem group, or a set of groups, should be listed only once in a Gemfile. # + # For example, if the values of `source`, `git`, `platforms`, or `path` + # surrounding `group` are different, no offense will be registered: + # + # [source,ruby] + # ----- + # platforms :ruby do + # group :default do + # gem 'openssl' + # end + # end + # + # platforms :jruby do + # group :default do + # gem 'jruby-openssl' + # end + # end + # ----- + # # @example # # bad # group :development do @@ -42,6 +60,7 @@ class DuplicatedGroup < Base MSG = 'Gem group `%s` already defined on line ' \ '%d of the Gemfile.' + SOURCE_BLOCK_NAMES = %i[source git platforms path].freeze # @!method group_declarations(node) def_node_search :group_declarations, '(send nil? :group ...)' @@ -61,11 +80,15 @@ def on_new_investigation private def duplicated_group_nodes - groups = group_declarations(processed_source.ast).group_by do |node| - group_attributes(node).sort + group_declarations = group_declarations(processed_source.ast) + group_keys = group_declarations.group_by do |node| + source_key = find_source_key(node) + group_attributes = group_attributes(node).sort.join + + "#{source_key}#{group_attributes}" end - groups.values.select { |nodes| nodes.size > 1 } + group_keys.values.select { |nodes| nodes.size > 1 } end def register_offense(node, group_name, line_of_first_occurrence) @@ -79,6 +102,16 @@ def register_offense(node, group_name, line_of_first_occurrence) add_offense(offense_location, message: message) end + def find_source_key(node) + source_block = node.each_ancestor(:block).find do |block_node| + SOURCE_BLOCK_NAMES.include?(block_node.method_name) + end + + return unless source_block + + "#{source_block.method_name}#{source_block.send_node.first_argument&.source}" + end + def group_attributes(node) node.arguments.map do |argument| if argument.hash_type? diff --git a/spec/rubocop/cop/bundler/duplicated_group_spec.rb b/spec/rubocop/cop/bundler/duplicated_group_spec.rb index ceae2b0954ce..4c9d100932c0 100644 --- a/spec/rubocop/cop/bundler/duplicated_group_spec.rb +++ b/spec/rubocop/cop/bundler/duplicated_group_spec.rb @@ -148,5 +148,168 @@ RUBY end end + + context 'and a set of groups is duplicated but `source` URLs are different' do + it 'does not register an offense' do + expect_no_offenses(<<-RUBY, 'Gemfile') + source 'https://rubygems.pkg.github.com/private-org' do + group :development do + gem 'rubocop' + end + end + + group :development do + gem 'rubocop-rails' + end + RUBY + end + end + + context 'and a set of groups is duplicated and `source` URLs are the same' do + it 'registers an offense' do + expect_offense(<<-RUBY, 'Gemfile') + source 'https://rubygems.pkg.github.com/private-org' do + group :development do + gem 'rubocop' + end + end + + source 'https://rubygems.pkg.github.com/private-org' do + group :development do + ^^^^^^^^^^^^^^^^^^ Gem group `:development` already defined on line 2 of the Gemfile. + gem 'rubocop-rails' + end + end + + group :development do + gem 'rubocop-performance' + end + RUBY + end + end + + context 'and a set of groups is duplicated but `git` URLs are different' do + it 'does not register an offense' do + expect_no_offenses(<<-RUBY, 'Gemfile') + git 'https://github.com/rubocop/rubocop.git' do + group :default do + gem 'rubocop' + end + end + + git 'https://github.com/rails/rails.git' do + group :default do + gem 'activesupport' + gem 'actionpack' + end + end + RUBY + end + end + + context 'and a set of groups is duplicated and `git` URLs are the same' do + it 'registers an offense' do + expect_offense(<<-RUBY, 'Gemfile') + git 'https://github.com/rails/rails.git' do + group :default do + gem 'activesupport' + end + end + + git 'https://github.com/rails/rails.git' do + group :default do + ^^^^^^^^^^^^^^ Gem group `:default` already defined on line 2 of the Gemfile. + gem 'actionpack' + end + end + RUBY + end + end + + context 'and a set of groups is duplicated but `platforms` values are different' do + it 'does not register an offense' do + expect_no_offenses(<<-RUBY, 'Gemfile') + platforms :ruby do + group :default do + gem 'openssl' + end + end + + platforms :jruby do + group :default do + gem 'jruby-openssl' + end + end + RUBY + end + end + + context 'and a set of groups is duplicated and `platforms` values are the same' do + it 'registers an offense' do + expect_offense(<<-RUBY, 'Gemfile') + platforms :ruby do + group :default do + gem 'ruby-debug' + end + end + + platforms :ruby do + group :default do + ^^^^^^^^^^^^^^ Gem group `:default` already defined on line 2 of the Gemfile. + gem 'sqlite3' + end + end + RUBY + end + end + + context 'and a set of groups is duplicated but `path` values are different' do + it 'does not register an offense' do + expect_no_offenses(<<-RUBY, 'Gemfile') + path 'components_admin' do + group :default do + gem 'admin_ui' + end + end + + path 'components_public' do + group :default do + gem 'public_ui' + end + end + RUBY + end + end + + context 'and a set of groups is duplicated and `path` values are the same' do + it 'registers an offense' do + expect_offense(<<-RUBY, 'Gemfile') + path 'components' do + group :default do + gem 'admin_ui' + end + end + + path 'components' do + group :default do + ^^^^^^^^^^^^^^ Gem group `:default` already defined on line 2 of the Gemfile. + gem 'public_ui' + end + end + RUBY + end + end + + context 'when `source` URL argument is not given' do + it 'does not crash' do + expect_no_offenses(<<-RUBY, 'Gemfile') + source do + group :development do + gem 'rubocop' + end + end + RUBY + end + end end end From 909564c356b44e9b4dc20537781bcc7cc033cf1c Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 16 Aug 2023 14:42:16 +0900 Subject: [PATCH 12/20] [Fix #12124] Fix false positives for `Style/RedundantParentheses` Fixes #12124. This PR fixes false positives for `Style/RedundantParentheses` when parentheses in `super` or `yield` call with multiline style argument. --- ..._positives_for_style_redundant_parentheses.md | 1 + lib/rubocop/cop/style/redundant_parentheses.rb | 4 +++- .../cop/style/redundant_parentheses_spec.rb | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_false_positives_for_style_redundant_parentheses.md diff --git a/changelog/fix_false_positives_for_style_redundant_parentheses.md b/changelog/fix_false_positives_for_style_redundant_parentheses.md new file mode 100644 index 000000000000..4a67a54d2f7f --- /dev/null +++ b/changelog/fix_false_positives_for_style_redundant_parentheses.md @@ -0,0 +1 @@ +* [#12124](https://github.com/rubocop/rubocop/issues/12124): Fix false positives for `Style/RedundantParentheses` when parentheses in `super` or `yield` call with multiline style argument. ([@koic][]) diff --git a/lib/rubocop/cop/style/redundant_parentheses.rb b/lib/rubocop/cop/style/redundant_parentheses.rb index 44e376c22b01..eff07b6cc266 100644 --- a/lib/rubocop/cop/style/redundant_parentheses.rb +++ b/lib/rubocop/cop/style/redundant_parentheses.rb @@ -98,7 +98,9 @@ def ternary_parentheses_required? end def like_method_argument_parentheses?(node) - node.send_type? && node.arguments.one? && !node.parenthesized? && + return false if !node.send_type? && !node.super_type? && !node.yield_type? + + node.arguments.one? && !node.parenthesized? && !node.arithmetic_operation? && node.first_argument.begin_type? end diff --git a/spec/rubocop/cop/style/redundant_parentheses_spec.rb b/spec/rubocop/cop/style/redundant_parentheses_spec.rb index 93542177b3aa..f9ad0f180fda 100644 --- a/spec/rubocop/cop/style/redundant_parentheses_spec.rb +++ b/spec/rubocop/cop/style/redundant_parentheses_spec.rb @@ -585,6 +585,22 @@ def x RUBY end + it 'accepts parentheses in super call with multiline style argument' do + expect_no_offenses(<<~RUBY) + super ( + 42 + ) + RUBY + end + + it 'accepts parentheses in yield call with multiline style argument' do + expect_no_offenses(<<~RUBY) + yield ( + 42 + ) + RUBY + end + it 'registers an offense and corrects when method arguments are unnecessarily parenthesized' do expect_offense(<<~RUBY) foo( From f8f5875b465e119e5cb556b47914aba09f606513 Mon Sep 17 00:00:00 2001 From: Chulki Lee Date: Mon, 14 Aug 2023 17:53:42 -0700 Subject: [PATCH 13/20] fix instance variable not initialized warning / memoization --- lib/rubocop/cop/utils/regexp_ranges.rb | 39 +++++++++++++++++--------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/rubocop/cop/utils/regexp_ranges.rb b/lib/rubocop/cop/utils/regexp_ranges.rb index aa60666c9dff..0fbc529f62a4 100644 --- a/lib/rubocop/cop/utils/regexp_ranges.rb +++ b/lib/rubocop/cop/utils/regexp_ranges.rb @@ -6,27 +6,40 @@ module Utils # Helper to abstract complexity of building range pairs # with octal escape reconstruction (needed for regexp_parser < 2.7). class RegexpRanges - attr_reader :compound_token, :root + attr_reader :root def initialize(root) @root = root @compound_token = [] + @pairs = [] + @populated = false + end + + def compound_token + populate_all unless @populated + + @compound_token end def pairs - unless @pairs - @pairs = [] - populate(root) - end + populate_all unless @populated + + @pairs + end + + private + + def populate_all + populate(@root) # If either bound is a compound the first one is an escape # and that's all we need to work with. # If there are any cops that wanted to operate on the compound # expression we could wrap it with a facade class. - @pairs.map { |pair| pair.map(&:first) } - end + @pairs.map! { |pair| pair.map(&:first) } - private + @populated = true + end def populate(expr) expressions = expr.expressions.to_a @@ -35,15 +48,15 @@ def populate(expr) current = expressions.shift if escaped_octal?(current) - compound_token << current - compound_token.concat(pop_octal_digits(expressions)) + @compound_token << current + @compound_token.concat(pop_octal_digits(expressions)) # If we have all the digits we can discard. end next unless current.type == :set process_set(expressions, current) - compound_token.clear + @compound_token.clear end end @@ -64,8 +77,8 @@ def process_set(expressions, current) def compose_range(expressions, current) range_start, range_end = current.expressions - range_start = if compound_token.size.between?(1, 2) && octal_digit?(range_start.text) - compound_token.dup << range_start + range_start = if @compound_token.size.between?(1, 2) && octal_digit?(range_start.text) + @compound_token.dup << range_start else [range_start] end From 252af0d4e517b3fabdb926a4cc22f90ca9a479f2 Mon Sep 17 00:00:00 2001 From: Marc Berchtold Date: Thu, 17 Aug 2023 10:42:09 +0200 Subject: [PATCH 14/20] [Fix #12105] Adjust target ruby gem requirement matcher and version parsing to support multiple version constraints [Fix #12105] Add changelog entry [Fix #12105] Fix changelog entry --- ...nt_support_multiple_version_constraints.md | 1 + lib/rubocop/target_ruby.rb | 14 +++-- spec/rubocop/target_ruby_spec.rb | 56 +++++++++++++++++++ 3 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 changelog/fix_target_ruby_gem_requirement_support_multiple_version_constraints.md diff --git a/changelog/fix_target_ruby_gem_requirement_support_multiple_version_constraints.md b/changelog/fix_target_ruby_gem_requirement_support_multiple_version_constraints.md new file mode 100644 index 000000000000..d328498e1817 --- /dev/null +++ b/changelog/fix_target_ruby_gem_requirement_support_multiple_version_constraints.md @@ -0,0 +1 @@ +* [#12105](https://github.com/rubocop/rubocop/issues/12105): Fix target ruby `Gem::Requirement` matcher and version parsing to support multiple version constraints. ([@ItsEcholot][]) diff --git a/lib/rubocop/target_ruby.rb b/lib/rubocop/target_ruby.rb index 13f6380f7d40..bb75d15f0c8c 100644 --- a/lib/rubocop/target_ruby.rb +++ b/lib/rubocop/target_ruby.rb @@ -155,9 +155,11 @@ class GemspecFile < Source (send _ :required_ruby_version= $_) PATTERN - # @!method gem_requirement?(node) - def_node_matcher :gem_requirement?, <<~PATTERN - (send (const(const _ :Gem):Requirement) :new $str) + # @!method gem_requirement_versions(node) + def_node_matcher :gem_requirement_versions, <<~PATTERN + (send (const(const _ :Gem):Requirement) :new + {$str+ | (send $str :freeze)+ | (array $str+) | (array (send $str :freeze)+)} + ) PATTERN def name @@ -194,10 +196,12 @@ def version_from_gemspec_file(file) end def version_from_right_hand_side(right_hand_side) + gem_requirement_versions = gem_requirement_versions(right_hand_side) + if right_hand_side.array_type? version_from_array(right_hand_side) - elsif gem_requirement?(right_hand_side) - right_hand_side.children.last.value + elsif gem_requirement_versions + gem_requirement_versions.map(&:value) else right_hand_side.value end diff --git a/spec/rubocop/target_ruby_spec.rb b/spec/rubocop/target_ruby_spec.rb index 872172d2fe67..44cf94c4478e 100644 --- a/spec/rubocop/target_ruby_spec.rb +++ b/spec/rubocop/target_ruby_spec.rb @@ -380,6 +380,62 @@ create_file(gemspec_file_path, content) expect(target_ruby.version).to eq default_version end + + it 'sets first known ruby version that satisfies range requirement' do + content = + <<-HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = Gem::Requirement.new('>= 2.3.1', '< 3.0.0') + s.licenses = ['MIT'] + end + HEREDOC + + create_file(gemspec_file_path, content) + expect(target_ruby.version).to eq default_version + end + + it 'sets first known ruby version that satisfies range requirement in array notation' do + content = + <<-HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = Gem::Requirement.new(['>= 2.3.1', '< 3.0.0']) + s.licenses = ['MIT'] + end + HEREDOC + + create_file(gemspec_file_path, content) + expect(target_ruby.version).to eq default_version + end + + it 'sets first known ruby version that satisfies range requirement with frozen strings' do + content = + <<-HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = Gem::Requirement.new('>= 2.3.1'.freeze, '< 3.0.0'.freeze) + s.licenses = ['MIT'] + end + HEREDOC + + create_file(gemspec_file_path, content) + expect(target_ruby.version).to eq default_version + end + + it 'sets first known ruby version that satisfies range requirement in array notation with frozen strings' do + content = + <<-HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = Gem::Requirement.new(['>= 2.3.1'.freeze, '< 3.0.0'.freeze]) + s.licenses = ['MIT'] + end + HEREDOC + + create_file(gemspec_file_path, content) + expect(target_ruby.version).to eq default_version + end end context 'when file contains `required_ruby_version` as an array' do From dd299948479c15cc7dd254a339631d241938b20b Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 19 Aug 2023 01:14:57 +0900 Subject: [PATCH 15/20] Use squiggly heredoc --- .../cop/lint/non_atomic_file_operation.rb | 4 +- lib/rubocop/cop/style/open_struct_use.rb | 2 +- rubocop.gemspec | 2 +- spec/rubocop/cli_spec.rb | 24 +- .../cop/bundler/duplicated_gem_spec.rb | 12 +- .../cop/bundler/duplicated_group_spec.rb | 24 +- spec/rubocop/cop/bundler/gem_comment_spec.rb | 68 +-- .../cop/layout/class_structure_spec.rb | 10 +- .../cop/layout/comment_indentation_spec.rb | 8 +- .../empty_lines_around_begin_body_spec.rb | 5 +- .../cop/layout/initial_indentation_spec.rb | 12 +- .../layout/rescue_ensure_alignment_spec.rb | 2 +- ..._inside_percent_literal_delimiters_spec.rb | 2 +- .../space_inside_reference_brackets_spec.rb | 2 +- .../cop/lint/duplicate_methods_spec.rb | 28 +- .../no_return_in_begin_end_blocks_spec.rb | 4 +- .../cop/lint/percent_string_array_spec.rb | 4 +- spec/rubocop/cop/lint/rescue_type_spec.rb | 8 +- spec/rubocop/cop/lint/syntax_spec.rb | 2 +- .../cop/naming/inclusive_language_spec.rb | 2 +- .../cop/style/documentation_method_spec.rb | 2 +- .../cop/style/empty_lambda_parameter_spec.rb | 4 +- spec/rubocop/cop/style/return_nil_spec.rb | 2 +- .../cop/style/string_concatenation_spec.rb | 24 +- spec/rubocop/cop/style/symbol_array_spec.rb | 8 +- spec/rubocop/cop/style/word_array_spec.rb | 8 +- spec/rubocop/cop/util_spec.rb | 4 +- .../cop/variable_force/assignment_spec.rb | 20 +- spec/rubocop/cop/variable_force/scope_spec.rb | 38 +- spec/rubocop/target_finder_spec.rb | 8 +- spec/rubocop/target_ruby_spec.rb | 464 +++++++++--------- 31 files changed, 394 insertions(+), 413 deletions(-) diff --git a/lib/rubocop/cop/lint/non_atomic_file_operation.rb b/lib/rubocop/cop/lint/non_atomic_file_operation.rb index 2a8bbdfbbd48..c39ec5926591 100644 --- a/lib/rubocop/cop/lint/non_atomic_file_operation.rb +++ b/lib/rubocop/cop/lint/non_atomic_file_operation.rb @@ -57,12 +57,12 @@ class NonAtomicFileOperation < Base REMOVE_FORCE_METHODS).freeze # @!method send_exist_node(node) - def_node_search :send_exist_node, <<-PATTERN + def_node_search :send_exist_node, <<~PATTERN $(send (const nil? {:FileTest :File :Dir :Shell}) {:exist? :exists?} ...) PATTERN # @!method receiver_and_method_name(node) - def_node_matcher :receiver_and_method_name, <<-PATTERN + def_node_matcher :receiver_and_method_name, <<~PATTERN (send (const nil? $_) $_ ...) PATTERN diff --git a/lib/rubocop/cop/style/open_struct_use.rb b/lib/rubocop/cop/style/open_struct_use.rb index 1940d2f54be1..eaddc61bc2f5 100644 --- a/lib/rubocop/cop/style/open_struct_use.rb +++ b/lib/rubocop/cop/style/open_struct_use.rb @@ -45,7 +45,7 @@ class OpenStructUse < Base MSG = 'Avoid using `OpenStruct`; use `Struct`, `Hash`, a class or test doubles instead.' # @!method uses_open_struct?(node) - def_node_matcher :uses_open_struct?, <<-PATTERN + def_node_matcher :uses_open_struct?, <<~PATTERN (const {nil? (cbase)} :OpenStruct) PATTERN diff --git a/rubocop.gemspec b/rubocop.gemspec index e4517d9b6e98..09720b1c27ab 100644 --- a/rubocop.gemspec +++ b/rubocop.gemspec @@ -8,7 +8,7 @@ Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.required_ruby_version = '>= 2.7.0' s.authors = ['Bozhidar Batsov', 'Jonas Arvidsson', 'Yuji Nakayama'] - s.description = <<-DESCRIPTION + s.description = <<~DESCRIPTION RuboCop is a Ruby code style checking and code formatting tool. It aims to enforce the community-driven Ruby Style Guide. DESCRIPTION diff --git a/spec/rubocop/cli_spec.rb b/spec/rubocop/cli_spec.rb index 329a16d083d7..8857f7d1bd6c 100644 --- a/spec/rubocop/cli_spec.rb +++ b/spec/rubocop/cli_spec.rb @@ -1639,18 +1639,18 @@ def meow_at_4am? expect(cli.run(%w[--format simple example])).to eq(1) - expect($stderr.string).to eq(<<-RESULT.strip_margin('|')) - |Warning: Layout/LineLength does not support Min parameter. - | - |Supported parameters are: - | - | - Enabled - | - Max - | - AllowHeredoc - | - AllowURI - | - URISchemes - | - IgnoreCopDirectives - | - AllowedPatterns + expect($stderr.string).to eq(<<~RESULT) + Warning: Layout/LineLength does not support Min parameter. + + Supported parameters are: + + - Enabled + - Max + - AllowHeredoc + - AllowURI + - URISchemes + - IgnoreCopDirectives + - AllowedPatterns RESULT end diff --git a/spec/rubocop/cop/bundler/duplicated_gem_spec.rb b/spec/rubocop/cop/bundler/duplicated_gem_spec.rb index 99a47ea6a7e2..e7c01b64e14a 100644 --- a/spec/rubocop/cop/bundler/duplicated_gem_spec.rb +++ b/spec/rubocop/cop/bundler/duplicated_gem_spec.rb @@ -31,7 +31,7 @@ context 'and a gem is duplicated in default group' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') source 'https://rubygems.org' gem 'rubocop' gem 'rubocop' @@ -42,7 +42,7 @@ context 'and a duplicated gem is in a git/path/group/platforms block' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') gem 'rubocop' group :development do gem 'rubocop', path: '/path/to/gem' @@ -53,7 +53,7 @@ end it 'registers an offense when gem from default group is conditionally duplicated' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') gem 'rubocop' if Dir.exist? local gem 'rubocop', path: local @@ -66,7 +66,7 @@ end it 'does not register an offense when gem is duplicated within `if-else` statement' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') if Dir.exist?(local) gem 'rubocop', path: local gem 'flog', path: local @@ -77,7 +77,7 @@ end it 'does not register an offense when gem is duplicated within `if-elsif` statement' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') if Dir.exist?(local) gem 'rubocop', path: local elsif ENV['RUBOCOP_VERSION'] == 'master' @@ -91,7 +91,7 @@ end it 'does not register an offense when gem is duplicated within `case` statement' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') case when Dir.exist?(local) gem 'rubocop', path: local diff --git a/spec/rubocop/cop/bundler/duplicated_group_spec.rb b/spec/rubocop/cop/bundler/duplicated_group_spec.rb index 4c9d100932c0..4a53bdd05c73 100644 --- a/spec/rubocop/cop/bundler/duplicated_group_spec.rb +++ b/spec/rubocop/cop/bundler/duplicated_group_spec.rb @@ -35,7 +35,7 @@ context 'and a group is duplicated' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') group :development do gem 'rubocop' end @@ -49,7 +49,7 @@ context 'and a group is duplicated using different argument types' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') group :development do gem 'rubocop' end @@ -137,7 +137,7 @@ context 'and a set of groups is duplicated' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') group :test, :development do gem 'rubocop' end @@ -151,7 +151,7 @@ context 'and a set of groups is duplicated but `source` URLs are different' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') source 'https://rubygems.pkg.github.com/private-org' do group :development do gem 'rubocop' @@ -167,7 +167,7 @@ context 'and a set of groups is duplicated and `source` URLs are the same' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') source 'https://rubygems.pkg.github.com/private-org' do group :development do gem 'rubocop' @@ -190,7 +190,7 @@ context 'and a set of groups is duplicated but `git` URLs are different' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') git 'https://github.com/rubocop/rubocop.git' do group :default do gem 'rubocop' @@ -209,7 +209,7 @@ context 'and a set of groups is duplicated and `git` URLs are the same' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') git 'https://github.com/rails/rails.git' do group :default do gem 'activesupport' @@ -228,7 +228,7 @@ context 'and a set of groups is duplicated but `platforms` values are different' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') platforms :ruby do group :default do gem 'openssl' @@ -246,7 +246,7 @@ context 'and a set of groups is duplicated and `platforms` values are the same' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') platforms :ruby do group :default do gem 'ruby-debug' @@ -265,7 +265,7 @@ context 'and a set of groups is duplicated but `path` values are different' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') path 'components_admin' do group :default do gem 'admin_ui' @@ -283,7 +283,7 @@ context 'and a set of groups is duplicated and `path` values are the same' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') path 'components' do group :default do gem 'admin_ui' @@ -302,7 +302,7 @@ context 'when `source` URL argument is not given' do it 'does not crash' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') source do group :development do gem 'rubocop' diff --git a/spec/rubocop/cop/bundler/gem_comment_spec.rb b/spec/rubocop/cop/bundler/gem_comment_spec.rb index db75dbb5bca5..a739124f5680 100644 --- a/spec/rubocop/cop/bundler/gem_comment_spec.rb +++ b/spec/rubocop/cop/bundler/gem_comment_spec.rb @@ -64,7 +64,7 @@ context 'and a gem has no comment' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') gem 'rubocop' ^^^^^^^^^^^^^ Missing gem description comment. RUBY @@ -88,15 +88,15 @@ context 'when a gem is uncommented and has no version specified' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY, 'Gemfile') - gem 'rubocop' + expect_no_offenses(<<~RUBY, 'Gemfile') + gem 'rubocop' RUBY end end context 'when a gem is uncommented and has options but no version specifiers' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') gem 'rubocop', group: development RUBY end @@ -104,25 +104,25 @@ context 'when a gem is uncommented and has a version specifier' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') - gem 'rubocop', '~> 12.0' - ^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. + expect_offense(<<~RUBY, 'Gemfile') + gem 'rubocop', '~> 12.0' + ^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. RUBY end end context 'when a gem is uncommented and has multiple version specifiers' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') - gem 'rubocop', '~> 12.0', '>= 11.0' - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. + expect_offense(<<~RUBY, 'Gemfile') + gem 'rubocop', '~> 12.0', '>= 11.0' + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. RUBY end end context 'when a gem is uncommented and has a version specifier along with other options' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') gem 'rubocop', '~> 12.0', required: true ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. RUBY @@ -144,15 +144,15 @@ context 'when a gem is uncommented and has no version specified' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY, 'Gemfile') - gem 'rubocop' + expect_no_offenses(<<~RUBY, 'Gemfile') + gem 'rubocop' RUBY end end context 'when a gem is uncommented and has options but no version specifiers' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') gem 'rubocop', group: development RUBY end @@ -160,7 +160,7 @@ context 'when a gem is uncommented and has only a minimum version specifier' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') gem 'rubocop', '>= 12.0' RUBY end @@ -168,52 +168,52 @@ context 'when a gem is uncommented and has a non-minimum version specifier with a leading space' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') - gem 'rubocop', ' ~> 12.0' - ^^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. + expect_offense(<<~RUBY, 'Gemfile') + gem 'rubocop', ' ~> 12.0' + ^^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. RUBY end end context 'when a gem is uncommented and has a version specifier without operator' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') - gem 'rubocop', '12.0' - ^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. + expect_offense(<<~RUBY, 'Gemfile') + gem 'rubocop', '12.0' + ^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. RUBY end end context 'when a gem is uncommented and has a frozen version specifier' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') - gem 'rubocop', '= 12.0' - ^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. + expect_offense(<<~RUBY, 'Gemfile') + gem 'rubocop', '= 12.0' + ^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. RUBY end end context 'when a gem is uncommented and has a pessimistic version specifier' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') - gem 'rubocop', '~> 12.0' - ^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. + expect_offense(<<~RUBY, 'Gemfile') + gem 'rubocop', '~> 12.0' + ^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. RUBY end end context 'when a gem is uncommented and has both minimum and non-minimum version specifier' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') - gem 'rubocop', '~> 12.0', '>= 11.0' - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. + expect_offense(<<~RUBY, 'Gemfile') + gem 'rubocop', '~> 12.0', '>= 11.0' + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. RUBY end end context 'when a gem is uncommented and has a version specifier along with other options' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') gem 'rubocop', '~> 12.0', required: true ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. RUBY @@ -226,7 +226,7 @@ context 'when a gem is uncommented and has one of the specified options' do it 'registers an offense' do - expect_offense(<<-RUBY, 'Gemfile') + expect_offense(<<~RUBY, 'Gemfile') gem 'rubocop', github: 'some_user/some_fork' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing gem description comment. RUBY @@ -235,7 +235,7 @@ context 'when a gem is uncommented and has a version specifier but none of the specified options' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') gem 'rubocop', '~> 12.0' RUBY end @@ -243,7 +243,7 @@ context 'when a gem is uncommented and contains only options not specified' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY, 'Gemfile') + expect_no_offenses(<<~RUBY, 'Gemfile') gem 'rubocop', group: development RUBY end diff --git a/spec/rubocop/cop/layout/class_structure_spec.rb b/spec/rubocop/cop/layout/class_structure_spec.rb index 2fdca4d94c26..80f0212daeb3 100644 --- a/spec/rubocop/cop/layout/class_structure_spec.rb +++ b/spec/rubocop/cop/layout/class_structure_spec.rb @@ -41,7 +41,7 @@ context 'when the first line ends with a comment' do it 'reports an offense and swaps the lines' do - expect_offense <<-RUBY + expect_offense <<~RUBY class GridTask DESC = 'Grid Task' # grid task name OID, subclasses should set this extend Helpers::MakeFromFile @@ -49,7 +49,7 @@ class GridTask end RUBY - expect_correction <<-RUBY + expect_correction <<~RUBY class GridTask extend Helpers::MakeFromFile DESC = 'Grid Task' # grid task name OID, subclasses should set this @@ -60,7 +60,7 @@ class GridTask context 'with a complete ordered example' do it 'does not create offense' do - expect_no_offenses <<-RUBY + expect_no_offenses <<~RUBY class Person # extend and include go first extend SomeModule @@ -154,7 +154,7 @@ def instance_method; end end context 'with protected methods declared before private' do - let(:code) { <<-RUBY } + let(:code) { <<~RUBY } class MyClass def public_method end @@ -182,7 +182,7 @@ def second_protected_method end context 'with attribute macros before after validations' do - let(:code) { <<-RUBY } + let(:code) { <<~RUBY } class Person include AnotherModule extend SomeModule diff --git a/spec/rubocop/cop/layout/comment_indentation_spec.rb b/spec/rubocop/cop/layout/comment_indentation_spec.rb index fd567d802ca6..9e68b5af2394 100644 --- a/spec/rubocop/cop/layout/comment_indentation_spec.rb +++ b/spec/rubocop/cop/layout/comment_indentation_spec.rb @@ -45,8 +45,8 @@ | ^^^^^^^^^ Incorrect indentation detected (column 1 instead of 0). RUBY - expect_correction(<<-RUBY.strip_margin('|')) - |# comment + expect_correction(<<~RUBY) + # comment RUBY end @@ -56,8 +56,8 @@ | ^^^^^^^^^ Incorrect indentation detected (column 2 instead of 0). RUBY - expect_correction(<<-RUBY.strip_margin('|')) - |# comment + expect_correction(<<~RUBY) + # comment RUBY end diff --git a/spec/rubocop/cop/layout/empty_lines_around_begin_body_spec.rb b/spec/rubocop/cop/layout/empty_lines_around_begin_body_spec.rb index 31a32f12dacf..05787fe96c5c 100644 --- a/spec/rubocop/cop/layout/empty_lines_around_begin_body_spec.rb +++ b/spec/rubocop/cop/layout/empty_lines_around_begin_body_spec.rb @@ -201,14 +201,13 @@ def bar RUBY end - include_examples 'accepts', 'begin block without empty line', <<-RUBY + include_examples 'accepts', 'begin block without empty line', <<~RUBY begin foo end RUBY - include_examples 'accepts', - 'begin block without empty line in a method', <<-RUBY + include_examples 'accepts', 'begin block without empty line in a method', <<~RUBY def foo begin bar diff --git a/spec/rubocop/cop/layout/initial_indentation_spec.rb b/spec/rubocop/cop/layout/initial_indentation_spec.rb index 9a0d1c566c8d..98d378b8a0d9 100644 --- a/spec/rubocop/cop/layout/initial_indentation_spec.rb +++ b/spec/rubocop/cop/layout/initial_indentation_spec.rb @@ -8,9 +8,9 @@ | end RUBY - expect_correction(<<-RUBY.strip_margin('|')) - |def f - | end + expect_correction(<<~RUBY) + def f + end RUBY end @@ -62,9 +62,9 @@ def f | ^ Indentation of first line in file detected. RUBY - expect_correction(<<-RUBY.strip_margin('|')) - | # comment - |x = 1 + expect_correction(<<~RUBY) + # comment + x = 1 RUBY end diff --git a/spec/rubocop/cop/layout/rescue_ensure_alignment_spec.rb b/spec/rubocop/cop/layout/rescue_ensure_alignment_spec.rb index b818dc10d652..223c66299cd1 100644 --- a/spec/rubocop/cop/layout/rescue_ensure_alignment_spec.rb +++ b/spec/rubocop/cop/layout/rescue_ensure_alignment_spec.rb @@ -430,7 +430,7 @@ def foo end it 'accepts correctly aligned rescue in assigned begin-end block' do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) foo = begin bar rescue BazError diff --git a/spec/rubocop/cop/layout/space_inside_percent_literal_delimiters_spec.rb b/spec/rubocop/cop/layout/space_inside_percent_literal_delimiters_spec.rb index e7c997c3c767..75fdf086294b 100644 --- a/spec/rubocop/cop/layout/space_inside_percent_literal_delimiters_spec.rb +++ b/spec/rubocop/cop/layout/space_inside_percent_literal_delimiters_spec.rb @@ -121,7 +121,7 @@ def foo end it 'accepts other percent literals' do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) %q( a b c ) %r( a b c ) %s( a b c ) diff --git a/spec/rubocop/cop/layout/space_inside_reference_brackets_spec.rb b/spec/rubocop/cop/layout/space_inside_reference_brackets_spec.rb index 685b0da6edc8..91523acfc8e2 100644 --- a/spec/rubocop/cop/layout/space_inside_reference_brackets_spec.rb +++ b/spec/rubocop/cop/layout/space_inside_reference_brackets_spec.rb @@ -118,7 +118,7 @@ end it 'does not register offense for non-empty brackets with newline inside' do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) foo[ bar ] diff --git a/spec/rubocop/cop/lint/duplicate_methods_spec.rb b/spec/rubocop/cop/lint/duplicate_methods_spec.rb index 35f6a177ea38..91eac51a65fb 100644 --- a/spec/rubocop/cop/lint/duplicate_methods_spec.rb +++ b/spec/rubocop/cop/lint/duplicate_methods_spec.rb @@ -250,7 +250,7 @@ def some_method end it "registers an offense for duplicate alias in #{type}" do - expect_offense(<<-RUBY, 'example.rb') + expect_offense(<<~RUBY, 'example.rb') #{opening_line} def some_method implement 1 @@ -262,7 +262,7 @@ def some_method end it "doesn't register an offense for non-duplicate alias in #{type}" do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) #{opening_line} def some_method implement 1 @@ -273,7 +273,7 @@ def some_method end it "registers an offense for duplicate alias_method in #{type}" do - expect_offense(<<-RUBY, 'example.rb') + expect_offense(<<~RUBY, 'example.rb') #{opening_line} def some_method implement 1 @@ -285,7 +285,7 @@ def some_method end it "accepts for non-duplicate alias_method in #{type}" do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) #{opening_line} def some_method implement 1 @@ -296,7 +296,7 @@ def some_method end it "doesn't register an offense for alias for gvar in #{type}" do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) #{opening_line} alias $foo $bar end @@ -304,7 +304,7 @@ def some_method end it "registers an offense for duplicate attr_reader in #{type}" do - expect_offense(<<-RUBY, 'example.rb') + expect_offense(<<~RUBY, 'example.rb') #{opening_line} def something end @@ -315,7 +315,7 @@ def something end it "registers an offense for duplicate attr_writer in #{type}" do - expect_offense(<<-RUBY, 'example.rb') + expect_offense(<<~RUBY, 'example.rb') #{opening_line} def something=(right) end @@ -326,7 +326,7 @@ def something=(right) end it "registers offenses for duplicate attr_accessor in #{type}" do - expect_offense(<<-RUBY, 'example.rb') + expect_offense(<<~RUBY, 'example.rb') #{opening_line} attr_accessor :something @@ -341,7 +341,7 @@ def something=(right) end it "registers an offense for duplicate attr in #{type}" do - expect_offense(<<-RUBY, 'example.rb') + expect_offense(<<~RUBY, 'example.rb') #{opening_line} def something end @@ -352,7 +352,7 @@ def something end it "registers offenses for duplicate assignable attr in #{type}" do - expect_offense(<<-RUBY, 'example.rb') + expect_offense(<<~RUBY, 'example.rb') #{opening_line} attr :something, true @@ -367,7 +367,7 @@ def something=(right) end it "accepts for attr_reader and setter in #{type}" do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) #{opening_line} def something=(right) end @@ -377,7 +377,7 @@ def something=(right) end it "accepts for attr_writer and getter in #{type}" do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) #{opening_line} def something end @@ -387,7 +387,7 @@ def something end it "registers an offense for duplicate nested method in #{type}" do - expect_offense(<<-RUBY, 'example.rb') + expect_offense(<<~RUBY, 'example.rb') #{opening_line} def foo def some_method @@ -407,7 +407,7 @@ def some_method end it "registers an offense for duplicate nested method in self method of #{type}" do - expect_offense(<<-RUBY, 'example.rb') + expect_offense(<<~RUBY, 'example.rb') #{opening_line} def self.foo def some_method diff --git a/spec/rubocop/cop/lint/no_return_in_begin_end_blocks_spec.rb b/spec/rubocop/cop/lint/no_return_in_begin_end_blocks_spec.rb index 977ae760d93a..ae1761b18e07 100644 --- a/spec/rubocop/cop/lint/no_return_in_begin_end_blocks_spec.rb +++ b/spec/rubocop/cop/lint/no_return_in_begin_end_blocks_spec.rb @@ -3,7 +3,7 @@ RSpec.describe RuboCop::Cop::Lint::NoReturnInBeginEndBlocks, :config do shared_examples 'rejects return inside a block' do |operator| it "rejects a return statement inside a block when using #{operator}" do - expect_offense(<<-RUBY) + expect_offense(<<~RUBY) some_value = 10 some_value #{operator} begin @@ -17,7 +17,7 @@ shared_examples 'accepts a block with no return' do |operator| it "accepts a block with no return when using #{operator}" do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) @good_method #{operator} begin if rand(1..2).odd? "odd number" diff --git a/spec/rubocop/cop/lint/percent_string_array_spec.rb b/spec/rubocop/cop/lint/percent_string_array_spec.rb index e6a0efa2bf29..0a6fd8a4dea7 100644 --- a/spec/rubocop/cop/lint/percent_string_array_spec.rb +++ b/spec/rubocop/cop/lint/percent_string_array_spec.rb @@ -66,12 +66,12 @@ context 'with invalid byte sequence in UTF-8' do it 'add an offense and corrects when tokens contain quotes' do - expect_offense(<<-RUBY) + expect_offense(<<~RUBY) %W("a\\255\\255") ^^^^^^^^^^^^^^^ Within `%w`/`%W`, quotes and ',' are unnecessary and may be unwanted in the resulting strings. RUBY - expect_correction(<<-RUBY) + expect_correction(<<~RUBY) %W(a\\255\\255) RUBY end diff --git a/spec/rubocop/cop/lint/rescue_type_spec.rb b/spec/rubocop/cop/lint/rescue_type_spec.rb index 9dfe246388ec..5ccf17cf6cad 100644 --- a/spec/rubocop/cop/lint/rescue_type_spec.rb +++ b/spec/rubocop/cop/lint/rescue_type_spec.rb @@ -6,7 +6,7 @@ end it 'accepts rescuing nothing' do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) begin foo rescue @@ -16,7 +16,7 @@ end it 'accepts rescuing a single exception' do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) def foobar foo rescue NameError @@ -26,8 +26,8 @@ def foobar end it 'accepts rescuing nothing within a method definition' do - expect_no_offenses(<<-RUBY) - def foobar + expect_no_offenses(<<~RUBY) + def foobar foo rescue bar diff --git a/spec/rubocop/cop/lint/syntax_spec.rb b/spec/rubocop/cop/lint/syntax_spec.rb index 3bdf13512e96..a3cc58b5316a 100644 --- a/spec/rubocop/cop/lint/syntax_spec.rb +++ b/spec/rubocop/cop/lint/syntax_spec.rb @@ -53,7 +53,7 @@ end context 'with a parser error' do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } # \xf9 RUBY diff --git a/spec/rubocop/cop/naming/inclusive_language_spec.rb b/spec/rubocop/cop/naming/inclusive_language_spec.rb index 914ec3ecda12..accdd764822b 100644 --- a/spec/rubocop/cop/naming/inclusive_language_spec.rb +++ b/spec/rubocop/cop/naming/inclusive_language_spec.rb @@ -354,7 +354,7 @@ class Nodewhitelist end it 'does not register offenses and not raise `ArgumentError` for invalid byte sequence in UTF-8' do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) %W("a\\255\\255") RUBY end diff --git a/spec/rubocop/cop/style/documentation_method_spec.rb b/spec/rubocop/cop/style/documentation_method_spec.rb index b05655d2478b..5bbc0dad51ad 100644 --- a/spec/rubocop/cop/style/documentation_method_spec.rb +++ b/spec/rubocop/cop/style/documentation_method_spec.rb @@ -387,7 +387,7 @@ class Foo context 'with documentation comment' do context 'when method is public' do it 'does not register an offense' do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) class Foo # Documentation def bar diff --git a/spec/rubocop/cop/style/empty_lambda_parameter_spec.rb b/spec/rubocop/cop/style/empty_lambda_parameter_spec.rb index 9f7fcc6ddc75..33efa3843f67 100644 --- a/spec/rubocop/cop/style/empty_lambda_parameter_spec.rb +++ b/spec/rubocop/cop/style/empty_lambda_parameter_spec.rb @@ -13,13 +13,13 @@ end it 'accepts a keyword lambda' do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) lambda { || do_something } RUBY end it 'does not crash on a super' do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) def foo super { || do_something } end diff --git a/spec/rubocop/cop/style/return_nil_spec.rb b/spec/rubocop/cop/style/return_nil_spec.rb index 05428745e4d6..f546ac13bc14 100644 --- a/spec/rubocop/cop/style/return_nil_spec.rb +++ b/spec/rubocop/cop/style/return_nil_spec.rb @@ -27,7 +27,7 @@ end it 'does not register an offense for return nil from iterators' do - expect_no_offenses(<<-RUBY) + expect_no_offenses(<<~RUBY) loop do return if x end diff --git a/spec/rubocop/cop/style/string_concatenation_spec.rb b/spec/rubocop/cop/style/string_concatenation_spec.rb index ec95efe7d850..1286df4131b8 100644 --- a/spec/rubocop/cop/style/string_concatenation_spec.rb +++ b/spec/rubocop/cop/style/string_concatenation_spec.rb @@ -24,12 +24,12 @@ end it 'correctly handles strings with special characters' do - expect_offense(<<-RUBY) + expect_offense(<<~RUBY) email_with_name = "\\n" + user.name + ' ' + user.email + '\\n' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. RUBY - expect_correction(<<-RUBY) + expect_correction(<<~RUBY) email_with_name = "\\n\#{user.name} \#{user.email}\\\\n" RUBY end @@ -65,7 +65,7 @@ context 'simple expressions' do it 'registers an offense and corrects' do - expect_offense(<<-RUBY) + expect_offense(<<~RUBY) email_with_name = user.name + ^^^^^^^^^^^ Prefer string interpolation to string concatenation. ' ' + @@ -73,7 +73,7 @@ '\\n' RUBY - expect_correction(<<-RUBY) + expect_correction(<<~RUBY) email_with_name = "\#{user.name} \#{user.email}\\\\n" RUBY end @@ -159,23 +159,23 @@ context 'double quotes inside string' do it 'registers an offense and corrects with double quotes' do - expect_offense(<<-'RUBY') + expect_offense(<<~'RUBY') email_with_name = "He said " + "\"Arrest that man!\"." ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. RUBY - expect_correction(<<-'RUBY') + expect_correction(<<~'RUBY') email_with_name = "He said \"Arrest that man!\"." RUBY end it 'registers an offense and corrects with percentage quotes' do - expect_offense(<<-RUBY) + expect_offense(<<~RUBY) email_with_name = %(He said ) + %("Arrest that man!".) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. RUBY - expect_correction(<<-'RUBY') + expect_correction(<<~'RUBY') email_with_name = "He said \"Arrest that man!\"." RUBY end @@ -183,7 +183,7 @@ context 'empty quotes' do it 'registers offense and corrects' do - expect_offense(<<-RUBY) + expect_offense(<<~RUBY) '"' + "foo" + '"' ^^^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. '"' + "foo" + "'" @@ -194,7 +194,7 @@ ^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. RUBY - expect_correction(<<-'RUBY') + expect_correction(<<~'RUBY') "\"foo\"" "\"foo'" "'foo\"" @@ -205,12 +205,12 @@ context 'double quotes inside string surrounded single quotes' do it 'registers an offense and corrects with double quotes' do - expect_offense(<<-RUBY) + expect_offense(<<~RUBY) '"bar"' + foo ^^^^^^^^^^^^^ Prefer string interpolation to string concatenation. RUBY - expect_correction(<<-'RUBY') + expect_correction(<<~'RUBY') "\"bar\"#{foo}" RUBY end diff --git a/spec/rubocop/cop/style/symbol_array_spec.rb b/spec/rubocop/cop/style/symbol_array_spec.rb index 54d139c6d207..112d0c8eb3a9 100644 --- a/spec/rubocop/cop/style/symbol_array_spec.rb +++ b/spec/rubocop/cop/style/symbol_array_spec.rb @@ -228,7 +228,7 @@ end it 'autocorrects an array in multiple lines' do - expect_offense(<<-RUBY) + expect_offense(<<~RUBY) [ ^ Use `%i` or `%I` for an array of symbols. :foo, @@ -237,7 +237,7 @@ ] RUBY - expect_correction(<<-RUBY) + expect_correction(<<~RUBY) %i[ foo bar @@ -247,14 +247,14 @@ end it 'autocorrects an array using partial newlines' do - expect_offense(<<-RUBY) + expect_offense(<<~RUBY) [:foo, :bar, :baz, ^^^^^^^^^^^^^^^^^^ Use `%i` or `%I` for an array of symbols. :boz, :buz, :biz] RUBY - expect_correction(<<-RUBY) + expect_correction(<<~RUBY) %i[foo bar baz boz buz biz] diff --git a/spec/rubocop/cop/style/word_array_spec.rb b/spec/rubocop/cop/style/word_array_spec.rb index 80e9a9cc914a..a9b8741c513b 100644 --- a/spec/rubocop/cop/style/word_array_spec.rb +++ b/spec/rubocop/cop/style/word_array_spec.rb @@ -244,7 +244,7 @@ end it 'autocorrects an array of words in multiple lines' do - expect_offense(<<-RUBY) + expect_offense(<<~RUBY) [ ^ Use `%w` or `%W` for an array of words. "foo", @@ -253,7 +253,7 @@ ] RUBY - expect_correction(<<-RUBY) + expect_correction(<<~RUBY) %w( foo bar @@ -263,14 +263,14 @@ end it 'autocorrects an array of words using partial newlines' do - expect_offense(<<-RUBY) + expect_offense(<<~RUBY) ["foo", "bar", "baz", ^^^^^^^^^^^^^^^^^^^^^ Use `%w` or `%W` for an array of words. "boz", "buz", "biz"] RUBY - expect_correction(<<-RUBY) + expect_correction(<<~RUBY) %w(foo bar baz boz buz biz) diff --git a/spec/rubocop/cop/util_spec.rb b/spec/rubocop/cop/util_spec.rb index ed659bc570b9..6e47126a478f 100644 --- a/spec/rubocop/cop/util_spec.rb +++ b/spec/rubocop/cop/util_spec.rb @@ -5,7 +5,7 @@ describe '#line_range' do let(:source) do - <<-RUBY + <<~RUBY foo = 1 bar = 2 class Test @@ -46,7 +46,7 @@ def some_method describe '#same_line?' do let(:source) do - <<-RUBY + <<~RUBY @foo + @bar @baz RUBY diff --git a/spec/rubocop/cop/variable_force/assignment_spec.rb b/spec/rubocop/cop/variable_force/assignment_spec.rb index cb0e4f67de1e..a598fb7310e5 100644 --- a/spec/rubocop/cop/variable_force/assignment_spec.rb +++ b/spec/rubocop/cop/variable_force/assignment_spec.rb @@ -6,7 +6,7 @@ let(:ast) { RuboCop::ProcessedSource.new(source, ruby_version).ast } let(:source) do - <<-RUBY + <<~RUBY class SomeClass def some_method(flag) puts 'Hello World!' @@ -62,7 +62,7 @@ def some_method(flag) describe '#meta_assignment_node' do context 'when it is += operator assignment' do let(:source) do - <<-RUBY + <<~RUBY def some_method foo += 1 end @@ -76,7 +76,7 @@ def some_method context 'when it is ||= operator assignment' do let(:source) do - <<-RUBY + <<~RUBY def some_method foo ||= 1 end @@ -90,7 +90,7 @@ def some_method context 'when it is &&= operator assignment' do let(:source) do - <<-RUBY + <<~RUBY def some_method foo &&= 1 end @@ -104,7 +104,7 @@ def some_method context 'when it is multiple assignment' do let(:source) do - <<-RUBY + <<~RUBY def some_method foo, bar = [1, 2] end @@ -149,7 +149,7 @@ def some_method describe '#operator' do context 'when it is normal assignment' do let(:source) do - <<-RUBY + <<~RUBY def some_method foo = 1 end @@ -163,7 +163,7 @@ def some_method context 'when it is += operator assignment' do let(:source) do - <<-RUBY + <<~RUBY def some_method foo += 1 end @@ -177,7 +177,7 @@ def some_method context 'when it is ||= operator assignment' do let(:source) do - <<-RUBY + <<~RUBY def some_method foo ||= 1 end @@ -191,7 +191,7 @@ def some_method context 'when it is &&= operator assignment' do let(:source) do - <<-RUBY + <<~RUBY def some_method foo &&= 1 end @@ -205,7 +205,7 @@ def some_method context 'when it is multiple assignment' do let(:source) do - <<-RUBY + <<~RUBY def some_method foo, bar = [1, 2] end diff --git a/spec/rubocop/cop/variable_force/scope_spec.rb b/spec/rubocop/cop/variable_force/scope_spec.rb index e35d371cca26..ea0ce598c503 100644 --- a/spec/rubocop/cop/variable_force/scope_spec.rb +++ b/spec/rubocop/cop/variable_force/scope_spec.rb @@ -27,7 +27,7 @@ describe '#name' do context 'when the scope is instance method definition' do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } def some_method end RUBY @@ -40,7 +40,7 @@ def some_method end context 'when the scope is singleton method definition' do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } def self.some_method end RUBY @@ -62,7 +62,7 @@ def self.some_method context 'when the scope is instance method' do let(:source) do - <<-RUBY + <<~RUBY def some_method this_is_target end @@ -76,7 +76,7 @@ def some_method context 'when the scope is singleton method' do let(:source) do - <<-RUBY + <<~RUBY def self.some_method this_is_target end @@ -90,7 +90,7 @@ def self.some_method context 'when the scope is module' do let(:source) do - <<-RUBY + <<~RUBY module SomeModule this_is_target end @@ -104,7 +104,7 @@ module SomeModule context 'when the scope is class' do let(:source) do - <<-RUBY + <<~RUBY class SomeClass this_is_target end @@ -118,7 +118,7 @@ class SomeClass context 'when the scope is singleton class' do let(:source) do - <<-RUBY + <<~RUBY class << self this_is_target end @@ -132,7 +132,7 @@ class << self context 'when the scope is block' do let(:source) do - <<-RUBY + <<~RUBY 1.times do this_is_target end @@ -146,7 +146,7 @@ class << self context 'when the scope is top level' do let(:source) do - <<-RUBY + <<~RUBY this_is_target RUBY end @@ -160,7 +160,7 @@ class << self describe '#include?' do subject { scope.include?(target_node) } - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } class SomeClass def self.some_method(arg1, arg2) do_something @@ -218,7 +218,7 @@ def self.some_method(arg1, arg2) describe 'outer scope boundary handling' do context 'when the scope is instance method' do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } def some_method(arg1, arg2) :body end @@ -231,7 +231,7 @@ def some_method(arg1, arg2) end context 'when the scope is singleton method' do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } def self.some_method(arg1, arg2) :body end @@ -244,7 +244,7 @@ def self.some_method(arg1, arg2) end context 'when the scope is module' do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } module SomeModule :body end @@ -257,7 +257,7 @@ module SomeModule end context 'when the scope is class' do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } some_super_class = Class.new class SomeClass < some_super_class @@ -272,7 +272,7 @@ class SomeClass < some_super_class end context 'when the scope is singleton class' do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } some_object = Object.new class << some_object @@ -287,7 +287,7 @@ class << some_object end context 'when the scope is block' do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } 1.times do |arg1, arg2| :body end @@ -300,7 +300,7 @@ class << some_object end context 'when the scope is top level' do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } :body RUBY @@ -313,7 +313,7 @@ class << some_object describe 'inner scope boundary handling' do context "when there's a method invocation with block" do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } foo = 1 do_something(1, 2) do |arg| @@ -330,7 +330,7 @@ class << some_object end context "when there's a singleton method definition" do - let(:source) { <<-RUBY } + let(:source) { <<~RUBY } foo = 1 def self.some_method(arg1, arg2) diff --git a/spec/rubocop/target_finder_spec.rb b/spec/rubocop/target_finder_spec.rb index f420f8e3ad20..8bc2be023466 100755 --- a/spec/rubocop/target_finder_spec.rb +++ b/spec/rubocop/target_finder_spec.rb @@ -263,7 +263,7 @@ context 'when local AllCops/Include lists two patterns' do before do - create_file('.rubocop.yml', <<-YAML) + create_file('.rubocop.yml', <<~YAML) AllCops: Include: - '**/*.rb' @@ -277,7 +277,7 @@ context 'when a subdirectory AllCops/Include only lists one pattern' do before do - create_file('dir2/.rubocop.yml', <<-YAML) + create_file('dir2/.rubocop.yml', <<~YAML) AllCops: Include: - '**/*.ruby' @@ -345,7 +345,7 @@ context 'when local AllCops/Include lists two patterns' do before do - create_file('.rubocop.yml', <<-YAML) + create_file('.rubocop.yml', <<~YAML) AllCops: Include: - '**/*.rb' @@ -357,7 +357,7 @@ context 'when a subdirectory AllCops/Include only lists one pattern' do before do - create_file('dir2/.rubocop.yml', <<-YAML) + create_file('dir2/.rubocop.yml', <<~YAML) AllCops: Include: - '**/*.ruby' diff --git a/spec/rubocop/target_ruby_spec.rb b/spec/rubocop/target_ruby_spec.rb index 44cf94c4478e..53b3df1007ca 100644 --- a/spec/rubocop/target_ruby_spec.rb +++ b/spec/rubocop/target_ruby_spec.rb @@ -150,145 +150,140 @@ let(:lock_file_path) { File.join(base_path, file_name) } it "uses MRI Ruby version when it is present in #{file_name}" do - content = - <<-HEREDOC - GEM - remote: https://rubygems.org/ - specs: - actionmailer (4.1.0) - actionpack (= 4.1.0) - rails (4.1.0) - actionmailer (= 4.1.0) - actionpack (= 4.1.0) - railties (= 4.1.0) - railties (4.1.0) - - PLATFORMS - ruby - - DEPENDENCIES - ruby-extensions (~> 1.9.0) - - RUBY VERSION - ruby 2.0.0p0 - - BUNDLED WITH - 1.16.1 - HEREDOC + content = <<~HEREDOC + GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.1.0) + actionpack (= 4.1.0) + rails (4.1.0) + actionmailer (= 4.1.0) + actionpack (= 4.1.0) + railties (= 4.1.0) + railties (4.1.0) + + PLATFORMS + ruby + + DEPENDENCIES + ruby-extensions (~> 1.9.0) + + RUBY VERSION + ruby 2.0.0p0 + + BUNDLED WITH + 1.16.1 + HEREDOC create_file(lock_file_path, content) expect(target_ruby.version).to eq 2.0 end it 'uses MRI Ruby version when it has multiple digits' do - content = - <<-HEREDOC - GEM - remote: https://rubygems.org/ - specs: - actionmailer (4.1.0) - actionpack (= 4.1.0) - rails (4.1.0) - actionmailer (= 4.1.0) - actionpack (= 4.1.0) - railties (= 4.1.0) - railties (4.1.0) - - PLATFORMS - ruby - - DEPENDENCIES - ruby-extensions (~> 1.9.0) - - RUBY VERSION - ruby 20.10.100p450 - - BUNDLED WITH - 1.16.1 - HEREDOC + content = <<~HEREDOC + GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.1.0) + actionpack (= 4.1.0) + rails (4.1.0) + actionmailer (= 4.1.0) + actionpack (= 4.1.0) + railties (= 4.1.0) + railties (4.1.0) + + PLATFORMS + ruby + + DEPENDENCIES + ruby-extensions (~> 1.9.0) + + RUBY VERSION + ruby 20.10.100p450 + + BUNDLED WITH + 1.16.1 + HEREDOC create_file(lock_file_path, content) expect(target_ruby.version).to eq 20.10 end it "uses the default Ruby when Ruby is not in #{file_name}" do - content = - <<-HEREDOC - GEM - remote: https://rubygems.org/ - specs: - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) - ast (2.4.0) - bump (0.5.4) - - PLATFORMS - ruby - - DEPENDENCIES - bump - bundler (~> 1.3) - ruby-extensions (~> 1.9.0) - - BUNDLED WITH - 1.16.1 - HEREDOC + content = <<~HEREDOC + GEM + remote: https://rubygems.org/ + specs: + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + ast (2.4.0) + bump (0.5.4) + + PLATFORMS + ruby + + DEPENDENCIES + bump + bundler (~> 1.3) + ruby-extensions (~> 1.9.0) + + BUNDLED WITH + 1.16.1 + HEREDOC create_file(lock_file_path, content) expect(target_ruby.version).to eq default_version end it "uses the default Ruby when rbx is in #{file_name}" do - content = - <<-HEREDOC - GEM - remote: https://rubygems.org/ - specs: - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) - ast (2.4.0) - bump (0.5.4) - - PLATFORMS - ruby - - DEPENDENCIES - bump - bundler (~> 1.3) - ruby-extensions (~> 1.9.0) - - RUBY VERSION - ruby 2.0.0p0 (rbx 3.42) - - BUNDLED WITH - 1.16.1 - HEREDOC + content = <<~HEREDOC + GEM + remote: https://rubygems.org/ + specs: + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + ast (2.4.0) + bump (0.5.4) + + PLATFORMS + ruby + + DEPENDENCIES + bump + bundler (~> 1.3) + ruby-extensions (~> 1.9.0) + + RUBY VERSION + ruby 2.0.0p0 (rbx 3.42) + + BUNDLED WITH + 1.16.1 + HEREDOC create_file(lock_file_path, content) expect(target_ruby.version).to eq default_version end it "uses the default Ruby when jruby is in #{file_name}" do - content = - <<-HEREDOC - GEM - remote: https://rubygems.org/ - specs: - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) - ast (2.4.0) - bump (0.5.4) - - PLATFORMS - ruby - - DEPENDENCIES - bump - bundler (~> 1.3) - ruby-extensions (~> 1.9.0) - - RUBY VERSION - ruby 2.0.0p0 (jruby 9.1.13.0) - - BUNDLED WITH - 1.16.1 - HEREDOC + content = <<~HEREDOC + GEM + remote: https://rubygems.org/ + specs: + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + ast (2.4.0) + bump (0.5.4) + + PLATFORMS + ruby + + DEPENDENCIES + bump + bundler (~> 1.3) + ruby-extensions (~> 1.9.0) + + RUBY VERSION + ruby 2.0.0p0 (jruby 9.1.13.0) + + BUNDLED WITH + 1.16.1 + HEREDOC create_file(lock_file_path, content) expect(target_ruby.version).to eq default_version end @@ -307,42 +302,39 @@ let(:gemspec_file_path) { File.join(base_path, 'example.gemspec') } it 'sets target_ruby from inclusive range' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.required_ruby_version = '>= 2.7.2' - s.licenses = ['MIT'] - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = '>= 2.7.2' + s.licenses = ['MIT'] + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq 2.7 end it 'sets target_ruby from exclusive range' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.required_ruby_version = '> 2.7.8' - s.licenses = ['MIT'] - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = '> 2.7.8' + s.licenses = ['MIT'] + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq 2.7 end it 'sets target_ruby from approximate version' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.required_ruby_version = '~> 2.7.0' - s.licenses = ['MIT'] - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = '~> 2.7.0' + s.licenses = ['MIT'] + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq 2.7 @@ -354,84 +346,78 @@ let(:gemspec_file_path) { File.join(base_path, 'example.gemspec') } it 'sets target_ruby from required_ruby_version from inclusive requirement range' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.required_ruby_version = Gem::Requirement.new('>= 2.3.1') - s.licenses = ['MIT'] - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = Gem::Requirement.new('>= 2.3.1') + s.licenses = ['MIT'] + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq default_version end it 'sets first known ruby version that satisfies requirement' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.required_ruby_version = Gem::Requirement.new('< 3.0.0') - s.licenses = ['MIT'] - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = Gem::Requirement.new('< 3.0.0') + s.licenses = ['MIT'] + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq default_version end it 'sets first known ruby version that satisfies range requirement' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.required_ruby_version = Gem::Requirement.new('>= 2.3.1', '< 3.0.0') - s.licenses = ['MIT'] - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = Gem::Requirement.new('>= 2.3.1', '< 3.0.0') + s.licenses = ['MIT'] + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq default_version end it 'sets first known ruby version that satisfies range requirement in array notation' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.required_ruby_version = Gem::Requirement.new(['>= 2.3.1', '< 3.0.0']) - s.licenses = ['MIT'] - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = Gem::Requirement.new(['>= 2.3.1', '< 3.0.0']) + s.licenses = ['MIT'] + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq default_version end it 'sets first known ruby version that satisfies range requirement with frozen strings' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.required_ruby_version = Gem::Requirement.new('>= 2.3.1'.freeze, '< 3.0.0'.freeze) - s.licenses = ['MIT'] - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = Gem::Requirement.new('>= 2.3.1'.freeze, '< 3.0.0'.freeze) + s.licenses = ['MIT'] + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq default_version end it 'sets first known ruby version that satisfies range requirement in array notation with frozen strings' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.required_ruby_version = Gem::Requirement.new(['>= 2.3.1'.freeze, '< 3.0.0'.freeze]) - s.licenses = ['MIT'] - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = Gem::Requirement.new(['>= 2.3.1'.freeze, '< 3.0.0'.freeze]) + s.licenses = ['MIT'] + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq default_version @@ -443,28 +429,26 @@ let(:gemspec_file_path) { File.join(base_path, 'example.gemspec') } it 'sets target_ruby to the minimal version satisfying the requirements' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.required_ruby_version = ['<=3.0.4', '>=2.7.5'] - s.licenses = ['MIT'] - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = ['<=3.0.4', '>=2.7.5'] + s.licenses = ['MIT'] + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq 2.7 end it 'sets target_ruby from required_ruby_version with many requirements' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.required_ruby_version = ['<=3.1.0', '>2.6.8', '~>2.7.1'] - s.licenses = ['MIT'] - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.required_ruby_version = ['<=3.1.0', '>2.6.8', '~>2.7.1'] + s.licenses = ['MIT'] + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq 2.7 @@ -476,15 +460,14 @@ let(:gemspec_file_path) { File.join(base_path, 'example.gemspec') } it 'sets default target_ruby' do - content = - <<-HEREDOC - Gem::Specification.new do |s| - s.name = 'test' - s.platform = Gem::Platform::RUBY - s.licenses = ['MIT'] - s.summary = 'test tool.' - end - HEREDOC + content = <<~HEREDOC + Gem::Specification.new do |s| + s.name = 'test' + s.platform = Gem::Platform::RUBY + s.licenses = ['MIT'] + s.summary = 'test tool.' + end + HEREDOC create_file(gemspec_file_path, content) expect(target_ruby.version).to eq default_version @@ -508,31 +491,30 @@ ['Gemfile.lock', 'gems.locked'].each do |file_name| context "when #{file_name} is in a parent directory" do it 'does' do - content = - <<-HEREDOC - GEM - remote: https://rubygems.org/ - specs: - actionmailer (4.1.0) - actionpack (= 4.1.0) - rails (4.1.0) - actionmailer (= 4.1.0) - actionpack (= 4.1.0) - railties (= 4.1.0) - railties (4.1.0) - - PLATFORMS - ruby - - DEPENDENCIES - ruby-extensions (~> 1.9.0) - - RUBY VERSION - ruby 2.0.0p0 - - BUNDLED WITH - 1.16.1 - HEREDOC + content = <<~HEREDOC + GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.1.0) + actionpack (= 4.1.0) + rails (4.1.0) + actionmailer (= 4.1.0) + actionpack (= 4.1.0) + railties (= 4.1.0) + railties (4.1.0) + + PLATFORMS + ruby + + DEPENDENCIES + ruby-extensions (~> 1.9.0) + + RUBY VERSION + ruby 2.0.0p0 + + BUNDLED WITH + 1.16.1 + HEREDOC dir = configuration.base_dir_for_path_parameters create_file(File.join(dir, '..', file_name), content) expect(target_ruby.version).to eq 2.0 From 75580b36f81ae08095b0d88eb854ab93f25141b2 Mon Sep 17 00:00:00 2001 From: r7kamura Date: Sat, 19 Aug 2023 20:23:03 +0900 Subject: [PATCH 16/20] Fix `Style/RedundantSelfAssignmentBranch` to handle heredocs --- ...lf_assignment_branch_to_handle_heredocs.md | 1 + .../style/redundant_self_assignment_branch.rb | 5 +++++ .../redundant_self_assignment_branch_spec.rb | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 changelog/fix_style_redundant_self_assignment_branch_to_handle_heredocs.md diff --git a/changelog/fix_style_redundant_self_assignment_branch_to_handle_heredocs.md b/changelog/fix_style_redundant_self_assignment_branch_to_handle_heredocs.md new file mode 100644 index 000000000000..1b363a0b6449 --- /dev/null +++ b/changelog/fix_style_redundant_self_assignment_branch_to_handle_heredocs.md @@ -0,0 +1 @@ +* [#12133](https://github.com/rubocop/rubocop/pull/12133): Fix `Style/RedundantSelfAssignmentBranch` to handle heredocs. ([@r7kamura][]) diff --git a/lib/rubocop/cop/style/redundant_self_assignment_branch.rb b/lib/rubocop/cop/style/redundant_self_assignment_branch.rb index cb0aec73bd1c..3340094e0606 100644 --- a/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +++ b/lib/rubocop/cop/style/redundant_self_assignment_branch.rb @@ -75,6 +75,11 @@ def register_offense(if_node, offense_branch, opposite_branch, keyword) add_offense(offense_branch) do |corrector| assignment_value = opposite_branch ? opposite_branch.source : 'nil' replacement = "#{assignment_value} #{keyword} #{if_node.condition.source}" + if opposite_branch.respond_to?(:heredoc?) && opposite_branch.heredoc? + replacement += opposite_branch.loc.heredoc_end.with( + begin_pos: opposite_branch.source_range.end_pos + ).source + end corrector.replace(if_node, replacement) end diff --git a/spec/rubocop/cop/style/redundant_self_assignment_branch_spec.rb b/spec/rubocop/cop/style/redundant_self_assignment_branch_spec.rb index 9b57e2313532..0c63eafc769e 100644 --- a/spec/rubocop/cop/style/redundant_self_assignment_branch_spec.rb +++ b/spec/rubocop/cop/style/redundant_self_assignment_branch_spec.rb @@ -93,6 +93,25 @@ RUBY end + it 'registers and corrects an offense when self-assigning redundant if branch with heredoc' do + expect_offense(<<~RUBY) + foo = if condition + foo + ^^^ Remove the self-assignment branch. + else + <<~TEXT + bar + TEXT + end + RUBY + + expect_correction(<<~RUBY) + foo = <<~TEXT unless condition + bar + TEXT + RUBY + end + it 'does not register an offense when self-assigning redundant else branch and multiline if branch' do expect_no_offenses(<<~RUBY) foo = if condition From ce93abdb36b8d1ac6f5732567e1cea13376a62b8 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sun, 20 Aug 2023 15:39:10 +0900 Subject: [PATCH 17/20] [Fix #12134] Fix a false positive for `Style/MethodCallWithArgsParentheses` Fixes #12134. This PR fixes a false positive for `Style/MethodCallWithArgsParentheses` when parentheses are used in one-line `in` pattern matching. --- ...r_style_method_call_with_args_parentheses.md | 1 + .../omit_parentheses.rb | 4 +++- .../method_call_with_args_parentheses_spec.rb | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 changelog/fix_a_false_positive_for_style_method_call_with_args_parentheses.md diff --git a/changelog/fix_a_false_positive_for_style_method_call_with_args_parentheses.md b/changelog/fix_a_false_positive_for_style_method_call_with_args_parentheses.md new file mode 100644 index 000000000000..af609e43e525 --- /dev/null +++ b/changelog/fix_a_false_positive_for_style_method_call_with_args_parentheses.md @@ -0,0 +1 @@ +* [#12134](https://github.com/rubocop/rubocop/issues/12134): Fix a false positive for `Style/MethodCallWithArgsParentheses` when parentheses are used in one-line `in` pattern matching. ([@koic][]) diff --git a/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb b/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb index b6e0c7909f5f..3bb110127a34 100644 --- a/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +++ b/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb @@ -146,7 +146,9 @@ def call_as_argument_or_chain?(node) end def call_in_match_pattern?(node) - node.parent&.match_pattern_type? + return false unless (parent = node.parent) + + parent.match_pattern_type? || parent.match_pattern_p_type? end def hash_literal_in_arguments?(node) diff --git a/spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb b/spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb index 941c026f7ec4..c3df1f69e013 100644 --- a/spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb +++ b/spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb @@ -961,7 +961,22 @@ def seatle_style arg: default(42) RUBY end - it 'accepts parens in singe-line pattern matching', :ruby30 do + # Ruby 2.7's one-line `in` pattern node type is `match-pattern`. + it 'accepts parens in one-line `in` pattern matching', :ruby27 do + expect_no_offenses(<<~RUBY) + execute(query) in {elapsed:, sql_count:} + RUBY + end + + # Ruby 3.0's one-line `in` pattern node type is `match-pattern-p`. + it 'accepts parens in one-line `in` pattern matching', :ruby30 do + expect_no_offenses(<<~RUBY) + execute(query) in {elapsed:, sql_count:} + RUBY + end + + # Ruby 3.0's one-line `=>` pattern node type is `match-pattern`. + it 'accepts parens in one-line `=>` pattern matching', :ruby30 do expect_no_offenses(<<~RUBY) execute(query) => {elapsed:, sql_count:} RUBY From 53433c4100d1628eed8518e5e1e8dfc1cb52c043 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Mon, 21 Aug 2023 01:02:46 +0900 Subject: [PATCH 18/20] Fix a false negative for `Layout/LeadingCommentSpace` This PR fixes a false negative for `Layout/LeadingCommentSpace` when using `#+` or `#-` as they are not RDoc comments. They are followed by `+` or `-` twice, such as `#++` and `#--`. --- ...se_negative_for_layout_leading_comment_space.md | 1 + lib/rubocop/cop/layout/leading_comment_space.rb | 2 +- .../cop/layout/leading_comment_space_spec.rb | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_a_false_negative_for_layout_leading_comment_space.md diff --git a/changelog/fix_a_false_negative_for_layout_leading_comment_space.md b/changelog/fix_a_false_negative_for_layout_leading_comment_space.md new file mode 100644 index 000000000000..88fe71307459 --- /dev/null +++ b/changelog/fix_a_false_negative_for_layout_leading_comment_space.md @@ -0,0 +1 @@ +* [#12136](https://github.com/rubocop/rubocop/pull/12136): Fix a false negative for `Layout/LeadingCommentSpace` when using `#+` or `#-` as they are not RDoc comments. ([@koic][]) diff --git a/lib/rubocop/cop/layout/leading_comment_space.rb b/lib/rubocop/cop/layout/leading_comment_space.rb index 9ea0ca0e4196..c1035029bd53 100644 --- a/lib/rubocop/cop/layout/leading_comment_space.rb +++ b/lib/rubocop/cop/layout/leading_comment_space.rb @@ -57,7 +57,7 @@ class LeadingCommentSpace < Base def on_new_investigation processed_source.comments.each do |comment| - next unless /\A#+[^#\s=+-]/.match?(comment.text) + next unless /\A(?!#\+\+|#--)(#+[^#\s=])/.match?(comment.text) next if comment.loc.line == 1 && allowed_on_first_line?(comment) next if doxygen_comment_style?(comment) next if gemfile_ruby_comment?(comment) diff --git a/spec/rubocop/cop/layout/leading_comment_space_spec.rb b/spec/rubocop/cop/layout/leading_comment_space_spec.rb index c9383df091a7..2e05bb266d5c 100644 --- a/spec/rubocop/cop/layout/leading_comment_space_spec.rb +++ b/spec/rubocop/cop/layout/leading_comment_space_spec.rb @@ -143,6 +143,20 @@ RUBY end + it 'registers an offense when using `#+` or `#-` as they are not RDoc comments' do + expect_offense(<<~RUBY) + #+ + ^^ Missing space after `#`. + #- + ^^ Missing space after `#`. + RUBY + + expect_correction(<<~RUBY) + # + + # - + RUBY + end + it 'registers an offense when starting `:`' do expect_offense(<<~RUBY) #:nodoc: From a3c111b38a1ea88c1c2edc47ad54260f51ed8bb1 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 21 Aug 2023 11:00:34 +0300 Subject: [PATCH 19/20] Update Changelog --- CHANGELOG.md | 15 +++++++++++++++ ...e_negative_for_layout_leading_comment_space.md | 1 - ...false_positive_for_bundler_duplicated_group.md | 1 - ...for_style_method_call_with_args_parentheses.md | 1 - .../fix_an_error_for_bundler_duplicated_group.md | 1 - ...forwarding_cop_when_forwarding_kwargs_block.md | 1 - ...forwarding_when_not_always_forwarding_block.md | 1 - changelog/fix_an_error_for_style_lambda.md | 1 - ...e_positives_for_style_redundant_parentheses.md | 1 - .../fix_false_positives_for_style_symbol_array.md | 1 - ...t_self_assignment_branch_to_handle_heredocs.md | 1 - ...rement_support_multiple_version_constraints.md | 1 - 12 files changed, 15 insertions(+), 11 deletions(-) delete mode 100644 changelog/fix_a_false_negative_for_layout_leading_comment_space.md delete mode 100644 changelog/fix_a_false_positive_for_bundler_duplicated_group.md delete mode 100644 changelog/fix_a_false_positive_for_style_method_call_with_args_parentheses.md delete mode 100644 changelog/fix_an_error_for_bundler_duplicated_group.md delete mode 100644 changelog/fix_an_error_for_style_arguments_forwarding_cop_when_forwarding_kwargs_block.md delete mode 100644 changelog/fix_an_error_for_style_arguments_forwarding_when_not_always_forwarding_block.md delete mode 100644 changelog/fix_an_error_for_style_lambda.md delete mode 100644 changelog/fix_false_positives_for_style_redundant_parentheses.md delete mode 100644 changelog/fix_false_positives_for_style_symbol_array.md delete mode 100644 changelog/fix_style_redundant_self_assignment_branch_to_handle_heredocs.md delete mode 100644 changelog/fix_target_ruby_gem_requirement_support_multiple_version_constraints.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 60f7e4e34599..7b3ecf6a8e03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,20 @@ ## master (unreleased) +### Bug fixes + +* [#12136](https://github.com/rubocop/rubocop/pull/12136): Fix a false negative for `Layout/LeadingCommentSpace` when using `#+` or `#-` as they are not RDoc comments. ([@koic][]) +* [#12113](https://github.com/rubocop/rubocop/issues/12113): Fix a false positive for `Bundler/DuplicatedGroup` when groups are duplicated but `source`, `git`, `platforms`, or `path` values are different. ([@koic][]) +* [#12134](https://github.com/rubocop/rubocop/issues/12134): Fix a false positive for `Style/MethodCallWithArgsParentheses` when parentheses are used in one-line `in` pattern matching. ([@koic][]) +* [#12111](https://github.com/rubocop/rubocop/issues/12111): Fix an error for `Bundler/DuplicatedGroup` group declaration has keyword option. ([@koic][]) +* [#12109](https://github.com/rubocop/rubocop/issues/12109): Fix an error for `Style/ArgumentsForwarding` cop when forwarding kwargs/block arg and an additional arg. ([@ydah][]) +* [#12117](https://github.com/rubocop/rubocop/issues/12117): Fix a false positive for `Style/ArgumentsForwarding` cop when not always forwarding block. ([@owst][]) +* [#12115](https://github.com/rubocop/rubocop/pull/12115): Fix an error for `Style/Lambda` when using numbered parameter with a multiline `->` call. ([@koic][]) +* [#12124](https://github.com/rubocop/rubocop/issues/12124): Fix false positives for `Style/RedundantParentheses` when parentheses in `super` or `yield` call with multiline style argument. ([@koic][]) +* [#12120](https://github.com/rubocop/rubocop/pull/12120): Fix false positives for `Style/SymbolArray` when `%i` array containing unescaped `[`, `]`, `(`, or `)`. ([@koic][]) +* [#12133](https://github.com/rubocop/rubocop/pull/12133): Fix `Style/RedundantSelfAssignmentBranch` to handle heredocs. ([@r7kamura][]) +* [#12105](https://github.com/rubocop/rubocop/issues/12105): Fix target ruby `Gem::Requirement` matcher and version parsing to support multiple version constraints. ([@ItsEcholot][]) + ## 1.56.0 (2023-08-09) ### New features @@ -7290,3 +7304,4 @@ [@p0deje]: https://github.com/p0deje [@bigzed]: https://github.com/bigzed [@OwlKing]: https://github.com/OwlKing +[@ItsEcholot]: https://github.com/ItsEcholot diff --git a/changelog/fix_a_false_negative_for_layout_leading_comment_space.md b/changelog/fix_a_false_negative_for_layout_leading_comment_space.md deleted file mode 100644 index 88fe71307459..000000000000 --- a/changelog/fix_a_false_negative_for_layout_leading_comment_space.md +++ /dev/null @@ -1 +0,0 @@ -* [#12136](https://github.com/rubocop/rubocop/pull/12136): Fix a false negative for `Layout/LeadingCommentSpace` when using `#+` or `#-` as they are not RDoc comments. ([@koic][]) diff --git a/changelog/fix_a_false_positive_for_bundler_duplicated_group.md b/changelog/fix_a_false_positive_for_bundler_duplicated_group.md deleted file mode 100644 index 3898d83db2bc..000000000000 --- a/changelog/fix_a_false_positive_for_bundler_duplicated_group.md +++ /dev/null @@ -1 +0,0 @@ -* [#12113](https://github.com/rubocop/rubocop/issues/12113): Fix a false positive for `Bundler/DuplicatedGroup` when groups are duplicated but `source`, `git`, `platforms`, or `path` values are different. ([@koic][]) diff --git a/changelog/fix_a_false_positive_for_style_method_call_with_args_parentheses.md b/changelog/fix_a_false_positive_for_style_method_call_with_args_parentheses.md deleted file mode 100644 index af609e43e525..000000000000 --- a/changelog/fix_a_false_positive_for_style_method_call_with_args_parentheses.md +++ /dev/null @@ -1 +0,0 @@ -* [#12134](https://github.com/rubocop/rubocop/issues/12134): Fix a false positive for `Style/MethodCallWithArgsParentheses` when parentheses are used in one-line `in` pattern matching. ([@koic][]) diff --git a/changelog/fix_an_error_for_bundler_duplicated_group.md b/changelog/fix_an_error_for_bundler_duplicated_group.md deleted file mode 100644 index 3bda40834ad1..000000000000 --- a/changelog/fix_an_error_for_bundler_duplicated_group.md +++ /dev/null @@ -1 +0,0 @@ -* [#12111](https://github.com/rubocop/rubocop/issues/12111): Fix an error for `Bundler/DuplicatedGroup` group declaration has keyword option. ([@koic][]) diff --git a/changelog/fix_an_error_for_style_arguments_forwarding_cop_when_forwarding_kwargs_block.md b/changelog/fix_an_error_for_style_arguments_forwarding_cop_when_forwarding_kwargs_block.md deleted file mode 100644 index 02ef67ee1c5f..000000000000 --- a/changelog/fix_an_error_for_style_arguments_forwarding_cop_when_forwarding_kwargs_block.md +++ /dev/null @@ -1 +0,0 @@ -* [#12109](https://github.com/rubocop/rubocop/issues/12109): Fix an error for `Style/ArgumentsForwarding` cop when forwarding kwargs/block arg and an additional arg. ([@ydah][]) diff --git a/changelog/fix_an_error_for_style_arguments_forwarding_when_not_always_forwarding_block.md b/changelog/fix_an_error_for_style_arguments_forwarding_when_not_always_forwarding_block.md deleted file mode 100644 index f04d137b0172..000000000000 --- a/changelog/fix_an_error_for_style_arguments_forwarding_when_not_always_forwarding_block.md +++ /dev/null @@ -1 +0,0 @@ -* [#12117](https://github.com/rubocop/rubocop/issues/12117): Fix a false positive for `Style/ArgumentsForwarding` cop when not always forwarding block. ([@owst][]) diff --git a/changelog/fix_an_error_for_style_lambda.md b/changelog/fix_an_error_for_style_lambda.md deleted file mode 100644 index e20de10547a4..000000000000 --- a/changelog/fix_an_error_for_style_lambda.md +++ /dev/null @@ -1 +0,0 @@ -* [#12115](https://github.com/rubocop/rubocop/pull/12115): Fix an error for `Style/Lambda` when using numbered parameter with a multiline `->` call. ([@koic][]) diff --git a/changelog/fix_false_positives_for_style_redundant_parentheses.md b/changelog/fix_false_positives_for_style_redundant_parentheses.md deleted file mode 100644 index 4a67a54d2f7f..000000000000 --- a/changelog/fix_false_positives_for_style_redundant_parentheses.md +++ /dev/null @@ -1 +0,0 @@ -* [#12124](https://github.com/rubocop/rubocop/issues/12124): Fix false positives for `Style/RedundantParentheses` when parentheses in `super` or `yield` call with multiline style argument. ([@koic][]) diff --git a/changelog/fix_false_positives_for_style_symbol_array.md b/changelog/fix_false_positives_for_style_symbol_array.md deleted file mode 100644 index e82b4d8d8d54..000000000000 --- a/changelog/fix_false_positives_for_style_symbol_array.md +++ /dev/null @@ -1 +0,0 @@ -* [#12120](https://github.com/rubocop/rubocop/pull/12120): Fix false positives for `Style/SymbolArray` when `%i` array containing unescaped `[`, `]`, `(`, or `)`. ([@koic][]) diff --git a/changelog/fix_style_redundant_self_assignment_branch_to_handle_heredocs.md b/changelog/fix_style_redundant_self_assignment_branch_to_handle_heredocs.md deleted file mode 100644 index 1b363a0b6449..000000000000 --- a/changelog/fix_style_redundant_self_assignment_branch_to_handle_heredocs.md +++ /dev/null @@ -1 +0,0 @@ -* [#12133](https://github.com/rubocop/rubocop/pull/12133): Fix `Style/RedundantSelfAssignmentBranch` to handle heredocs. ([@r7kamura][]) diff --git a/changelog/fix_target_ruby_gem_requirement_support_multiple_version_constraints.md b/changelog/fix_target_ruby_gem_requirement_support_multiple_version_constraints.md deleted file mode 100644 index d328498e1817..000000000000 --- a/changelog/fix_target_ruby_gem_requirement_support_multiple_version_constraints.md +++ /dev/null @@ -1 +0,0 @@ -* [#12105](https://github.com/rubocop/rubocop/issues/12105): Fix target ruby `Gem::Requirement` matcher and version parsing to support multiple version constraints. ([@ItsEcholot][]) From 24e7411d9606fd064e720ecb65a965646b6f8a06 Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 21 Aug 2023 11:01:01 +0300 Subject: [PATCH 20/20] Cut 1.56.1 --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- CHANGELOG.md | 2 ++ CONTRIBUTING.md | 2 +- docs/antora.yml | 2 +- docs/modules/ROOT/pages/cops_bundler.adoc | 18 ++++++++++++++++++ lib/rubocop/version.rb | 2 +- relnotes/v1.56.1.md | 19 +++++++++++++++++++ 7 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 relnotes/v1.56.1.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 148881598eb9..34c34ea7e47b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -38,7 +38,7 @@ output by `rubocop -V`, include them as well. Here's an example: ``` $ [bundle exec] rubocop -V -1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux] +1.56.1 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux] - rubocop-performance 1.18.0 - rubocop-rspec 2.23.2 ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b3ecf6a8e03..2a866cc80e63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ ## master (unreleased) +## 1.56.1 (2023-08-21) + ### Bug fixes * [#12136](https://github.com/rubocop/rubocop/pull/12136): Fix a false negative for `Layout/LeadingCommentSpace` when using `#+` or `#-` as they are not RDoc comments. ([@koic][]) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ca4d4f9fcbeb..07b916941df2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ do so. ```console $ rubocop -V -1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux] +1.56.1 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux] - rubocop-performance 1.18.0 - rubocop-rspec 2.23.2 ``` diff --git a/docs/antora.yml b/docs/antora.yml index 9c897ea03d1d..b4de30cfda13 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -2,6 +2,6 @@ name: rubocop title: RuboCop # We always provide version without patch here (e.g. 1.1), # as patch versions should not appear in the docs. -version: ~ +version: '1.56' nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/pages/cops_bundler.adoc b/docs/modules/ROOT/pages/cops_bundler.adoc index b73165ff2dc2..c81a4531f0ec 100644 --- a/docs/modules/ROOT/pages/cops_bundler.adoc +++ b/docs/modules/ROOT/pages/cops_bundler.adoc @@ -77,6 +77,24 @@ end A Gem group, or a set of groups, should be listed only once in a Gemfile. +For example, if the values of `source`, `git`, `platforms`, or `path` +surrounding `group` are different, no offense will be registered: + +[source,ruby] +----- +platforms :ruby do + group :default do + gem 'openssl' + end +end + +platforms :jruby do + group :default do + gem 'jruby-openssl' + end +end +----- + === Examples [source,ruby] diff --git a/lib/rubocop/version.rb b/lib/rubocop/version.rb index f3f5e071ad06..a85e8b3523c7 100644 --- a/lib/rubocop/version.rb +++ b/lib/rubocop/version.rb @@ -3,7 +3,7 @@ module RuboCop # This module holds the RuboCop version information. module Version - STRING = '1.56.0' + STRING = '1.56.1' MSG = '%s (using Parser %s, ' \ 'rubocop-ast %s, ' \ diff --git a/relnotes/v1.56.1.md b/relnotes/v1.56.1.md new file mode 100644 index 000000000000..1cf8a53d3d52 --- /dev/null +++ b/relnotes/v1.56.1.md @@ -0,0 +1,19 @@ +### Bug fixes + +* [#12136](https://github.com/rubocop/rubocop/pull/12136): Fix a false negative for `Layout/LeadingCommentSpace` when using `#+` or `#-` as they are not RDoc comments. ([@koic][]) +* [#12113](https://github.com/rubocop/rubocop/issues/12113): Fix a false positive for `Bundler/DuplicatedGroup` when groups are duplicated but `source`, `git`, `platforms`, or `path` values are different. ([@koic][]) +* [#12134](https://github.com/rubocop/rubocop/issues/12134): Fix a false positive for `Style/MethodCallWithArgsParentheses` when parentheses are used in one-line `in` pattern matching. ([@koic][]) +* [#12111](https://github.com/rubocop/rubocop/issues/12111): Fix an error for `Bundler/DuplicatedGroup` group declaration has keyword option. ([@koic][]) +* [#12109](https://github.com/rubocop/rubocop/issues/12109): Fix an error for `Style/ArgumentsForwarding` cop when forwarding kwargs/block arg and an additional arg. ([@ydah][]) +* [#12117](https://github.com/rubocop/rubocop/issues/12117): Fix a false positive for `Style/ArgumentsForwarding` cop when not always forwarding block. ([@owst][]) +* [#12115](https://github.com/rubocop/rubocop/pull/12115): Fix an error for `Style/Lambda` when using numbered parameter with a multiline `->` call. ([@koic][]) +* [#12124](https://github.com/rubocop/rubocop/issues/12124): Fix false positives for `Style/RedundantParentheses` when parentheses in `super` or `yield` call with multiline style argument. ([@koic][]) +* [#12120](https://github.com/rubocop/rubocop/pull/12120): Fix false positives for `Style/SymbolArray` when `%i` array containing unescaped `[`, `]`, `(`, or `)`. ([@koic][]) +* [#12133](https://github.com/rubocop/rubocop/pull/12133): Fix `Style/RedundantSelfAssignmentBranch` to handle heredocs. ([@r7kamura][]) +* [#12105](https://github.com/rubocop/rubocop/issues/12105): Fix target ruby `Gem::Requirement` matcher and version parsing to support multiple version constraints. ([@ItsEcholot][]) + +[@koic]: https://github.com/koic +[@ydah]: https://github.com/ydah +[@owst]: https://github.com/owst +[@r7kamura]: https://github.com/r7kamura +[@ItsEcholot]: https://github.com/ItsEcholot