-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2072 from bf4/more_precise_rubocop
Add rubocop binstub that respects file patterns
- Loading branch information
Showing
4 changed files
with
96 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Usage: | ||
# bin/rubocop [-A|-t|-h] | ||
# bin/rubocop [file or path] [cli options] | ||
# | ||
# Options: | ||
# Autocorrect -A | ||
# AutoGenConfig -t | ||
# Usage -h,--help,help | ||
|
||
set -e | ||
|
||
case $1 in | ||
-A) | ||
echo "Rubocop autocorrect is ON" >&2 | ||
bundle exec rake -f lib/tasks/rubocop.rake rubocop:auto_correct | ||
;; | ||
|
||
-t) | ||
echo "Rubocop is generating a new TODO" >&2 | ||
bundle exec rake -f lib/tasks/rubocop.rake rubocop:auto_gen_config | ||
;; | ||
|
||
-h|--help|help) | ||
sed -ne '/^#/!q;s/.\{1,2\}//;1d;p' < "$0" | ||
;; | ||
|
||
*) | ||
# with no args, run vanilla rubocop | ||
# else assume we're passing in arbitrary arguments | ||
if [ -z "$1" ]; then | ||
bundle exec rake -f lib/tasks/rubocop.rake rubocop | ||
else | ||
bundle exec rubocop "$@" | ||
fi | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |