Repository navigation
Expand file tree
/
Copy pathRakefile
More file actions
69 lines (56 loc) · 2.22 KB
/
Copy pathRakefile
File metadata and controls
69 lines (56 loc) · 2.22 KB
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
# frozen_string_literal: true
require 'bundler/gem_tasks'
Dir['tasks/**/*.rake'].each { |t| load t }
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 'Ensure that all cops are defined in the cookstyle.yml and chefstyle.yml configs'
task :validate_config do
require 'cookstyle'
require 'yaml' unless defined?(YAML)
status = 0
configs = {
'config/cookstyle.yml' => YAML.load_file('config/cookstyle.yml'),
'config/chefstyle.yml' => YAML.load_file('config/chefstyle.yml'),
}
puts 'Checking that all cops are defined in the cookstyle.yml and chefstyle.yml configs:'
RuboCop::Cop::Chef.constants.each do |dep|
department = RuboCop::Cop::Chef.const_get(dep)
department.constants.each do |cop|
# Cookstyle and Chefstyle cops share the RuboCop::Cop::Chef namespace but ship separate
# configs, so check each cop against the config that matches where it's defined.
#
# Cops are registered for lazy loading, so ask for the pending autoload path first.
# `autoload?` returns nil once a cop has been loaded, in which case
# `const_source_location` gives the real file. Note that for a cop that is still
# unloaded, `const_source_location` would point at the `register_cop` call site
# instead of the cop's own file, which is why it can't be used on its own.
source = (department.autoload?(cop) || department.const_source_location(cop)&.first).to_s
config_file = source.include?('/cop/chefstyle/') ? 'config/chefstyle.yml' : 'config/cookstyle.yml'
next if configs[config_file]["Chef/#{dep}/#{cop}"]
puts "Error: Chef/#{dep}/#{cop} not found in #{config_file}"
status = 1
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]