-
Notifications
You must be signed in to change notification settings - Fork 54
/
run-foodcritic
executable file
·73 lines (55 loc) · 1.69 KB
/
run-foodcritic
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
#!/usr/bin/env ruby
# vim:fileencoding=utf-8
require 'English'
def main(argv = ARGV)
return 1 if argv.empty?
failed = []
cookbook_path = argv.first
fc_args = %W(#{ENV['FC_ARGS']})
fc_tags = ENV['FC_TAGS'] || File.join(cookbook_path, '.foodcritic-tags')
quiet = ENV['QUIET'].nil? ? false : true
foodcritic_exe = ENV['FOODCRITIC_EXE'] || 'foodcritic'
if File.exist?(fc_tags)
fc_args += File.read(fc_tags).split.map { |t| "--tags #{t.strip}" }
end
Dir.glob("#{cookbook_path}/*") do |cookbook|
next unless File.exist?(File.join(cookbook, 'metadata.rb'))
failed << run_foodcritic_for_cookbook(
cookbook: cookbook,
quiet: quiet,
fc_args: fc_args,
foodcritic_exe: foodcritic_exe
)
end
failed.compact!
unless failed.empty?
puts "FAILED:\n#{failed.join(' ')}"
return 1
end
0
end
def run_foodcritic_for_cookbook(cookbook: '', quiet: false, fc_args: '',
foodcritic_exe: 'foodcritic')
return nil if cookbook.empty?
return nil unless File.directory?(cookbook)
cookbook_name = File.basename(cookbook)
return nil if cookbook_name == 'cookbooks'
foodcritic_command = %W(
#{foodcritic_exe}
--epic-fail any
#{fc_args.join(' ')}
#{cookbook}
).join(' ')
puts "---> #{cookbook_name}: #{foodcritic_command}" unless quiet
output = `#{foodcritic_command} 2>&1`.chomp
output = output.split(/[\r\n]/).map(&:strip).reject(&:empty?).join("\n")
puts output unless output.empty?
if $CHILD_STATUS.success?
puts "---> #{cookbook_name} ✔︎" unless quiet
else
puts "---> #{cookbook_name} ✘" unless quiet
return cookbook_name
end
nil
end
exit(main) if $PROGRAM_NAME == __FILE__