File tree Expand file tree Collapse file tree 4 files changed +96
-31
lines changed Expand file tree Collapse file tree 4 files changed +96
-31
lines changed Original file line number Diff line number Diff line change 1
1
AllCops :
2
2
TargetRubyVersion : 2.1
3
3
Exclude :
4
- - config/initializers/forbidden_yaml.rb
5
4
- !ruby/regexp /(vendor|bundle|bin|db|tmp)\/.*/
6
5
DisplayCopNames : true
7
6
DisplayStyleGuide : true
7
+ # https://github.com/bbatsov/rubocop/blob/master/manual/caching.md
8
+ # https://github.com/bbatsov/rubocop/blob/e8680418b351491e111a18cf5b453fc07a3c5239/config/default.yml#L60-L77
9
+ UseCache : true
10
+ CacheRootDirectory : tmp
8
11
9
12
Rails :
10
13
Enabled : true
Original file line number Diff line number Diff line change 7
7
require 'simplecov'
8
8
rescue LoadError # rubocop:disable Lint/HandleExceptions
9
9
end
10
+ import ( 'lib/tasks/rubocop.rake' )
10
11
11
12
Bundler ::GemHelper . install_tasks
12
13
@@ -30,36 +31,6 @@ namespace :yard do
30
31
end
31
32
end
32
33
33
- begin
34
- require 'rubocop'
35
- require 'rubocop/rake_task'
36
- rescue LoadError # rubocop:disable Lint/HandleExceptions
37
- else
38
- Rake ::Task [ :rubocop ] . clear if Rake ::Task . task_defined? ( :rubocop )
39
- require 'rbconfig'
40
- # https://github.com/bundler/bundler/blob/1b3eb2465a/lib/bundler/constants.rb#L2
41
- windows_platforms = /(msdos|mswin|djgpp|mingw)/
42
- if RbConfig ::CONFIG [ 'host_os' ] =~ windows_platforms
43
- desc 'No-op rubocop on Windows-- unsupported platform'
44
- task :rubocop do
45
- puts 'Skipping rubocop on Windows'
46
- end
47
- elsif defined? ( ::Rubinius )
48
- desc 'No-op rubocop to avoid rbx segfault'
49
- task :rubocop do
50
- puts 'Skipping rubocop on rbx due to segfault'
51
- puts 'https://github.com/rubinius/rubinius/issues/3499'
52
- end
53
- else
54
- Rake ::Task [ :rubocop ] . clear if Rake ::Task . task_defined? ( :rubocop )
55
- desc 'Execute rubocop'
56
- RuboCop ::RakeTask . new ( :rubocop ) do |task |
57
- task . options = [ '--rails' , '--display-cop-names' , '--display-style-guide' ]
58
- task . fail_on_error = true
59
- end
60
- end
61
- end
62
-
63
34
require 'rake/testtask'
64
35
65
36
Rake ::TestTask . new ( :test ) do |t |
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+ #
3
+ # Usage:
4
+ # bin/rubocop [-A|-t|-h]
5
+ # bin/rubocop [file or path] [cli options]
6
+ #
7
+ # Options:
8
+ # Autocorrect -A
9
+ # AutoGenConfig -t
10
+ # Usage -h,--help,help
11
+
12
+ set -e
13
+
14
+ case $1 in
15
+ -A)
16
+ echo " Rubocop autocorrect is ON" >&2
17
+ bundle exec rake -f lib/tasks/rubocop.rake rubocop:auto_correct
18
+ ;;
19
+
20
+ -t)
21
+ echo " Rubocop is generating a new TODO" >&2
22
+ bundle exec rake -f lib/tasks/rubocop.rake rubocop:auto_gen_config
23
+ ;;
24
+
25
+ -h|--help|help)
26
+ sed -ne ' /^#/!q;s/.\{1,2\}//;1d;p' < " $0 "
27
+ ;;
28
+
29
+ * )
30
+ # with no args, run vanilla rubocop
31
+ # else assume we're passing in arbitrary arguments
32
+ if [ -z " $1 " ]; then
33
+ bundle exec rake -f lib/tasks/rubocop.rake rubocop
34
+ else
35
+ bundle exec rubocop " $@ "
36
+ fi
37
+ ;;
38
+ esac
Original file line number Diff line number Diff line change
1
+ begin
2
+ require 'rubocop'
3
+ require 'rubocop/rake_task'
4
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
5
+ else
6
+ require 'rbconfig'
7
+ # https://github.com/bundler/bundler/blob/1b3eb2465a/lib/bundler/constants.rb#L2
8
+ windows_platforms = /(msdos|mswin|djgpp|mingw)/
9
+ if RbConfig ::CONFIG [ 'host_os' ] =~ windows_platforms
10
+ desc 'No-op rubocop on Windows-- unsupported platform'
11
+ task :rubocop do
12
+ puts 'Skipping rubocop on Windows'
13
+ end
14
+ elsif defined? ( ::Rubinius )
15
+ desc 'No-op rubocop to avoid rbx segfault'
16
+ task :rubocop do
17
+ puts 'Skipping rubocop on rbx due to segfault'
18
+ puts 'https://github.com/rubinius/rubinius/issues/3499'
19
+ end
20
+ else
21
+ Rake ::Task [ :rubocop ] . clear if Rake ::Task . task_defined? ( :rubocop )
22
+ patterns = [
23
+ 'Gemfile' ,
24
+ 'Rakefile' ,
25
+ 'lib/**/*.{rb,rake}' ,
26
+ 'config/**/*.rb' ,
27
+ 'app/**/*.rb' ,
28
+ 'test/**/*.rb'
29
+ ]
30
+ desc 'Execute rubocop'
31
+ RuboCop ::RakeTask . new ( :rubocop ) do |task |
32
+ task . options = [ '--rails' , '--display-cop-names' , '--display-style-guide' ]
33
+ task . formatters = [ 'progress' ]
34
+ task . patterns = patterns
35
+ task . fail_on_error = true
36
+ end
37
+
38
+ namespace :rubocop do
39
+ desc 'Auto-gen rubocop config'
40
+ task :auto_gen_config do
41
+ options = [ '--auto-gen-config' ] . concat patterns
42
+ require 'benchmark'
43
+ result = 0
44
+ cli = RuboCop ::CLI . new
45
+ time = Benchmark . realtime do
46
+ result = cli . run ( options )
47
+ end
48
+ puts "Finished in #{ time } seconds" if cli . options [ :debug ]
49
+ abort ( 'RuboCop failed!' ) if result . nonzero?
50
+ end
51
+ end
52
+ end
53
+ end
You can’t perform that action at this time.
0 commit comments