Skip to content

Commit

Permalink
Use rubocop-rails >= 2.22.0 for better Rails 7.1 support
Browse files Browse the repository at this point in the history
Before, rubocop-rails treated the Rails 7.1 `Rails.env.local?` as an
unrecognized environment name, requiring custom configuration of
`Rails/UnknownEnv` as a workaround.

Now that rubocop-rails 2.22.0 is released, this workaround is no longer
needed.

This commit removes the workaround and ensures that `rubocop-rails` is
added to the Gemfile with the `>= 2.22.0` version requirement.
  • Loading branch information
mattbrictson committed Oct 27, 2023
1 parent 4a120f4 commit 2594def
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/nextgen/generators/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
plugins << "minitest" if minitest?
plugins << "performance"
plugins << "rails"
install_gems "rubocop", *plugins.map { "rubocop-#{_1}" }, group: :development, require: false
install_gem("rubocop-rails", version: ">= 2.22.0", group: :development, require: false)
install_gems(*plugins.map { "rubocop-#{_1}" }, "rubocop", group: :development, require: false)
binstub "rubocop"

say_git "Generate .rubocop.yml"
Expand Down
9 changes: 0 additions & 9 deletions template/.rubocop.yml.tt
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,6 @@ Rails/RootPathnameMethods:
Rails/SkipsModelValidations:
Enabled: false

<% if Gem::Version.new(Rails.version) >= Gem::Version.new("7.1.0.beta1") -%>
Rails/UnknownEnv:
Environments:
- development
- test
- production
- local
<% end -%>

Rails/Validation:
Enabled: false

Expand Down
35 changes: 35 additions & 0 deletions test/nextgen/generators/rubocop_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require_relative "test_case"

class Nextgen::Generators::RubocopTest < Nextgen::Generators::TestCase
destination File.join(Dir.tmpdir, "test_#{SecureRandom.hex(8)}")
setup :prepare_destination

setup do
%w[README.md Rakefile].each { FileUtils.touch Pathname.new(destination_root).join(_1) }
Pathname.new(destination_root).join("Gemfile").write(<<~GEMFILE)
source "https://rubygems.org"
GEMFILE
end

test "installs rubocop gems in development group, with version spec for rubocop-rails" do
apply_generator

assert_file "Gemfile", /#{Regexp.quote(<<~GEMFILE)}/
group :development do
gem "rubocop", require: false
gem "rubocop-performance", require: false
gem "rubocop-rails", ">= 2.22.0", require: false
end
GEMFILE
end

test "installs generates a .rubocop.yml file that requires additional plugins" do
apply_generator

assert_file ".rubocop.yml", /#{Regexp.quote(<<~YML)}/
require:
- rubocop-performance
- rubocop-rails
YML
end
end

0 comments on commit 2594def

Please sign in to comment.