Skip to content

Commit

Permalink
Add safe autocorrects
Browse files Browse the repository at this point in the history
Co-authored-by: Ashley Willard <ashley.willard@gusto.com>
Co-authored-by: Ivy Evans <ivy.evans@gusto.com>
  • Loading branch information
3 people committed Nov 15, 2024
1 parent 8322c2c commit a61bd8b
Show file tree
Hide file tree
Showing 53 changed files with 219 additions and 207 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"
source 'https://rubygems.org'

# Specify your gem's dependencies in packs-rails.gemspec
gemspec
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -10,5 +10,5 @@ require "packs-rails"
# require "pry"
# Pry.start

require "irb"
require 'irb'
IRB.start(__FILE__)
12 changes: 6 additions & 6 deletions bin/tapioca
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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')
10 changes: 5 additions & 5 deletions lib/packs-rails.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'packs'
require "active_support"
require "rails/application"
require 'active_support'
require 'rails/application'
require 'sorbet-runtime'

module Packs
Expand All @@ -22,7 +22,7 @@ def root
end

@config = ActiveSupport::OrderedOptions.new
@config.paths = %w(
@config.paths = %w[
app
app/controllers
app/channels
Expand All @@ -36,8 +36,8 @@ def root
config/locales
config/initializers
config/routes
)
]
end

require "packs/rails/railtie"
require 'packs/rails/railtie'
end
8 changes: 4 additions & 4 deletions lib/packs/rails/integrations.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions lib/packs/rails/integrations/factory_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions lib/packs/rails/integrations/rails.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/packs/rails/integrations/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand Down
3 changes: 1 addition & 2 deletions lib/packs/rails/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "rails/railtie"
require 'rails/railtie'

module Packs
module Rails
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/packs/rails/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "packs-rails"
require 'packs-rails'

Packs::Rails::Integrations::RSpec.new
4 changes: 2 additions & 2 deletions lib/packs/rails/stim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/packs/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Packs
module Rails
VERSION = "0.0.5".freeze
VERSION = '0.0.5'.freeze
end
end
2 changes: 1 addition & 1 deletion spec/fixtures/rails-6.1/Rakefile
Original file line number Diff line number Diff line change
@@ -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
28 changes: 17 additions & 11 deletions spec/fixtures/rails-6.1/bin/bundle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# this file is here to facilitate running it.
#

require "rubygems"
require 'rubygems'

m = Module.new do
module_function
Expand All @@ -18,45 +18,49 @@ 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|
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
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)
end

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

Expand All @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions spec/fixtures/rails-6.1/bin/rails
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 3 additions & 3 deletions spec/fixtures/rails-6.1/bin/rake
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/fixtures/rails-6.1/bin/setup
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
require "fileutils"
require 'fileutils'

# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
Expand Down
10 changes: 5 additions & 5 deletions spec/fixtures/rails-6.1/bin/spring
Original file line number Diff line number Diff line change
@@ -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
16 changes: 8 additions & 8 deletions spec/fixtures/rails-6.1/bin/webpack
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit a61bd8b

Please sign in to comment.