foodcritic 15.1.0 → 16.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/chef_dsl_metadata/{chef_14.8.12.json → chef_14.14.29.json} +394 -169
- data/chef_dsl_metadata/{chef_13.12.3.json → chef_15.4.45.json} +15454 -2631
- data/foodcritic.gemspec +2 -2
- data/lib/foodcritic.rb +2 -1
- data/lib/foodcritic/api.rb +55 -42
- data/lib/foodcritic/chef.rb +5 -3
- data/lib/foodcritic/command_line.rb +78 -52
- data/lib/foodcritic/domain.rb +7 -9
- data/lib/foodcritic/dsl.rb +4 -1
- data/lib/foodcritic/gerkin/tag.rb +55 -0
- data/lib/foodcritic/gerkin/tag_expression.rb +66 -0
- data/lib/foodcritic/linter.rb +24 -8
- data/lib/foodcritic/notifications.rb +3 -1
- data/lib/foodcritic/output.rb +1 -1
- data/lib/foodcritic/rules/fc001.rb +6 -6
- data/lib/foodcritic/rules/fc004.rb +1 -0
- data/lib/foodcritic/rules/fc006.rb +9 -9
- data/lib/foodcritic/rules/fc007.rb +3 -1
- data/lib/foodcritic/rules/fc016.rb +1 -0
- data/lib/foodcritic/rules/fc019.rb +7 -6
- data/lib/foodcritic/rules/fc022.rb +24 -25
- data/lib/foodcritic/rules/fc024.rb +16 -13
- data/lib/foodcritic/rules/fc029.rb +1 -0
- data/lib/foodcritic/rules/fc031.rb +1 -1
- data/lib/foodcritic/rules/fc032.rb +2 -2
- data/lib/foodcritic/rules/fc033.rb +2 -2
- data/lib/foodcritic/rules/fc034.rb +5 -2
- data/lib/foodcritic/rules/fc039.rb +12 -12
- data/lib/foodcritic/rules/fc040.rb +1 -1
- data/lib/foodcritic/rules/fc044.rb +8 -12
- data/lib/foodcritic/rules/fc048.rb +1 -0
- data/lib/foodcritic/rules/fc121.rb +6 -10
- data/lib/foodcritic/rules/fc123.rb +16 -0
- data/lib/foodcritic/template.rb +3 -6
- data/lib/foodcritic/version.rb +1 -1
- metadata +34 -32
@@ -3,11 +3,14 @@ rule "FC024", "Consider adding platform equivalents" do
|
|
3
3
|
RHEL = %w{centos redhat scientific oracle}.freeze
|
4
4
|
recipe do |ast, filename|
|
5
5
|
next if Pathname.new(filename).basename.to_s == "metadata.rb"
|
6
|
+
|
6
7
|
metadata_path = Pathname.new(
|
7
|
-
File.join(File.dirname(filename), "..", "metadata.rb")
|
8
|
+
File.join(File.dirname(filename), "..", "metadata.rb")
|
9
|
+
).cleanpath
|
8
10
|
md_platforms = if File.exist?(metadata_path)
|
9
11
|
supported_platforms(read_ast(
|
10
|
-
metadata_path
|
12
|
+
metadata_path
|
13
|
+
)).map { |p| p[:platform] }
|
11
14
|
else
|
12
15
|
[]
|
13
16
|
end
|
@@ -16,16 +19,16 @@ rule "FC024", "Consider adding platform equivalents" do
|
|
16
19
|
['//method_add_arg[fcall/ident/@value="platform?"]/
|
17
20
|
arg_paren/args_add_block',
|
18
21
|
"//when"].map do |expr|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
ast.xpath(expr).map do |whn|
|
23
|
+
platforms = whn.xpath('args_add/
|
24
|
+
descendant::tstring_content').map do |p|
|
25
|
+
p["value"]
|
26
|
+
end.sort
|
27
|
+
unless platforms.size == 1 || (md_platforms & platforms).empty?
|
28
|
+
whn unless (platforms & RHEL).empty? ||
|
29
|
+
((md_platforms & RHEL) - (platforms & RHEL)).empty?
|
30
|
+
end
|
31
|
+
end.compact
|
32
|
+
end.flatten
|
30
33
|
end
|
31
34
|
end
|
@@ -3,6 +3,7 @@ rule "FC029", "No leading cookbook name in recipe metadata" do
|
|
3
3
|
metadata do |ast, filename|
|
4
4
|
field(ast, "recipe").map do |declared_recipe|
|
5
5
|
next unless declared_recipe.xpath("count(//vcall|//var_ref)").to_i == 0
|
6
|
+
|
6
7
|
recipe_name = declared_recipe.xpath('args_add_block/
|
7
8
|
descendant::tstring_content[1]/@value').to_s
|
8
9
|
unless recipe_name.empty? ||
|
@@ -1,7 +1,7 @@
|
|
1
1
|
rule "FC031", "Cookbook without metadata.rb file" do
|
2
2
|
tags %w{correctness metadata}
|
3
3
|
cookbook do |filename|
|
4
|
-
|
4
|
+
unless File.exist?(File.join(filename, "metadata.rb"))
|
5
5
|
[file_match(File.join(filename, "metadata.rb"))]
|
6
6
|
end
|
7
7
|
end
|
@@ -2,9 +2,9 @@ rule "FC032", "Invalid notification timing" do
|
|
2
2
|
tags %w{correctness notifications}
|
3
3
|
recipe do |ast|
|
4
4
|
valid_timings = if resource_attribute?("file", "notifies_before")
|
5
|
-
|
5
|
+
%i{delayed immediate before}
|
6
6
|
else
|
7
|
-
|
7
|
+
%i{delayed immediate}
|
8
8
|
end
|
9
9
|
find_resources(ast).select do |resource|
|
10
10
|
notifications(resource).any? do |notification|
|
@@ -9,7 +9,7 @@ rule "FC033", "Missing template file" do
|
|
9
9
|
end.map do |resource|
|
10
10
|
# fetch the specified file to the template
|
11
11
|
file = template_file(resource_attributes(resource,
|
12
|
-
|
12
|
+
return_expressions: true))
|
13
13
|
{ resource: resource, file: file }
|
14
14
|
end.reject do |resource|
|
15
15
|
# skip the check if the file path is derived since
|
@@ -25,7 +25,7 @@ rule "FC033", "Missing template file" do
|
|
25
25
|
# templates/ubuntu/something.erb down to something.erb, which breaks
|
26
26
|
# legit nested dirs in the templates dir like templates/something/something.erb
|
27
27
|
break if template_path.dirname.basename.to_s == "templates" ||
|
28
|
-
|
28
|
+
template_path.dirname.dirname.basename.to_s == "templates"
|
29
29
|
end
|
30
30
|
File.join(relative_path.reverse) == resource[:file]
|
31
31
|
end
|
@@ -9,13 +9,16 @@ rule "FC034", "Unused template variables" do
|
|
9
9
|
File.basename(path) == template_file(resource)
|
10
10
|
end
|
11
11
|
next unless template_paths.any?
|
12
|
+
|
12
13
|
passed_vars = resource["variables"].xpath(
|
13
|
-
"symbol/ident/@value"
|
14
|
+
"symbol/ident/@value"
|
15
|
+
).map(&:to_s)
|
14
16
|
|
15
17
|
unused_vars_exist = template_paths.all? do |template_path|
|
16
18
|
begin
|
17
19
|
template_vars = templates_included(
|
18
|
-
all_templates, template_path
|
20
|
+
all_templates, template_path
|
21
|
+
).map do |template|
|
19
22
|
read_ast(template).xpath("//var_ref/ivar/@value").map do |v|
|
20
23
|
v.to_s.sub(/^@/, "")
|
21
24
|
end
|
@@ -3,17 +3,17 @@ rule "FC039", "Node method cannot be accessed with key" do
|
|
3
3
|
recipe do |ast|
|
4
4
|
[{ type: :string, path: "@value" },
|
5
5
|
{ type: :symbol, path: "ident/@value" }].map do |access_type|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
attribute_access(ast, type: access_type[:type]).select do |att|
|
7
|
+
att_name = att.xpath(access_type[:path]).to_s.to_sym
|
8
|
+
att_name != :tags && chef_node_methods.include?(att_name)
|
9
|
+
end.select do |att|
|
10
|
+
!att.xpath('ancestor::args_add_block[position() = 1]
|
11
|
+
[preceding-sibling::vcall | preceding-sibling::var_ref]').empty?
|
12
|
+
end.select do |att|
|
13
|
+
att_type = att.xpath('ancestor::args_add_block[position() = 1]
|
14
|
+
/../var_ref/ident/@value').to_s
|
15
|
+
ast.xpath("//assign/var_field/ident[@value='#{att_type}']").empty?
|
16
|
+
end
|
17
|
+
end.flatten
|
18
18
|
end
|
19
19
|
end
|
@@ -5,7 +5,7 @@ rule "FC040", "Execute resource used to run git commands" do
|
|
5
5
|
find_resources(ast, type: "execute").select do |cmd|
|
6
6
|
cmd_str = (resource_attribute(cmd, "command") || resource_name(cmd)).to_s
|
7
7
|
|
8
|
-
actual_git_commands = cmd_str.scan(/git ([a-z]+)/).map
|
8
|
+
actual_git_commands = cmd_str.scan(/git ([a-z]+)/).map(&:first)
|
9
9
|
(possible_git_commands & actual_git_commands).any?
|
10
10
|
end
|
11
11
|
end
|
@@ -1,22 +1,18 @@
|
|
1
1
|
rule "FC044", "Avoid bare attribute keys" do
|
2
2
|
tags %w{style}
|
3
3
|
attributes do |ast|
|
4
|
-
declared = ast.xpath("//descendant::var_field/ident/@value").map
|
5
|
-
v.to_s
|
6
|
-
end
|
4
|
+
declared = ast.xpath("//descendant::var_field/ident/@value").map(&:to_s)
|
7
5
|
|
8
6
|
ast.xpath('//assign/*[self::vcall or self::var_ref]
|
9
7
|
[count(child::kw) = 0]/ident').select do |v|
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
val.to_s
|
14
|
-
end
|
9
|
+
local_declared = v.xpath("ancestor::*[self::brace_block or self::do_block]
|
10
|
+
/block_var/descendant::ident/@value").map(&:to_s)
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
(v["value"] != "secure_password") &&
|
13
|
+
!(declared + local_declared).uniq.include?(v["value"]) &&
|
14
|
+
!v.xpath("ancestor::*[self::brace_block or self::do_block]/block_var/
|
15
|
+
descendant::ident/@value='#{v["value"]}'")
|
16
|
+
end
|
21
17
|
end
|
22
18
|
end
|
@@ -7,6 +7,7 @@ rule "FC048", "Prefer shell_out helper method to shelling out with Ruby" do
|
|
7
7
|
ast.xpath('//*[self::command or self::fcall]/ident[@value="system"]').select do |x|
|
8
8
|
resource_name = x.xpath("ancestor::do_block/preceding-sibling::command/ident/@value")
|
9
9
|
next false if resource_name.any? && resource_name.all? { |r| resource_attribute?(r.to_s, "system") }
|
10
|
+
|
10
11
|
next x.xpath('count(following-sibling::args_add_block/descendant::kw[@value="true" or @value="false"]) = 0')
|
11
12
|
end
|
12
13
|
end
|
@@ -1,10 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# metadata do |ast, filename|
|
8
|
-
# [file_match(filename)] unless (declared_dependencies(ast) & %w{build-essential dmg chef_handler chef_hostname mac_os_x swap sysctl}).empty?
|
9
|
-
# end
|
10
|
-
# end
|
1
|
+
rule "FC121", "Cookbook depends on cookbook made obsolete by Chef 14" do
|
2
|
+
tags %w{correctness}
|
3
|
+
metadata do |ast, filename|
|
4
|
+
[file_match(filename)] unless (declared_dependencies(ast) & %w{build-essential dmg chef_handler chef_hostname mac_os_x swap sysctl}).empty?
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
rule "FC123", "Content of a cookbook file is larger than 1MB" do
|
2
|
+
tags %w{files}
|
3
|
+
cookbook do |path|
|
4
|
+
values = []
|
5
|
+
files_path = File.join(path, "files")
|
6
|
+
if File.exist?(files_path)
|
7
|
+
Dir.glob("#{files_path}/**/*").each do |file|
|
8
|
+
size = File.size(file)
|
9
|
+
if size > 1024 * 1024 # 1 megabyte
|
10
|
+
values += [file_match(file)]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
values
|
15
|
+
end
|
16
|
+
end
|
data/lib/foodcritic/template.rb
CHANGED
@@ -20,14 +20,11 @@ module FoodCritic
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def add_text(src, text)
|
24
|
-
end
|
23
|
+
def add_text(src, text); end
|
25
24
|
|
26
|
-
def add_preamble(codebuf)
|
27
|
-
end
|
25
|
+
def add_preamble(codebuf); end
|
28
26
|
|
29
|
-
def add_postamble(codebuf)
|
30
|
-
end
|
27
|
+
def add_postamble(codebuf); end
|
31
28
|
|
32
29
|
def add_stmt(src, code)
|
33
30
|
@expressions << { type: :statement, code: code.strip }
|
data/lib/foodcritic/version.rb
CHANGED
metadata
CHANGED
@@ -1,35 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foodcritic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 16.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Crump
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: cucumber-core
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.3'
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '4.0'
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '1.3'
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '4.0'
|
33
13
|
- !ruby/object:Gem::Dependency
|
34
14
|
name: nokogiri
|
35
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,6 +100,26 @@ dependencies:
|
|
120
100
|
- - "~>"
|
121
101
|
- !ruby/object:Gem::Version
|
122
102
|
version: '1.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: cucumber-core
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.3'
|
110
|
+
- - "<"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '4.0'
|
113
|
+
type: :development
|
114
|
+
prerelease: false
|
115
|
+
version_requirements: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '1.3'
|
120
|
+
- - "<"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '4.0'
|
123
123
|
- !ruby/object:Gem::Dependency
|
124
124
|
name: rspec
|
125
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,8 +162,8 @@ dependencies:
|
|
162
162
|
- - "~>"
|
163
163
|
- !ruby/object:Gem::Version
|
164
164
|
version: '1.0'
|
165
|
-
description:
|
166
|
-
email:
|
165
|
+
description: A code linting tool for Chef Infra cookbooks.
|
166
|
+
email:
|
167
167
|
executables:
|
168
168
|
- foodcritic
|
169
169
|
extensions: []
|
@@ -172,8 +172,8 @@ files:
|
|
172
172
|
- Gemfile
|
173
173
|
- LICENSE
|
174
174
|
- bin/foodcritic
|
175
|
-
- chef_dsl_metadata/
|
176
|
-
- chef_dsl_metadata/
|
175
|
+
- chef_dsl_metadata/chef_14.14.29.json
|
176
|
+
- chef_dsl_metadata/chef_15.4.45.json
|
177
177
|
- foodcritic.gemspec
|
178
178
|
- lib/foodcritic.rb
|
179
179
|
- lib/foodcritic/api.rb
|
@@ -183,6 +183,8 @@ files:
|
|
183
183
|
- lib/foodcritic/domain.rb
|
184
184
|
- lib/foodcritic/dsl.rb
|
185
185
|
- lib/foodcritic/error_checker.rb
|
186
|
+
- lib/foodcritic/gerkin/tag.rb
|
187
|
+
- lib/foodcritic/gerkin/tag_expression.rb
|
186
188
|
- lib/foodcritic/linter.rb
|
187
189
|
- lib/foodcritic/notifications.rb
|
188
190
|
- lib/foodcritic/output.rb
|
@@ -298,6 +300,7 @@ files:
|
|
298
300
|
- lib/foodcritic/rules/fc120.rb
|
299
301
|
- lib/foodcritic/rules/fc121.rb
|
300
302
|
- lib/foodcritic/rules/fc122.rb
|
303
|
+
- lib/foodcritic/rules/fc123.rb
|
301
304
|
- lib/foodcritic/template.rb
|
302
305
|
- lib/foodcritic/version.rb
|
303
306
|
- lib/foodcritic/xml.rb
|
@@ -306,7 +309,7 @@ homepage: http://foodcritic.io
|
|
306
309
|
licenses:
|
307
310
|
- MIT
|
308
311
|
metadata: {}
|
309
|
-
post_install_message:
|
312
|
+
post_install_message:
|
310
313
|
rdoc_options: []
|
311
314
|
require_paths:
|
312
315
|
- lib
|
@@ -321,9 +324,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
321
324
|
- !ruby/object:Gem::Version
|
322
325
|
version: '0'
|
323
326
|
requirements: []
|
324
|
-
|
325
|
-
|
326
|
-
signing_key:
|
327
|
+
rubygems_version: 3.1.2
|
328
|
+
signing_key:
|
327
329
|
specification_version: 4
|
328
|
-
summary: foodcritic-
|
330
|
+
summary: foodcritic-16.3.0
|
329
331
|
test_files: []
|