mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Add rubocop binstub that rspects file patterns
Best of both worlds! (Because you can't override the default rubocop includes) The binstub basically, lets me safely `rubocop test/foo_test.rb` instead of `bundle exec rubocop test/foo_test.rb` ```bash # ~/.profile # https://twitter.com/tpope/status/165631968996900865 # tl;dr `mkdir .git/safe` to add `bin` to path, e.g. `bin/rails` PATH=".git/safe/../../bin:$PATH" ```
This commit is contained in:
53
lib/tasks/rubocop.rake
Normal file
53
lib/tasks/rubocop.rake
Normal file
@@ -0,0 +1,53 @@
|
||||
begin
|
||||
require 'rubocop'
|
||||
require 'rubocop/rake_task'
|
||||
rescue LoadError # rubocop:disable Lint/HandleExceptions
|
||||
else
|
||||
require 'rbconfig'
|
||||
# https://github.com/bundler/bundler/blob/1b3eb2465a/lib/bundler/constants.rb#L2
|
||||
windows_platforms = /(msdos|mswin|djgpp|mingw)/
|
||||
if RbConfig::CONFIG['host_os'] =~ windows_platforms
|
||||
desc 'No-op rubocop on Windows-- unsupported platform'
|
||||
task :rubocop do
|
||||
puts 'Skipping rubocop on Windows'
|
||||
end
|
||||
elsif defined?(::Rubinius)
|
||||
desc 'No-op rubocop to avoid rbx segfault'
|
||||
task :rubocop do
|
||||
puts 'Skipping rubocop on rbx due to segfault'
|
||||
puts 'https://github.com/rubinius/rubinius/issues/3499'
|
||||
end
|
||||
else
|
||||
Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
|
||||
patterns = [
|
||||
'Gemfile',
|
||||
'Rakefile',
|
||||
'lib/**/*.{rb,rake}',
|
||||
'config/**/*.rb',
|
||||
'app/**/*.rb',
|
||||
'test/**/*.rb'
|
||||
]
|
||||
desc 'Execute rubocop'
|
||||
RuboCop::RakeTask.new(:rubocop) do |task|
|
||||
task.options = ['--rails', '--display-cop-names', '--display-style-guide']
|
||||
task.formatters = ['progress']
|
||||
task.patterns = patterns
|
||||
task.fail_on_error = true
|
||||
end
|
||||
|
||||
namespace :rubocop do
|
||||
desc 'Auto-gen rubocop config'
|
||||
task :auto_gen_config do
|
||||
options = ['--auto-gen-config'].concat patterns
|
||||
require 'benchmark'
|
||||
result = 0
|
||||
cli = RuboCop::CLI.new
|
||||
time = Benchmark.realtime do
|
||||
result = cli.run(options)
|
||||
end
|
||||
puts "Finished in #{time} seconds" if cli.options[:debug]
|
||||
abort('RuboCop failed!') if result.nonzero?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user