From 4c525a8f09a54cd3f189a8526b662a93b3842c7d Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Thu, 23 Nov 2023 16:01:27 +0900 Subject: [PATCH] Require RuboCop 1.30+ as runtime dependency This PR makes RuboCop Performance require RuboCop 1.30+ to fix some errors: https://github.com/rubocop/rubocop-performance/actions/runs/6966652446/job/18957154150 It introduces CI for the oldest RuboCop version still supported, implementing a workflow for regression testing that is similar to the one found a https://github.com/rubocop/rubocop-rails/commit/c9acb7a. --- .github/workflows/test.yml | 33 +++++++++++++++++++ ...re_rubocop_1_33_as_a_runtime_dependency.md | 1 + .../cop/performance/redundant_merge.rb | 4 ++- rubocop-performance.gemspec | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 changelog/change_require_rubocop_1_33_as_a_runtime_dependency.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..28ede1c997 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + oldest_supported_rubocop: + runs-on: ubuntu-latest + name: The oldest supported RuboCop version + steps: + - uses: actions/checkout@v4 + - name: Use the oldest supported RuboCop + run: | + sed -e "/gem 'rubocop', github: 'rubocop\/rubocop'/d" \ + -e "/gem 'rubocop-rspec',/d" -i Gemfile + cat << EOF > Gemfile.local + gem 'rubocop', '1.30.0' # Specify the oldest supported RuboCop version + EOF + - name: set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7 + bundler-cache: true + - name: spec + run: bundle exec rake spec diff --git a/changelog/change_require_rubocop_1_33_as_a_runtime_dependency.md b/changelog/change_require_rubocop_1_33_as_a_runtime_dependency.md new file mode 100644 index 0000000000..48b258f7a9 --- /dev/null +++ b/changelog/change_require_rubocop_1_33_as_a_runtime_dependency.md @@ -0,0 +1 @@ +* [#388](https://github.com/rubocop/rubocop-performance/pull/388): Require RuboCop 1.30+ as runtime dependency. ([@koic][]) diff --git a/lib/rubocop/cop/performance/redundant_merge.rb b/lib/rubocop/cop/performance/redundant_merge.rb index 7e6060ef1b..3a18bdf210 100644 --- a/lib/rubocop/cop/performance/redundant_merge.rb +++ b/lib/rubocop/cop/performance/redundant_merge.rb @@ -130,7 +130,9 @@ def to_assignments(receiver, pairs) end def rewrite_with_modifier(node, parent, new_source) - indent = ' ' * configured_indentation_width + # FIXME: `|| 2` can be removed when support is limited to RuboCop 1.44 or higher. + # https://github.com/rubocop/rubocop/commit/02d1e5b + indent = ' ' * (configured_indentation_width || 2) padding = "\n#{indent + leading_spaces(node)}" new_source.gsub!("\n", padding) diff --git a/rubocop-performance.gemspec b/rubocop-performance.gemspec index 478b015df5..833b605601 100644 --- a/rubocop-performance.gemspec +++ b/rubocop-performance.gemspec @@ -30,6 +30,6 @@ Gem::Specification.new do |s| 'rubygems_mfa_required' => 'true' } - s.add_runtime_dependency('rubocop', '>= 1.7.0', '< 2.0') + s.add_runtime_dependency('rubocop', '>= 1.30.0', '< 2.0') s.add_runtime_dependency('rubocop-ast', '>= 1.30.0', '< 2.0') end