forked from till/easybib-cookbooks
/
foodcritic-rules.rb
71 lines (65 loc) · 2.25 KB
/
foodcritic-rules.rb
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
# Foodcritic Custom rules as a preparation for the Chef12 move.
#
# Since node[deploy], node[opsworks] and opsworks_* will be gone in Chef12,
# we are relocating everything using this in easybib_deploy, easybib/libraries/* and the wt-data cookbook
# so that we then have one single point for each case we have to readjust for Chef12.
rule 'WT001', 'Don\'t use opsworks_ definition calls outside the easybib deploy provider' do
tags %w(bug wt)
cookbook do |path|
recipes = Dir["#{path}/{#{standard_cookbook_subdirs.join(',')}}/**/*.rb"]
recipes += Dir["#{path}/*.rb"]
recipes.collect do |recipe|
lines = File.readlines(recipe)
lines.collect.with_index do |line, index|
if line.match('^( *)opsworks_') && recipe != 'easybib/providers/deploy.rb'
{
:filename => recipe,
:matched => recipe,
:line => index + 1,
:column => 0
}
end
end.compact
end.flatten
end
end
rule 'WT002', 'Don\'t use node[opsworks] outside the easybib library wrappers' do
tags %w(bug wt)
cookbook do |path|
recipes = Dir["#{path}/{#{standard_cookbook_subdirs.join(',')}}/**/*.rb"]
recipes += Dir["#{path}/*.rb"]
recipes.collect do |recipe|
lines = File.readlines(recipe)
lines.collect.with_index do |line, index|
if line.match('node\[(\'|"|:*)opsworks') && !recipe.match('^easybib/libraries')
{
:filename => recipe,
:matched => recipe,
:line => index + 1,
:column => 0
}
end
end.compact
end.flatten
end
end
rule 'WT003', 'Don\'t use node[deploy] outside the easybib & wt-data library wrappers' do
tags %w(bug wt)
cookbook do |path|
recipes = Dir["#{path}/{#{standard_cookbook_subdirs.join(',')}}/**/*.rb"]
recipes += Dir["#{path}/*.rb"]
recipes.collect do |recipe|
lines = File.readlines(recipe)
lines.collect.with_index do |line, index|
if line.match('node\[(\'|"|:*)deploy') && !recipe.match('^easybib/libraries') && !recipe.match('^wt-data')
{
:filename => recipe,
:matched => recipe,
:line => index + 1,
:column => 0
}
end
end.compact
end.flatten
end
end