Shopify Rubocop
Used 19 times
P
Pawel Osiczko
Usage
This template installs Caliber Rubocops, and adds Shopify's Ruby Style Guide. Gems are installed in the `code_quality` gem group.
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://www.railsbytes.com/script/Xo5s5q"
Template Source
Review the code before running this template on your machine.
# Add Rubocop in code_quality group
gem_group :code_quality do
gem "caliber"
gem "rubocop-shopify"
end
# Install Rubocop gems
Bundler.with_unbundled_env { run "bundle install" }
# Create a project .rubocop.yml with performance, thread, rake, rspec Rubocops from Caliber
# Use Shopify's Rubocop version for Ruby and Rails
create_file '.rubocop.yml' do <<~YAML
AllCops:
NewCops: enable
inherit_gem:
caliber:
# Prefer Shopify's style guide over the caliber's RuboCop style guide
# - config/ruby.yml
- config/performance.yml
- config/thread.yml
- config/rake.yml
- config/rspec.yml
rubocop-shopify: rubocop.yml
YAML
end
content = <<~'RUBY'
return if require_error.nil? &&
Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
RUBY
gsub_file "bin/bundle",
"return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))",
content
content = <<~'RUBY'
warning = <<~END
Activating bundler (#{bundler_requirement}) failed:
#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
END
warn(warning)
RUBY
gsub_file "bin/bundle",
/warn \"Activating bundler .+$/,
content
say "Ready to run rubocop -A"