forked from chef/cookstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
79 lines (62 loc) · 2.18 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true
require 'bundler/gem_tasks'
Dir['tasks/**/*.rake'].each { |t| load t }
upstream = Gem::Specification.find_by_name('rubocop')
desc "Vendor rubocop-#{upstream.version} configuration into gem"
task :vendor do
src = Pathname.new(upstream.gem_dir).join('config')
dst = Pathname.new(__FILE__).dirname.join('config')
mkdir_p dst
cp(src.join('default.yml'), dst.join('upstream.yml'))
require 'rubocop'
require 'yaml' unless defined?(YAML)
cfg = RuboCop::Cop::Cop.all.each_with_object({}) { |cop, acc| acc[cop.cop_name] = { 'Enabled' => false } unless cop.cop_name.start_with?('Chef'); }
File.open(dst.join('disable_all.yml'), 'w') { |fh| fh.write YAML.dump(cfg) }
sh %(git add #{dst}/{upstream,disable_all}.yml)
sh %(git commit -m "Vendor rubocop-#{upstream.version} upstream configuration." -m "Obvious fix; these changes are the result of automation not creative thinking.")
end
require 'cookstyle'
desc 'Run cookstyle against cookstyle'
task :style do
sh('bundle exec cookstyle')
end
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/cop/**/*.rb']
end
desc 'Run RSpec with code coverage'
task :coverage do
ENV['COVERAGE'] = 'true'
Rake::Task['spec'].execute
end
desc 'Ensure that all cops are defined in the cookstyle.yml config'
task :validate_config do
require 'cookstyle'
require 'yaml' unless defined?(YAML)
status = 0
config = YAML.load_file('config/cookstyle.yml')
puts 'Checking that all cops are defined in config/cookstyle.yml:'
RuboCop::Cop::Chef.constants.each do |dep|
RuboCop::Cop::Chef.const_get(dep).constants.each do |cop|
unless config["Chef/#{dep}/#{cop}"]
puts "Error: Chef/#{dep}/#{cop} not found in config/cookstyle.yml"
status = 1
end
end
end
puts 'All Cops found in the config. Good work.' if status == 0
exit status
end
begin
require 'yard'
YARD::Rake::YardocTask.new(:docs)
rescue LoadError
puts 'yard is not available. bundle install first to make sure all dependencies are installed.'
end
task :console do
require 'irb'
require 'irb/completion'
ARGV.clear
IRB.start
end
task default: [:style, :spec, :validate_config]