Skip to content

Commit

Permalink
Extend 'default' task with RuboCop linting
Browse files Browse the repository at this point in the history
This adds a new 'lint' rake task that runs as part of a default call
to 'rake'. Having linting run locally by default makes it easier to
catch build issues, and is a prerequisite for moving to GitHub Actions,
since we want to avoid listing lots of separate build steps.

Note that we first wipe the 'default' rake task, since RSpec has a habbit
of auto-populating it, which makes it hard to define it explicitly.

The 'lint' task runs RuboCop as a separate process, which is a technique
to avoid a LoadError when the gem is unavailable in production.
  • Loading branch information
Ben Thorner committed May 7, 2020
1 parent 2d6ce0d commit 0091c46
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
9 changes: 5 additions & 4 deletions Rakefile
@@ -1,6 +1,7 @@
# 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 File.expand_path("config/application", __dir__)

Rails.application.load_tasks

# RSpec shoves itself into the default task without asking, which confuses the ordering.
# https://github.com/rspec/rspec-rails/blob/eb3377bca425f0d74b9f510dbb53b2a161080016/lib/rspec/rails/tasks/rspec.rake#L6
Rake::Task[:default].clear unless Rails.env.production?
task default: %i[spec lint]
11 changes: 3 additions & 8 deletions lib/tasks/lint.rake
@@ -1,9 +1,4 @@
unless Rails.env.production?
require "rubocop/rake_task"

RuboCop::RakeTask.new(:lint) do |t|
t.patterns = %w[app config Gemfile lib spec]
t.formatters = %w[clang]
t.options = %w[--parallel]
end
desc "Lint Ruby"
task lint: :environment do
sh "bundle exec rubocop"
end

0 comments on commit 0091c46

Please sign in to comment.