From 8322c2c78bf3fe888e53574cacd1af7ceab4f5f3 Mon Sep 17 00:00:00 2001 From: Teal Stannard Date: Fri, 15 Nov 2024 11:48:13 -0800 Subject: [PATCH 1/4] Add rubocop.yml added to gemspec Co-authored-by: Ashley Willard Co-authored-by: Ivy Evans --- .rubocop.yml | 123 ++++++++++++++++++++++++++++++++++++++++++++ packs-rails.gemspec | 51 +++++++++--------- 2 files changed, 149 insertions(+), 25 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..64b735d --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,123 @@ +# The behavior of RuboCop can be controlled via the .rubocop.yml +# configuration file. It makes it possible to enable/disable +# certain cops (checks) and to alter their behavior if they accept +# any parameters. The file can be placed either in your home +# directory or in some project directory. +# +# RuboCop will start looking for the configuration file in the directory +# where the inspected file is and continue its way up to the root directory. +# +# See https://docs.rubocop.org/rubocop/configuration +AllCops: + NewCops: enable + Exclude: + - vendor/bundle/**/** + TargetRubyVersion: 2.6 + +Metrics/ParameterLists: + Enabled: false + +# This cop is annoying with typed configuration +Style/TrivialAccessors: + Enabled: false + +# This rubocop is annoying when we use interfaces a lot +Lint/UnusedMethodArgument: + Enabled: false + +Gemspec/RequireMFA: + Enabled: false + +Lint/DuplicateBranch: + Enabled: false + +# If is sometimes easier to think about than unless sometimes +Style/NegatedIf: + Enabled: false + +# Disabling for now until it's clearer why we want this +Style/FrozenStringLiteralComment: + Enabled: false + +# It's nice to be able to read the condition first before reading the code within the condition +Style/GuardClause: + Enabled: false + +# +# Leaving length metrics to human judgment for now +# +Metrics/ModuleLength: + Enabled: false + +Layout/LineLength: + Enabled: false + +Metrics/BlockLength: + Enabled: false + +Metrics/MethodLength: + Enabled: false + +Metrics/AbcSize: + Enabled: false + +Metrics/ClassLength: + Enabled: false + +# This doesn't feel useful +Metrics/CyclomaticComplexity: + Enabled: false + +# This doesn't feel useful +Metrics/PerceivedComplexity: + Enabled: false + +# It's nice to be able to read the condition first before reading the code within the condition +Style/IfUnlessModifier: + Enabled: false + +# This leads to code that is not very readable at times (very long lines) +Style/ConditionalAssignment: + Enabled: false + +# For now, we prefer to lean on clean method signatures as documentation. We may change this later. +Style/Documentation: + Enabled: false + +# Sometimes we leave comments in empty else statements intentionally +Style/EmptyElse: + Enabled: false + +# Sometimes we want to more explicitly list out a condition +Style/RedundantCondition: + Enabled: false + +# This leads to code that is not very readable at times (very long lines) +Layout/MultilineMethodCallIndentation: + Enabled: false + +# Blocks across lines are okay sometimes +Style/BlockDelimiters: + Enabled: false + +# Sometimes we like methods like `get_packages` +Naming/AccessorMethodName: + Enabled: false + +# This leads to code that is not very readable at times (very long lines) +Layout/FirstArgumentIndentation: + Enabled: false + +# This leads to code that is not very readable at times (very long lines) +Layout/ArgumentAlignment: + Enabled: false + +Style/AccessorGrouping: + Enabled: false + +Style/HashSyntax: + Enabled: false + +Gemspec/DevelopmentDependencies: + Enabled: true + EnforcedStyle: gemspec \ No newline at end of file diff --git a/packs-rails.gemspec b/packs-rails.gemspec index da936c5..0a57981 100644 --- a/packs-rails.gemspec +++ b/packs-rails.gemspec @@ -1,36 +1,37 @@ -require_relative "lib/packs/rails/version" +require_relative 'lib/packs/rails/version' Gem::Specification.new do |spec| - spec.name = "packs-rails" + spec.name = 'packs-rails' spec.version = Packs::Rails::VERSION - spec.authors = ["Ngan Pham"] - spec.email = ["gusto-opensource-buildkite@gusto.com"] + spec.authors = ['Ngan Pham'] + spec.email = ['gusto-opensource-buildkite@gusto.com'] - spec.summary = "A Rails helper to package your code." - spec.description = "packs-rails establishes and implements a set of conventions for splitting up large monoliths." - spec.homepage = "https://github.com/rubyatscale/packs-rails" - spec.license = "MIT" - spec.required_ruby_version = Gem::Requirement.new(">= 2.7") + spec.summary = 'A Rails helper to package your code.' + spec.description = 'packs-rails establishes and implements a set of conventions for splitting up large monoliths.' + spec.homepage = 'https://github.com/rubyatscale/packs-rails' + spec.license = 'MIT' + spec.required_ruby_version = Gem::Requirement.new('>= 2.7') - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://github.com/rubyatscale/packs-rails" - spec.metadata["changelog_uri"] = "https://github.com/rubyatscale/packs-rails/releases" + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = 'https://github.com/rubyatscale/packs-rails' + spec.metadata['changelog_uri'] = 'https://github.com/rubyatscale/packs-rails/releases' - spec.files = Dir["VERSION", "CHANGELOG.md", "LICENSE.txt", "README.md", "lib/**/*", "bin/**/*"] - spec.bindir = "exe" - spec.executables = Dir["exe/*"].map { |exe| File.basename(exe) } - spec.require_paths = ["lib"] + spec.files = Dir['VERSION', 'CHANGELOG.md', 'LICENSE.txt', 'README.md', 'lib/**/*', 'bin/**/*'] + spec.bindir = 'exe' + spec.executables = Dir['exe/*'].map { |exe| File.basename(exe) } + spec.require_paths = ['lib'] - spec.add_dependency "railties" - spec.add_dependency "activesupport" - spec.add_dependency "packs" + spec.add_dependency 'activesupport' + spec.add_dependency 'packs' + spec.add_dependency 'railties' - spec.add_development_dependency "rake" - spec.add_development_dependency "rspec" - spec.add_development_dependency "debug" - spec.add_development_dependency "sorbet" - spec.add_development_dependency "tapioca" + spec.add_development_dependency 'debug' + spec.add_development_dependency 'rake' + spec.add_development_dependency 'rspec' + spec.add_development_dependency 'rubocop' + spec.add_development_dependency 'sorbet' + spec.add_development_dependency 'tapioca' # We need this in test to load our test fixture Rails application, which represents the "client" of packs-rails - spec.add_development_dependency "rails" + spec.add_development_dependency 'rails' end From a61bd8b452a44392bf8a45884c053d50ae1e3010 Mon Sep 17 00:00:00 2001 From: Teal Stannard Date: Fri, 15 Nov 2024 11:50:30 -0800 Subject: [PATCH 2/4] Add safe autocorrects Co-authored-by: Ashley Willard Co-authored-by: Ivy Evans --- Gemfile | 2 +- bin/console | 6 +-- bin/tapioca | 12 ++--- lib/packs-rails.rb | 10 ++-- lib/packs/rails/integrations.rb | 8 +-- lib/packs/rails/integrations/factory_bot.rb | 4 +- lib/packs/rails/integrations/rails.rb | 13 ++--- lib/packs/rails/integrations/rspec.rb | 3 +- lib/packs/rails/railtie.rb | 3 +- lib/packs/rails/rspec.rb | 2 +- lib/packs/rails/stim.rb | 4 +- lib/packs/rails/version.rb | 2 +- spec/fixtures/rails-6.1/Rakefile | 2 +- spec/fixtures/rails-6.1/bin/bundle | 28 +++++++---- spec/fixtures/rails-6.1/bin/rails | 6 +-- spec/fixtures/rails-6.1/bin/rake | 6 +-- spec/fixtures/rails-6.1/bin/setup | 2 +- spec/fixtures/rails-6.1/bin/spring | 10 ++-- spec/fixtures/rails-6.1/bin/webpack | 16 +++--- .../fixtures/rails-6.1/bin/webpack-dev-server | 16 +++--- spec/fixtures/rails-6.1/bin/yarn | 6 +-- spec/fixtures/rails-6.1/config.ru | 2 +- spec/fixtures/rails-6.1/config/application.rb | 4 +- spec/fixtures/rails-6.1/config/boot.rb | 2 +- spec/fixtures/rails-6.1/config/environment.rb | 2 +- .../config/environments/development.rb | 2 +- .../config/environments/production.rb | 8 +-- .../rails-6.1/config/environments/test.rb | 2 +- .../initializers/backtrace_silencers.rb | 2 +- .../initializers/filter_parameter_logging.rb | 4 +- spec/fixtures/rails-6.1/config/puma.rb | 12 ++--- spec/fixtures/rails-6.1/config/spring.rb | 8 +-- .../test/application_system_test_case.rb | 2 +- .../application_cable/connection_test.rb | 2 +- spec/fixtures/rails-6.1/test/test_helper.rb | 4 +- spec/fixtures/rails-7.0/Gemfile | 19 ++++--- spec/fixtures/rails-7.0/Rakefile | 2 +- spec/fixtures/rails-7.0/bin/bundle | 34 +++++++------ spec/fixtures/rails-7.0/bin/rails | 6 +-- spec/fixtures/rails-7.0/bin/rake | 4 +- spec/fixtures/rails-7.0/bin/setup | 16 +++--- spec/fixtures/rails-7.0/config.ru | 2 +- spec/fixtures/rails-7.0/config/application.rb | 16 +++--- spec/fixtures/rails-7.0/config/boot.rb | 4 +- spec/fixtures/rails-7.0/config/environment.rb | 2 +- .../config/environments/development.rb | 6 +-- .../config/environments/production.rb | 10 ++-- .../rails-7.0/config/environments/test.rb | 6 +-- .../initializers/filter_parameter_logging.rb | 4 +- spec/fixtures/rails-7.0/config/puma.rb | 12 ++--- spec/fixtures/rails-7.0/test/test_helper.rb | 6 +-- spec/packs-rails_spec.rb | 50 +++++++++---------- spec/spec_helper.rb | 10 ++-- 53 files changed, 219 insertions(+), 207 deletions(-) diff --git a/Gemfile b/Gemfile index f20b6c7..059411e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source "https://rubygems.org" +source 'https://rubygems.org' # Specify your gem's dependencies in packs-rails.gemspec gemspec diff --git a/bin/console b/bin/console index c52c25c..a908417 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,7 @@ #!/usr/bin/env ruby -require "bundler/setup" -require "packs-rails" +require 'bundler/setup' +require 'packs-rails' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. @@ -10,5 +10,5 @@ require "packs-rails" # require "pry" # Pry.start -require "irb" +require 'irb' IRB.start(__FILE__) diff --git a/bin/tapioca b/bin/tapioca index 32290de..ce95fac 100755 --- a/bin/tapioca +++ b/bin/tapioca @@ -8,11 +8,11 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path('bundle', __dir__) if File.file?(bundle_binstub) if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ @@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this end end -require "rubygems" -require "bundler/setup" +require 'rubygems' +require 'bundler/setup' -load Gem.bin_path("tapioca", "tapioca") +load Gem.bin_path('tapioca', 'tapioca') diff --git a/lib/packs-rails.rb b/lib/packs-rails.rb index 7e5800f..05827ee 100644 --- a/lib/packs-rails.rb +++ b/lib/packs-rails.rb @@ -1,6 +1,6 @@ require 'packs' -require "active_support" -require "rails/application" +require 'active_support' +require 'rails/application' require 'sorbet-runtime' module Packs @@ -22,7 +22,7 @@ def root end @config = ActiveSupport::OrderedOptions.new - @config.paths = %w( + @config.paths = %w[ app app/controllers app/channels @@ -36,8 +36,8 @@ def root config/locales config/initializers config/routes - ) + ] end - require "packs/rails/railtie" + require 'packs/rails/railtie' end diff --git a/lib/packs/rails/integrations.rb b/lib/packs/rails/integrations.rb index ff039dc..6fbc90a 100644 --- a/lib/packs/rails/integrations.rb +++ b/lib/packs/rails/integrations.rb @@ -1,11 +1,11 @@ -require "active_support" +require 'active_support' module Packs module Rails module Integrations - autoload :FactoryBot, "packs/rails/integrations/factory_bot" - autoload :Rails, "packs/rails/integrations/rails" - autoload :RSpec, "packs/rails/integrations/rspec" + autoload :FactoryBot, 'packs/rails/integrations/factory_bot' + autoload :Rails, 'packs/rails/integrations/rails' + autoload :RSpec, 'packs/rails/integrations/rspec' end end end diff --git a/lib/packs/rails/integrations/factory_bot.rb b/lib/packs/rails/integrations/factory_bot.rb index 3055712..8aff0cd 100644 --- a/lib/packs/rails/integrations/factory_bot.rb +++ b/lib/packs/rails/integrations/factory_bot.rb @@ -8,8 +8,8 @@ def initialize(app) return unless app.config.respond_to?(:factory_bot) Packs.all.reject(&:is_gem?).each do |pack| - app.config.factory_bot.definition_file_paths << pack.relative_path.join("spec/factories").to_s - app.config.factory_bot.definition_file_paths << pack.relative_path.join("test/factories").to_s + app.config.factory_bot.definition_file_paths << pack.relative_path.join('spec/factories').to_s + app.config.factory_bot.definition_file_paths << pack.relative_path.join('test/factories').to_s end end end diff --git a/lib/packs/rails/integrations/rails.rb b/lib/packs/rails/integrations/rails.rb index ad3e086..fe03780 100644 --- a/lib/packs/rails/integrations/rails.rb +++ b/lib/packs/rails/integrations/rails.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true # typed: true -require "active_support/inflections" +require 'active_support/inflections' module Packs module Rails module Integrations class Rails - CONFIG_ROUTES_PATH = "config/routes".freeze + CONFIG_ROUTES_PATH = 'config/routes' def initialize(app) @app = app @@ -42,12 +42,13 @@ def inject_paths def pre_rails_6_1? return @_pre_rails_6_1 if defined?(@_pre_rails_6_1) - @_pre_rails_6_1 = ::Rails.gem_version < Gem::Version.new("6.1") + + @_pre_rails_6_1 = ::Rails.gem_version < Gem::Version.new('6.1') end def create_namespace(name) namespace = ActiveSupport::Inflector.camelize(name) - namespace.split("::").reduce(Object) do |base, mod| + namespace.split('::').reduce(Object) do |base, mod| if base.const_defined?(mod, false) base.const_get(mod, false) else @@ -57,10 +58,10 @@ def create_namespace(name) end def create_engine(pack) - name = pack.metadata.fetch("engine_name", pack.last_name) + name = pack.metadata.fetch('engine_name', pack.last_name) namespace = create_namespace(name) stim = Stim.new(pack, namespace) - namespace.const_set("Engine", Class.new(::Rails::Engine)).include(stim) + namespace.const_set('Engine', Class.new(::Rails::Engine)).include(stim) end end end diff --git a/lib/packs/rails/integrations/rspec.rb b/lib/packs/rails/integrations/rspec.rb index 280cfb7..ceecb1b 100644 --- a/lib/packs/rails/integrations/rspec.rb +++ b/lib/packs/rails/integrations/rspec.rb @@ -17,6 +17,7 @@ def initialize pack_paths = Packs.all.map do |pack| next if pack.is_gem? + spec_path = pack.relative_path.join(default_path) spec_path.to_s if spec_path.exist? end @@ -28,7 +29,7 @@ def initialize # end of it. # # packs/my_pack => packs/my_pack/spec - # + # # If it doesn't match a pack path, we leave it alone. to_run.map! do |path| diff --git a/lib/packs/rails/railtie.rb b/lib/packs/rails/railtie.rb index c07f124..1787712 100644 --- a/lib/packs/rails/railtie.rb +++ b/lib/packs/rails/railtie.rb @@ -1,4 +1,4 @@ -require "rails/railtie" +require 'rails/railtie' module Packs module Rails @@ -11,7 +11,6 @@ class Railtie < ::Rails::Railtie # hook into packs-rails via ActiveSupport hooks. ActiveSupport.run_load_hooks(:packs_rails, Packs) end - end end end diff --git a/lib/packs/rails/rspec.rb b/lib/packs/rails/rspec.rb index 8706d84..0cc08db 100644 --- a/lib/packs/rails/rspec.rb +++ b/lib/packs/rails/rspec.rb @@ -1,3 +1,3 @@ -require "packs-rails" +require 'packs-rails' Packs::Rails::Integrations::RSpec.new diff --git a/lib/packs/rails/stim.rb b/lib/packs/rails/stim.rb index ac254fe..e2bbbdc 100644 --- a/lib/packs/rails/stim.rb +++ b/lib/packs/rails/stim.rb @@ -23,10 +23,10 @@ def included(engine) (Packs::Rails.config.paths + # In addition to the paths we've delegated to the main app, we don't allow # Engine Packs to have various capabilities. - %w( + %w[ config/environments db/migrate - ) + ] ).uniq.each do |path| engine.paths[path] = nil end diff --git a/lib/packs/rails/version.rb b/lib/packs/rails/version.rb index 3c7310c..43f6fd5 100644 --- a/lib/packs/rails/version.rb +++ b/lib/packs/rails/version.rb @@ -1,5 +1,5 @@ module Packs module Rails - VERSION = "0.0.5".freeze + VERSION = '0.0.5'.freeze end end diff --git a/spec/fixtures/rails-6.1/Rakefile b/spec/fixtures/rails-6.1/Rakefile index 9a5ea73..e85f913 100644 --- a/spec/fixtures/rails-6.1/Rakefile +++ b/spec/fixtures/rails-6.1/Rakefile @@ -1,6 +1,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative "config/application" +require_relative 'config/application' Rails.application.load_tasks diff --git a/spec/fixtures/rails-6.1/bin/bundle b/spec/fixtures/rails-6.1/bin/bundle index 42c7fd7..feff07c 100755 --- a/spec/fixtures/rails-6.1/bin/bundle +++ b/spec/fixtures/rails-6.1/bin/bundle @@ -8,7 +8,7 @@ # this file is here to facilitate running it. # -require "rubygems" +require 'rubygems' m = Module.new do module_function @@ -18,12 +18,13 @@ m = Module.new do end def env_var_version - ENV["BUNDLER_VERSION"] + ENV.fetch('BUNDLER_VERSION', nil) end def cli_arg_version return unless invoked_as_script? # don't want to hijack other binstubs - return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update` + bundler_version = nil update_index = nil ARGV.each_with_index do |a, i| @@ -31,23 +32,24 @@ m = Module.new do bundler_version = a end next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ - bundler_version = $1 + + bundler_version = Regexp.last_match(1) update_index = i end bundler_version end def gemfile - gemfile = ENV["BUNDLE_GEMFILE"] + gemfile = ENV.fetch('BUNDLE_GEMFILE', nil) return gemfile if gemfile && !gemfile.empty? - File.expand_path("../Gemfile", __dir__) + File.expand_path('../Gemfile', __dir__) end def lockfile lockfile = case File.basename(gemfile) - when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") + when 'gems.rb' then gemfile.sub(/\.rb$/, '.locked') else "#{gemfile}.lock" end File.expand_path(lockfile) @@ -55,8 +57,10 @@ m = Module.new do def lockfile_version return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) end @@ -76,20 +80,22 @@ m = Module.new do end def load_bundler! - ENV["BUNDLE_GEMFILE"] ||= gemfile + ENV['BUNDLE_GEMFILE'] ||= gemfile activate_bundler end def activate_bundler gem_error = activation_error_handling do - gem "bundler", bundler_requirement + gem 'bundler', bundler_requirement end return if gem_error.nil? + require_error = activation_error_handling do - require "bundler/version" + require 'bundler/version' end return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" exit 42 end @@ -105,5 +111,5 @@ end m.load_bundler! if m.invoked_as_script? - load Gem.bin_path("bundler", "bundle") + load Gem.bin_path('bundler', 'bundle') end diff --git a/spec/fixtures/rails-6.1/bin/rails b/spec/fixtures/rails-6.1/bin/rails index 21d3e02..3846d27 100755 --- a/spec/fixtures/rails-6.1/bin/rails +++ b/spec/fixtures/rails-6.1/bin/rails @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -load File.expand_path("spring", __dir__) +load File.expand_path('spring', __dir__) APP_PATH = File.expand_path('../config/application', __dir__) -require_relative "../config/boot" -require "rails/commands" +require_relative '../config/boot' +require 'rails/commands' diff --git a/spec/fixtures/rails-6.1/bin/rake b/spec/fixtures/rails-6.1/bin/rake index 7327f47..31bcf93 100755 --- a/spec/fixtures/rails-6.1/bin/rake +++ b/spec/fixtures/rails-6.1/bin/rake @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -load File.expand_path("spring", __dir__) -require_relative "../config/boot" -require "rake" +load File.expand_path('spring', __dir__) +require_relative '../config/boot' +require 'rake' Rake.application.run diff --git a/spec/fixtures/rails-6.1/bin/setup b/spec/fixtures/rails-6.1/bin/setup index 90700ac..97dc988 100755 --- a/spec/fixtures/rails-6.1/bin/setup +++ b/spec/fixtures/rails-6.1/bin/setup @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -require "fileutils" +require 'fileutils' # path to your application root. APP_ROOT = File.expand_path('..', __dir__) diff --git a/spec/fixtures/rails-6.1/bin/spring b/spec/fixtures/rails-6.1/bin/spring index 89f6161..9ef6a0a 100755 --- a/spec/fixtures/rails-6.1/bin/spring +++ b/spec/fixtures/rails-6.1/bin/spring @@ -1,10 +1,10 @@ #!/usr/bin/env ruby -if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"]) +if !defined?(Spring) && [nil, 'development', 'test'].include?(ENV.fetch('RAILS_ENV', nil)) # Load Spring without loading other gems in the Gemfile, for speed. - require "bundler" - Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring| + require 'bundler' + Bundler.locked_gems.specs.find { |spec| spec.name == 'spring' }&.tap do |spring| Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path - gem "spring", spring.version - require "spring/binstub" + gem 'spring', spring.version + require 'spring/binstub' end end diff --git a/spec/fixtures/rails-6.1/bin/webpack b/spec/fixtures/rails-6.1/bin/webpack index 1031168..e40a234 100755 --- a/spec/fixtures/rails-6.1/bin/webpack +++ b/spec/fixtures/rails-6.1/bin/webpack @@ -1,18 +1,18 @@ #!/usr/bin/env ruby -ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" -ENV["NODE_ENV"] ||= "development" +ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] || 'development' +ENV['NODE_ENV'] ||= 'development' -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath) -require "bundler/setup" +require 'bundler/setup' -require "webpacker" -require "webpacker/webpack_runner" +require 'webpacker' +require 'webpacker/webpack_runner' -APP_ROOT = File.expand_path("..", __dir__) +APP_ROOT = File.expand_path('..', __dir__) Dir.chdir(APP_ROOT) do Webpacker::WebpackRunner.run(ARGV) end diff --git a/spec/fixtures/rails-6.1/bin/webpack-dev-server b/spec/fixtures/rails-6.1/bin/webpack-dev-server index dd96627..081391b 100755 --- a/spec/fixtures/rails-6.1/bin/webpack-dev-server +++ b/spec/fixtures/rails-6.1/bin/webpack-dev-server @@ -1,18 +1,18 @@ #!/usr/bin/env ruby -ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" -ENV["NODE_ENV"] ||= "development" +ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] || 'development' +ENV['NODE_ENV'] ||= 'development' -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath) -require "bundler/setup" +require 'bundler/setup' -require "webpacker" -require "webpacker/dev_server_runner" +require 'webpacker' +require 'webpacker/dev_server_runner' -APP_ROOT = File.expand_path("..", __dir__) +APP_ROOT = File.expand_path('..', __dir__) Dir.chdir(APP_ROOT) do Webpacker::DevServerRunner.run(ARGV) end diff --git a/spec/fixtures/rails-6.1/bin/yarn b/spec/fixtures/rails-6.1/bin/yarn index 241546e..81499bf 100755 --- a/spec/fixtures/rails-6.1/bin/yarn +++ b/spec/fixtures/rails-6.1/bin/yarn @@ -3,7 +3,7 @@ require 'pathname' APP_ROOT = File.expand_path('..', __dir__) Dir.chdir(APP_ROOT) do - executable_path = ENV["PATH"].split(File::PATH_SEPARATOR).find do |path| + executable_path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |path| normalized_path = File.expand_path(path) normalized_path != __dir__ && File.executable?(Pathname.new(normalized_path).join('yarn')) @@ -12,8 +12,8 @@ Dir.chdir(APP_ROOT) do if executable_path exec File.expand_path(Pathname.new(executable_path).join('yarn')), *ARGV else - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + warn 'Yarn executable was not detected in the system.' + warn 'Download Yarn at https://yarnpkg.com/en/docs/install' exit 1 end end diff --git a/spec/fixtures/rails-6.1/config.ru b/spec/fixtures/rails-6.1/config.ru index 4a3c09a..ad1fbf2 100644 --- a/spec/fixtures/rails-6.1/config.ru +++ b/spec/fixtures/rails-6.1/config.ru @@ -1,6 +1,6 @@ # This file is used by Rack-based servers to start the application. -require_relative "config/environment" +require_relative 'config/environment' run Rails.application Rails.application.load_server diff --git a/spec/fixtures/rails-6.1/config/application.rb b/spec/fixtures/rails-6.1/config/application.rb index 30d3dcb..fe00c10 100644 --- a/spec/fixtures/rails-6.1/config/application.rb +++ b/spec/fixtures/rails-6.1/config/application.rb @@ -1,6 +1,6 @@ -require_relative "boot" +require_relative 'boot' -require "rails/all" +require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. diff --git a/spec/fixtures/rails-6.1/config/boot.rb b/spec/fixtures/rails-6.1/config/boot.rb index d69bd27..30f5120 100644 --- a/spec/fixtures/rails-6.1/config/boot.rb +++ b/spec/fixtures/rails-6.1/config/boot.rb @@ -1,3 +1,3 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -require "bundler/setup" # Set up gems listed in the Gemfile. +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/spec/fixtures/rails-6.1/config/environment.rb b/spec/fixtures/rails-6.1/config/environment.rb index cac5315..426333b 100644 --- a/spec/fixtures/rails-6.1/config/environment.rb +++ b/spec/fixtures/rails-6.1/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require_relative "application" +require_relative 'application' # Initialize the Rails application. Rails.application.initialize! diff --git a/spec/fixtures/rails-6.1/config/environments/development.rb b/spec/fixtures/rails-6.1/config/environments/development.rb index 7ab18f5..e9da2dd 100644 --- a/spec/fixtures/rails-6.1/config/environments/development.rb +++ b/spec/fixtures/rails-6.1/config/environments/development.rb @@ -1,4 +1,4 @@ -require "active_support/core_ext/integer/time" +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/spec/fixtures/rails-6.1/config/environments/production.rb b/spec/fixtures/rails-6.1/config/environments/production.rb index 983849f..8737911 100644 --- a/spec/fixtures/rails-6.1/config/environments/production.rb +++ b/spec/fixtures/rails-6.1/config/environments/production.rb @@ -1,4 +1,4 @@ -require "active_support/core_ext/integer/time" +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -53,7 +53,7 @@ config.log_level = :info # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -82,13 +82,13 @@ config.active_support.disallowed_deprecation_warnings = [] # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new + config.log_formatter = Logger::Formatter.new # Use a different logger for distributed setups. # require "syslog/logger" # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? + if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) diff --git a/spec/fixtures/rails-6.1/config/environments/test.rb b/spec/fixtures/rails-6.1/config/environments/test.rb index 93ed4f1..b9152b2 100644 --- a/spec/fixtures/rails-6.1/config/environments/test.rb +++ b/spec/fixtures/rails-6.1/config/environments/test.rb @@ -1,4 +1,4 @@ -require "active_support/core_ext/integer/time" +require 'active_support/core_ext/integer/time' # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that diff --git a/spec/fixtures/rails-6.1/config/initializers/backtrace_silencers.rb b/spec/fixtures/rails-6.1/config/initializers/backtrace_silencers.rb index 33699c3..d4d9b3b 100644 --- a/spec/fixtures/rails-6.1/config/initializers/backtrace_silencers.rb +++ b/spec/fixtures/rails-6.1/config/initializers/backtrace_silencers.rb @@ -5,4 +5,4 @@ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code # by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". -Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] +Rails.backtrace_cleaner.remove_silencers! if ENV['BACKTRACE'] diff --git a/spec/fixtures/rails-6.1/config/initializers/filter_parameter_logging.rb b/spec/fixtures/rails-6.1/config/initializers/filter_parameter_logging.rb index 4b34a03..3e69694 100644 --- a/spec/fixtures/rails-6.1/config/initializers/filter_parameter_logging.rb +++ b/spec/fixtures/rails-6.1/config/initializers/filter_parameter_logging.rb @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [ - :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +Rails.application.config.filter_parameters += %i[ + passw secret token _key crypt salt certificate otp ssn ] diff --git a/spec/fixtures/rails-6.1/config/puma.rb b/spec/fixtures/rails-6.1/config/puma.rb index d9b3e83..6b7e304 100644 --- a/spec/fixtures/rails-6.1/config/puma.rb +++ b/spec/fixtures/rails-6.1/config/puma.rb @@ -4,25 +4,25 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } +min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `worker_timeout` threshold that Puma will use to wait before # terminating a worker in development environments. # -worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" +worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development' # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV') { 'development' } # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } +pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together diff --git a/spec/fixtures/rails-6.1/config/spring.rb b/spec/fixtures/rails-6.1/config/spring.rb index db5bf13..8f6432b 100644 --- a/spec/fixtures/rails-6.1/config/spring.rb +++ b/spec/fixtures/rails-6.1/config/spring.rb @@ -1,6 +1,6 @@ Spring.watch( - ".ruby-version", - ".rbenv-vars", - "tmp/restart.txt", - "tmp/caching-dev.txt" + '.ruby-version', + '.rbenv-vars', + 'tmp/restart.txt', + 'tmp/caching-dev.txt' ) diff --git a/spec/fixtures/rails-6.1/test/application_system_test_case.rb b/spec/fixtures/rails-6.1/test/application_system_test_case.rb index d19212a..23701b4 100644 --- a/spec/fixtures/rails-6.1/test/application_system_test_case.rb +++ b/spec/fixtures/rails-6.1/test/application_system_test_case.rb @@ -1,4 +1,4 @@ -require "test_helper" +require 'test_helper' class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] diff --git a/spec/fixtures/rails-6.1/test/channels/application_cable/connection_test.rb b/spec/fixtures/rails-6.1/test/channels/application_cable/connection_test.rb index 800405f..d05dbd2 100644 --- a/spec/fixtures/rails-6.1/test/channels/application_cable/connection_test.rb +++ b/spec/fixtures/rails-6.1/test/channels/application_cable/connection_test.rb @@ -1,4 +1,4 @@ -require "test_helper" +require 'test_helper' class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase # test "connects with cookies" do diff --git a/spec/fixtures/rails-6.1/test/test_helper.rb b/spec/fixtures/rails-6.1/test/test_helper.rb index 47b598d..d5300f8 100644 --- a/spec/fixtures/rails-6.1/test/test_helper.rb +++ b/spec/fixtures/rails-6.1/test/test_helper.rb @@ -1,6 +1,6 @@ ENV['RAILS_ENV'] ||= 'test' -require_relative "../config/environment" -require "rails/test_help" +require_relative '../config/environment' +require 'rails/test_help' class ActiveSupport::TestCase # Run tests in parallel with specified workers diff --git a/spec/fixtures/rails-7.0/Gemfile b/spec/fixtures/rails-7.0/Gemfile index 8cb2032..9993049 100644 --- a/spec/fixtures/rails-7.0/Gemfile +++ b/spec/fixtures/rails-7.0/Gemfile @@ -1,32 +1,31 @@ -source "https://rubygems.org" +source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby "3.0.3" +ruby '3.0.3' # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem "rails", "~> 7.0.3", ">= 7.0.3.1" +gem 'rails', '~> 7.0.3', '>= 7.0.3.1' -gem "stimpack", path: File.expand_path("../../..", __dir__) +gem 'stimpack', path: File.expand_path('../../..', __dir__) # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] -gem "sprockets-rails" +gem 'sprockets-rails' # Use sqlite3 as the database for Active Record -gem "sqlite3", "~> 1.4" +gem 'sqlite3', '~> 1.4' # Use the Puma web server [https://github.com/puma/puma] -gem "puma", "~> 5.0" +gem 'puma', '~> 5.0' # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem - gem "debug", platforms: %i[ mri mingw x64_mingw ] + gem 'debug', platforms: %i[mri mingw x64_mingw] end group :development do # Speed up commands on slow machines / big apps [https://github.com/rails/spring] # gem "spring" end - diff --git a/spec/fixtures/rails-7.0/Rakefile b/spec/fixtures/rails-7.0/Rakefile index 9a5ea73..e85f913 100644 --- a/spec/fixtures/rails-7.0/Rakefile +++ b/spec/fixtures/rails-7.0/Rakefile @@ -1,6 +1,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative "config/application" +require_relative 'config/application' Rails.application.load_tasks diff --git a/spec/fixtures/rails-7.0/bin/bundle b/spec/fixtures/rails-7.0/bin/bundle index 981e650..9ebe280 100755 --- a/spec/fixtures/rails-7.0/bin/bundle +++ b/spec/fixtures/rails-7.0/bin/bundle @@ -8,7 +8,7 @@ # this file is here to facilitate running it. # -require "rubygems" +require 'rubygems' m = Module.new do module_function @@ -18,12 +18,13 @@ m = Module.new do end def env_var_version - ENV["BUNDLER_VERSION"] + ENV.fetch('BUNDLER_VERSION', nil) end def cli_arg_version return unless invoked_as_script? # don't want to hijack other binstubs - return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update` + bundler_version = nil update_index = nil ARGV.each_with_index do |a, i| @@ -31,23 +32,24 @@ m = Module.new do bundler_version = a end next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ - bundler_version = $1 + + bundler_version = Regexp.last_match(1) update_index = i end bundler_version end def gemfile - gemfile = ENV["BUNDLE_GEMFILE"] + gemfile = ENV.fetch('BUNDLE_GEMFILE', nil) return gemfile if gemfile && !gemfile.empty? - File.expand_path("../Gemfile", __dir__) + File.expand_path('../Gemfile', __dir__) end def lockfile lockfile = case File.basename(gemfile) - when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile) else "#{gemfile}.lock" end File.expand_path(lockfile) @@ -55,15 +57,17 @@ m = Module.new do def lockfile_version return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) end def bundler_requirement @bundler_requirement ||= env_var_version || cli_arg_version || - bundler_requirement_for(lockfile_version) + bundler_requirement_for(lockfile_version) end def bundler_requirement_for(version) @@ -73,28 +77,30 @@ m = Module.new do requirement = bundler_gem_version.approximate_recommendation - return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0") + return requirement unless Gem.rubygems_version < Gem::Version.new('2.7.0') - requirement += ".a" if bundler_gem_version.prerelease? + requirement += '.a' if bundler_gem_version.prerelease? requirement end def load_bundler! - ENV["BUNDLE_GEMFILE"] ||= gemfile + ENV['BUNDLE_GEMFILE'] ||= gemfile activate_bundler end def activate_bundler gem_error = activation_error_handling do - gem "bundler", bundler_requirement + gem 'bundler', bundler_requirement end return if gem_error.nil? + require_error = activation_error_handling do - require "bundler/version" + require 'bundler/version' end return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" exit 42 end @@ -110,5 +116,5 @@ end m.load_bundler! if m.invoked_as_script? - load Gem.bin_path("bundler", "bundle") + load Gem.bin_path('bundler', 'bundle') end diff --git a/spec/fixtures/rails-7.0/bin/rails b/spec/fixtures/rails-7.0/bin/rails index efc0377..0739660 100755 --- a/spec/fixtures/rails-7.0/bin/rails +++ b/spec/fixtures/rails-7.0/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path("../config/application", __dir__) -require_relative "../config/boot" -require "rails/commands" +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/spec/fixtures/rails-7.0/bin/rake b/spec/fixtures/rails-7.0/bin/rake index 4fbf10b..1724048 100755 --- a/spec/fixtures/rails-7.0/bin/rake +++ b/spec/fixtures/rails-7.0/bin/rake @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -require_relative "../config/boot" -require "rake" +require_relative '../config/boot' +require 'rake' Rake.application.run diff --git a/spec/fixtures/rails-7.0/bin/setup b/spec/fixtures/rails-7.0/bin/setup index ec47b79..d6e019a 100755 --- a/spec/fixtures/rails-7.0/bin/setup +++ b/spec/fixtures/rails-7.0/bin/setup @@ -1,8 +1,8 @@ #!/usr/bin/env ruby -require "fileutils" +require 'fileutils' # path to your application root. -APP_ROOT = File.expand_path("..", __dir__) +APP_ROOT = File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -13,9 +13,9 @@ FileUtils.chdir APP_ROOT do # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. - puts "== Installing dependencies ==" - system! "gem install bundler --conservative" - system("bundle check") || system!("bundle install") + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') # puts "\n== Copying sample files ==" # unless File.exist?("config/database.yml") @@ -23,11 +23,11 @@ FileUtils.chdir APP_ROOT do # end puts "\n== Preparing database ==" - system! "bin/rails db:prepare" + system! 'bin/rails db:prepare' puts "\n== Removing old logs and tempfiles ==" - system! "bin/rails log:clear tmp:clear" + system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" - system! "bin/rails restart" + system! 'bin/rails restart' end diff --git a/spec/fixtures/rails-7.0/config.ru b/spec/fixtures/rails-7.0/config.ru index 4a3c09a..ad1fbf2 100644 --- a/spec/fixtures/rails-7.0/config.ru +++ b/spec/fixtures/rails-7.0/config.ru @@ -1,6 +1,6 @@ # This file is used by Rack-based servers to start the application. -require_relative "config/environment" +require_relative 'config/environment' run Rails.application Rails.application.load_server diff --git a/spec/fixtures/rails-7.0/config/application.rb b/spec/fixtures/rails-7.0/config/application.rb index 640d704..64066d6 100644 --- a/spec/fixtures/rails-7.0/config/application.rb +++ b/spec/fixtures/rails-7.0/config/application.rb @@ -1,24 +1,24 @@ -require_relative "boot" +require_relative 'boot' -require "rails" +require 'rails' # Pick the frameworks you want: -require "active_model/railtie" +require 'active_model/railtie' # require "active_job/railtie" -require "active_record/railtie" +require 'active_record/railtie' # require "active_storage/engine" -require "action_controller/railtie" +require 'action_controller/railtie' # require "action_mailer/railtie" # require "action_mailbox/engine" # require "action_text/engine" -require "action_view/railtie" +require 'action_view/railtie' # require "action_cable/engine" -require "rails/test_unit/railtie" +require 'rails/test_unit/railtie' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -Packs::Rails.config.root = ['packs', 'components', 'utilities'] +Packs::Rails.config.root = %w[packs components utilities] module TestApp class Application < Rails::Application diff --git a/spec/fixtures/rails-7.0/config/boot.rb b/spec/fixtures/rails-7.0/config/boot.rb index 2820116..30f5120 100644 --- a/spec/fixtures/rails-7.0/config/boot.rb +++ b/spec/fixtures/rails-7.0/config/boot.rb @@ -1,3 +1,3 @@ -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -require "bundler/setup" # Set up gems listed in the Gemfile. +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/spec/fixtures/rails-7.0/config/environment.rb b/spec/fixtures/rails-7.0/config/environment.rb index cac5315..426333b 100644 --- a/spec/fixtures/rails-7.0/config/environment.rb +++ b/spec/fixtures/rails-7.0/config/environment.rb @@ -1,5 +1,5 @@ # Load the Rails application. -require_relative "application" +require_relative 'application' # Initialize the Rails application. Rails.application.initialize! diff --git a/spec/fixtures/rails-7.0/config/environments/development.rb b/spec/fixtures/rails-7.0/config/environments/development.rb index f811f68..a2d6752 100644 --- a/spec/fixtures/rails-7.0/config/environments/development.rb +++ b/spec/fixtures/rails-7.0/config/environments/development.rb @@ -1,4 +1,4 @@ -require "active_support/core_ext/integer/time" +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -19,13 +19,13 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join("tmp/caching-dev.txt").exist? + if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{2.days.to_i}" + 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false diff --git a/spec/fixtures/rails-7.0/config/environments/production.rb b/spec/fixtures/rails-7.0/config/environments/production.rb index ac46ed4..2f27a39 100644 --- a/spec/fixtures/rails-7.0/config/environments/production.rb +++ b/spec/fixtures/rails-7.0/config/environments/production.rb @@ -1,4 +1,4 @@ -require "active_support/core_ext/integer/time" +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -22,7 +22,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass @@ -45,7 +45,7 @@ config.log_level = :info # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -58,13 +58,13 @@ config.active_support.report_deprecations = false # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new + config.log_formatter = Logger::Formatter.new # Use a different logger for distributed setups. # require "syslog/logger" # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") - if ENV["RAILS_LOG_TO_STDOUT"].present? + if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) diff --git a/spec/fixtures/rails-7.0/config/environments/test.rb b/spec/fixtures/rails-7.0/config/environments/test.rb index eb2f171..16b3759 100644 --- a/spec/fixtures/rails-7.0/config/environments/test.rb +++ b/spec/fixtures/rails-7.0/config/environments/test.rb @@ -1,4 +1,4 @@ -require "active_support/core_ext/integer/time" +require 'active_support/core_ext/integer/time' # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that @@ -14,12 +14,12 @@ # Eager loading loads your whole application. When running a single test locally, # this probably isn't necessary. It's a good idea to do in a continuous integration # system, or in some way before deploying your code. - config.eager_load = ENV["CI"].present? + config.eager_load = ENV['CI'].present? # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{1.hour.to_i}" + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. diff --git a/spec/fixtures/rails-7.0/config/initializers/filter_parameter_logging.rb b/spec/fixtures/rails-7.0/config/initializers/filter_parameter_logging.rb index adc6568..166997c 100644 --- a/spec/fixtures/rails-7.0/config/initializers/filter_parameter_logging.rb +++ b/spec/fixtures/rails-7.0/config/initializers/filter_parameter_logging.rb @@ -3,6 +3,6 @@ # Configure parameters to be filtered from the log file. Use this to limit dissemination of # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported # notations and behaviors. -Rails.application.config.filter_parameters += [ - :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +Rails.application.config.filter_parameters += %i[ + passw secret token _key crypt salt certificate otp ssn ] diff --git a/spec/fixtures/rails-7.0/config/puma.rb b/spec/fixtures/rails-7.0/config/puma.rb index daaf036..e9dc159 100644 --- a/spec/fixtures/rails-7.0/config/puma.rb +++ b/spec/fixtures/rails-7.0/config/puma.rb @@ -4,25 +4,25 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } +min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `worker_timeout` threshold that Puma will use to wait before # terminating a worker in development environments. # -worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" +worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development' # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV') { 'development' } # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } +pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together diff --git a/spec/fixtures/rails-7.0/test/test_helper.rb b/spec/fixtures/rails-7.0/test/test_helper.rb index d713e37..d5300f8 100644 --- a/spec/fixtures/rails-7.0/test/test_helper.rb +++ b/spec/fixtures/rails-7.0/test/test_helper.rb @@ -1,6 +1,6 @@ -ENV["RAILS_ENV"] ||= "test" -require_relative "../config/environment" -require "rails/test_help" +ENV['RAILS_ENV'] ||= 'test' +require_relative '../config/environment' +require 'rails/test_help' class ActiveSupport::TestCase # Run tests in parallel with specified workers diff --git a/spec/packs-rails_spec.rb b/spec/packs-rails_spec.rb index 45a5b21..3b37884 100644 --- a/spec/packs-rails_spec.rb +++ b/spec/packs-rails_spec.rb @@ -1,68 +1,68 @@ -require "pathname" +require 'pathname' rails_dir = require_test_rails_application RSpec.describe Packs::Rails do - it "autoloads classes in autoload paths" do - expect(defined?(Shirts::ShortSleeve)).to eq("constant") + it 'autoloads classes in autoload paths' do + expect(defined?(Shirts::ShortSleeve)).to eq('constant') end - it "adds pack paths to the application" do + it 'adds pack paths to the application' do Packs::Rails.config.paths.each do |path| - expect(Rails.application.paths[path].paths).to include(rails_dir.join('packs', "shirts", path)) + expect(Rails.application.paths[path].paths).to include(rails_dir.join('packs', 'shirts', path)) end end - it "does not add gem paths to the application" do + it 'does not add gem paths to the application' do Packs::Rails.config.paths.each do |path| - expect(Rails.application.paths[path].paths).to_not include(rails_dir.join('components', "jackets", path)) + expect(Rails.application.paths[path].paths).to_not include(rails_dir.join('components', 'jackets', path)) end end - it "creates engines namespace for engine packs" do - expect(defined?(Shoes::Engine)).to eq("constant") + it 'creates engines namespace for engine packs' do + expect(defined?(Shoes::Engine)).to eq('constant') end context 'nested packs' do - it "autoloads classes in autoload paths" do - expect(defined?(Shorts::Linen)).to eq("constant") + it 'autoloads classes in autoload paths' do + expect(defined?(Shorts::Linen)).to eq('constant') end - it "adds pack paths to the application" do + it 'adds pack paths to the application' do Packs::Rails.config.paths.each do |path| - expect(Rails.application.paths[path].paths).to include(rails_dir.join('packs', "pants", "shorts", path)) + expect(Rails.application.paths[path].paths).to include(rails_dir.join('packs', 'pants', 'shorts', path)) end end - it "creates engines namespace for engine packs" do - expect(defined?(Shorts::Engine)).to eq("constant") + it 'creates engines namespace for engine packs' do + expect(defined?(Shorts::Engine)).to eq('constant') end end context 'custom engine name' do - it "autoloads classes in autoload paths" do - expect(defined?(Pants::Jeans::Bootcut)).to eq("constant") + it 'autoloads classes in autoload paths' do + expect(defined?(Pants::Jeans::Bootcut)).to eq('constant') end - it "adds pack paths to the application" do + it 'adds pack paths to the application' do Packs::Rails.config.paths.each do |path| - expect(Rails.application.paths[path].paths).to include(rails_dir.join('packs', "pants", "jeans", path)) + expect(Rails.application.paths[path].paths).to include(rails_dir.join('packs', 'pants', 'jeans', path)) end end - it "creates engines namespace for engine packs" do - expect(defined?(Pants::Jeans::Engine)).to eq("constant") + it 'creates engines namespace for engine packs' do + expect(defined?(Pants::Jeans::Engine)).to eq('constant') end end context 'alternate roots' do - it "autoloads classes in autoload paths" do - expect(defined?(Belts::Brown)).to eq("constant") + it 'autoloads classes in autoload paths' do + expect(defined?(Belts::Brown)).to eq('constant') end - it "adds pack paths to the application" do + it 'adds pack paths to the application' do Packs::Rails.config.paths.each do |path| - expect(Rails.application.paths[path].paths).to include(rails_dir.join('utilities', "belts", path)) + expect(Rails.application.paths[path].paths).to include(rails_dir.join('utilities', 'belts', path)) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e2714bb..2ad76db 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,10 @@ -require "bundler/setup" -require "packs-rails" +require 'bundler/setup' +require 'packs-rails' require 'packs/rspec/support' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" + config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! @@ -14,9 +14,9 @@ end end -def require_test_rails_application(version = ENV.fetch("RAILS_VERSION", "7.0")) +def require_test_rails_application(version = ENV.fetch('RAILS_VERSION', '7.0')) rails_dir = Pathname.new(File.expand_path("fixtures/rails-#{version}", __dir__)) Dir.chdir(rails_dir) - require_relative rails_dir.join("config/environment") + require_relative rails_dir.join('config/environment') rails_dir end From 86491ec011209eb7d937040df691ba4927cf471e Mon Sep 17 00:00:00 2001 From: Teal Stannard Date: Fri, 15 Nov 2024 11:53:51 -0800 Subject: [PATCH 3/4] Add risky but okay autocorrectable changes Co-authored-by: Ashley Willard Co-authored-by: Ivy Evans --- lib/packs/rails/integrations/rspec.rb | 2 +- spec/fixtures/rails-6.1/config/puma.rb | 4 ++-- .../application_cable/connection_test.rb | 18 ++++++++++-------- spec/fixtures/rails-6.1/test/test_helper.rb | 14 ++++++++------ spec/fixtures/rails-7.0/config/puma.rb | 4 ++-- spec/fixtures/rails-7.0/test/test_helper.rb | 14 ++++++++------ 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lib/packs/rails/integrations/rspec.rb b/lib/packs/rails/integrations/rspec.rb index ceecb1b..b9e1ef6 100644 --- a/lib/packs/rails/integrations/rspec.rb +++ b/lib/packs/rails/integrations/rspec.rb @@ -33,7 +33,7 @@ def initialize # If it doesn't match a pack path, we leave it alone. to_run.map! do |path| - if pack = Packs.find(path) + if (pack = Packs.find(path)) [ pack, *nested_packs_for(pack) diff --git a/spec/fixtures/rails-6.1/config/puma.rb b/spec/fixtures/rails-6.1/config/puma.rb index 6b7e304..ec43a47 100644 --- a/spec/fixtures/rails-6.1/config/puma.rb +++ b/spec/fixtures/rails-6.1/config/puma.rb @@ -4,7 +4,7 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count @@ -15,7 +15,7 @@ # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch('PORT') { 3000 } +port ENV.fetch('PORT', 3000) # Specifies the `environment` that Puma will run in. # diff --git a/spec/fixtures/rails-6.1/test/channels/application_cable/connection_test.rb b/spec/fixtures/rails-6.1/test/channels/application_cable/connection_test.rb index d05dbd2..f925925 100644 --- a/spec/fixtures/rails-6.1/test/channels/application_cable/connection_test.rb +++ b/spec/fixtures/rails-6.1/test/channels/application_cable/connection_test.rb @@ -1,11 +1,13 @@ require 'test_helper' -class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase - # test "connects with cookies" do - # cookies.signed[:user_id] = 42 - # - # connect - # - # assert_equal connection.user_id, "42" - # end +module ApplicationCable + class ConnectionTest < ActionCable::Connection::TestCase + # test "connects with cookies" do + # cookies.signed[:user_id] = 42 + # + # connect + # + # assert_equal connection.user_id, "42" + # end + end end diff --git a/spec/fixtures/rails-6.1/test/test_helper.rb b/spec/fixtures/rails-6.1/test/test_helper.rb index d5300f8..1b7300e 100644 --- a/spec/fixtures/rails-6.1/test/test_helper.rb +++ b/spec/fixtures/rails-6.1/test/test_helper.rb @@ -2,12 +2,14 @@ require_relative '../config/environment' require 'rails/test_help' -class ActiveSupport::TestCase - # Run tests in parallel with specified workers - parallelize(workers: :number_of_processors) +module ActiveSupport + class TestCase + # Run tests in parallel with specified workers + parallelize(workers: :number_of_processors) - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all - # Add more helper methods to be used by all tests here... + # Add more helper methods to be used by all tests here... + end end diff --git a/spec/fixtures/rails-7.0/config/puma.rb b/spec/fixtures/rails-7.0/config/puma.rb index e9dc159..0593712 100644 --- a/spec/fixtures/rails-7.0/config/puma.rb +++ b/spec/fixtures/rails-7.0/config/puma.rb @@ -4,7 +4,7 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count @@ -15,7 +15,7 @@ # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch('PORT') { 3000 } +port ENV.fetch('PORT', 3000) # Specifies the `environment` that Puma will run in. # diff --git a/spec/fixtures/rails-7.0/test/test_helper.rb b/spec/fixtures/rails-7.0/test/test_helper.rb index d5300f8..1b7300e 100644 --- a/spec/fixtures/rails-7.0/test/test_helper.rb +++ b/spec/fixtures/rails-7.0/test/test_helper.rb @@ -2,12 +2,14 @@ require_relative '../config/environment' require 'rails/test_help' -class ActiveSupport::TestCase - # Run tests in parallel with specified workers - parallelize(workers: :number_of_processors) +module ActiveSupport + class TestCase + # Run tests in parallel with specified workers + parallelize(workers: :number_of_processors) - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all - # Add more helper methods to be used by all tests here... + # Add more helper methods to be used by all tests here... + end end From ac9b2182102ff7b3337d828a19de98933b1d1d21 Mon Sep 17 00:00:00 2001 From: Teal Stannard Date: Fri, 15 Nov 2024 11:58:41 -0800 Subject: [PATCH 4/4] Add rubocop todo Co-authored-by: Ashley Willard Co-authored-by: Ivy Evans --- .rubocop.yml | 2 ++ .rubocop_todo.yml | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 64b735d..b2799ff 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +inherit_from: .rubocop_todo.yml + # The behavior of RuboCop can be controlled via the .rubocop.yml # configuration file. It makes it possible to enable/disable # certain cops (checks) and to alter their behavior if they accept diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..1165f47 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,76 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2024-11-15 19:57:24 UTC using RuboCop version 1.65.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Configuration parameters: EnforcedStyle, AllowedGems, Include. +# SupportedStyles: Gemfile, gems.rb, gemspec +# Include: **/*.gemspec, **/Gemfile, **/gems.rb +Gemspec/DevelopmentDependencies: + Exclude: + - 'spec/fixtures/rails-7.0/Gemfile' + +# Offense count: 2 +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'packs-rails.gemspec' + - 'spec/fixtures/rails-7.0/components/jackets/jackets.gemspec' + +# Offense count: 16 +# Configuration parameters: AllowComments. +Lint/EmptyClass: + Enabled: false + +# Offense count: 3 +# Configuration parameters: AllowComments. +Lint/EmptyFile: + Exclude: + - 'spec/fixtures/rails-6.1/packs/shirts/app/models/shirts/pocket.rb' + - 'spec/fixtures/rails-7.0/components/jackets/jackets.gemspec' + - 'spec/fixtures/rails-7.0/packs/shirts/app/models/shirts/pocket.rb' + +# Offense count: 2 +# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# CheckDefinitionPathHierarchyRoots: lib, spec, test, src +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'Rakefile.rb' + - 'lib/packs-rails.rb' + - 'spec/packs-rails_spec.rb' + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyleForLeadingUnderscores. +# SupportedStylesForLeadingUnderscores: disallowed, required, optional +Naming/MemoizedInstanceVariableName: + Exclude: + - 'lib/packs/rails/integrations/rails.rb' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. +# SupportedStyles: snake_case, normalcase, non_integer +# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 +Naming/VariableNumber: + Exclude: + - 'lib/packs/rails/integrations/rails.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/GlobalStdStream: + Exclude: + - 'spec/fixtures/rails-6.1/config/environments/production.rb' + - 'spec/fixtures/rails-7.0/config/environments/production.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: RequireEnglish. +# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names +Style/SpecialGlobalVars: + EnforcedStyle: use_perl_names