foodcritic 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/chef_dsl_metadata/chef_0.10.0.json +7108 -0
  2. data/chef_dsl_metadata/chef_0.10.10.json +7879 -0
  3. data/chef_dsl_metadata/chef_0.10.2.json +7108 -0
  4. data/chef_dsl_metadata/chef_0.10.4.json +7303 -0
  5. data/chef_dsl_metadata/chef_0.10.6.json +7368 -0
  6. data/chef_dsl_metadata/chef_0.10.8.json +7368 -0
  7. data/chef_dsl_metadata/chef_0.8.14.json +6374 -0
  8. data/chef_dsl_metadata/chef_0.8.16.json +6374 -0
  9. data/chef_dsl_metadata/chef_0.9.0.json +6817 -0
  10. data/chef_dsl_metadata/chef_0.9.10.json +7481 -0
  11. data/chef_dsl_metadata/chef_0.9.12.json +7481 -0
  12. data/chef_dsl_metadata/chef_0.9.14.json +7485 -0
  13. data/chef_dsl_metadata/chef_0.9.16.json +7485 -0
  14. data/chef_dsl_metadata/chef_0.9.18.json +7485 -0
  15. data/chef_dsl_metadata/chef_0.9.2.json +6817 -0
  16. data/chef_dsl_metadata/chef_0.9.4.json +6862 -0
  17. data/chef_dsl_metadata/chef_0.9.6.json +6862 -0
  18. data/chef_dsl_metadata/chef_0.9.8.json +6866 -0
  19. data/chef_dsl_metadata/chef_10.12.0.json +7879 -0
  20. data/{chef_dsl_metadata.json → chef_dsl_metadata/chef_10.14.0.json} +156 -54
  21. data/chef_dsl_metadata/chef_10.14.2.json +8436 -0
  22. data/chef_dsl_metadata/chef_10.14.4.json +8436 -0
  23. data/chef_dsl_metadata/chef_10.16.0.json +8437 -0
  24. data/chef_dsl_metadata/chef_10.16.2.json +8437 -0
  25. data/chef_dsl_metadata/chef_10.16.4.json +8437 -0
  26. data/chef_dsl_metadata/chef_10.16.6.json +8437 -0
  27. data/chef_dsl_metadata/chef_10.18.0.json +8438 -0
  28. data/chef_dsl_metadata/chef_10.18.2.json +8438 -0
  29. data/chef_dsl_metadata/chef_10.20.0.json +8438 -0
  30. data/chef_dsl_metadata/chef_10.22.0.json +8438 -0
  31. data/chef_dsl_metadata/chef_10.24.0.json +8438 -0
  32. data/chef_dsl_metadata/chef_11.0.0.json +8772 -0
  33. data/chef_dsl_metadata/chef_11.2.0.json +8772 -0
  34. data/chef_dsl_metadata/chef_11.4.0.json +8772 -0
  35. data/lib/foodcritic/ast.rb +1 -1
  36. data/lib/foodcritic/chef.rb +12 -9
  37. data/lib/foodcritic/dsl.rb +7 -2
  38. data/lib/foodcritic/linter.rb +6 -4
  39. data/lib/foodcritic/version.rb +1 -1
  40. metadata +40 -7
@@ -8,7 +8,7 @@ module FoodCritic
8
8
  end
9
9
 
10
10
  def ast_node_has_children?(node)
11
- node.respond_to?(:first)
11
+ node.respond_to?(:first) and ! node.respond_to?(:match)
12
12
  end
13
13
 
14
14
  # If the provided node is the line / column information.
@@ -45,20 +45,23 @@ module FoodCritic
45
45
  # To avoid the runtime hit of loading the Chef gem and its dependencies
46
46
  # we load the DSL metadata from a JSON file shipped with our gem.
47
47
  #
48
- # The DSL metadata therefore reflects the version of Chef in the gemset
49
- # where foodcritic was built, rather than the version in the local user
50
- # gemset.
51
- #
52
- # TODO: Now that the effective version of Chef to check with can be passed
53
- # on the command-line we should bundle metadata for historical Chef gem
54
- # versions.
48
+ # The DSL metadata doesn't necessarily reflect the version of Chef in the
49
+ # local user gemset.
55
50
  def load_metadata
56
- metadata_path = File.join(File.dirname(__FILE__), '..', '..',
57
- 'chef_dsl_metadata.json')
51
+ version = self.respond_to?(:chef_version) ? chef_version : Linter::DEFAULT_CHEF_VERSION
52
+ metadata_path = [version, version.sub(/\.[a-z].*/, ''),
53
+ Linter::DEFAULT_CHEF_VERSION].map do |version|
54
+ metadata_path(version)
55
+ end.find{|m| File.exists?(m)}
58
56
  @dsl_metadata ||= Yajl::Parser.parse(IO.read(metadata_path),
59
57
  :symbolize_keys => true)
60
58
  end
61
59
 
60
+ def metadata_path(chef_version)
61
+ File.join(File.dirname(__FILE__), '..', '..',
62
+ "chef_dsl_metadata/chef_#{chef_version}.json")
63
+ end
64
+
62
65
  def resource_check?(key, resource_type, field)
63
66
  if resource_type.to_s.empty? || field.to_s.empty?
64
67
  raise ArgumentError, "Arguments cannot be nil or empty."
@@ -23,9 +23,14 @@ module FoodCritic
23
23
 
24
24
  class RuleDsl
25
25
  attr_reader :rules
26
+ attr_reader :chef_version
26
27
 
27
28
  include Api
28
29
 
30
+ def initialize(chef_version=Linter::DEFAULT_CHEF_VERSION)
31
+ @chef_version = chef_version
32
+ end
33
+
29
34
  # Define a new rule, the outer block of a rule definition.
30
35
  def rule(code, name, &block)
31
36
  @rules = [] if @rules.nil?
@@ -65,8 +70,8 @@ module FoodCritic
65
70
  rule_block :template
66
71
 
67
72
  # Load the ruleset(s).
68
- def self.load(paths)
69
- dsl = RuleDsl.new
73
+ def self.load(paths, chef_version=Linter::DEFAULT_CHEF_VERSION)
74
+ dsl = RuleDsl.new(chef_version)
70
75
  paths.map do |path|
71
76
  File.directory?(path) ? Dir["#{path}/**/*.rb"].sort : path
72
77
  end.flatten.each do |path|
@@ -12,7 +12,8 @@ module FoodCritic
12
12
 
13
13
  # The default version that will be used to determine relevant rules. This
14
14
  # can be over-ridden at the command line with the `--chef-version` option.
15
- DEFAULT_CHEF_VERSION = "0.10.10"
15
+ DEFAULT_CHEF_VERSION = "11.4.0"
16
+ attr_reader :chef_version
16
17
 
17
18
  # Perform a lint check. This method is intended for use by the command-line
18
19
  # wrapper. If you are programatically using foodcritic you should use
@@ -47,6 +48,7 @@ module FoodCritic
47
48
  cookbook_paths = sanity_check_cookbook_paths(cookbook_paths)
48
49
  options = setup_defaults(options)
49
50
  @options = options
51
+ @chef_version = options[:chef_version] || DEFAULT_CHEF_VERSION
50
52
 
51
53
  warnings = []; last_dir = nil; matched_rule_tags = Set.new
52
54
 
@@ -92,7 +94,7 @@ module FoodCritic
92
94
 
93
95
  def load_rules!(options)
94
96
  @rules = RuleDsl.load([File.join(File.dirname(__FILE__), 'rules.rb')] +
95
- options[:include_rules])
97
+ options[:include_rules], chef_version)
96
98
  end
97
99
 
98
100
  private
@@ -123,7 +125,7 @@ module FoodCritic
123
125
  def active_rules(options)
124
126
  @rules.select do |rule|
125
127
  matching_tags?(options[:tags], rule.tags) and
126
- applies_to_version?(rule, options[:chef_version] || DEFAULT_CHEF_VERSION)
128
+ applies_to_version?(rule, chef_version)
127
129
  end
128
130
  end
129
131
 
@@ -188,7 +190,7 @@ module FoodCritic
188
190
 
189
191
  # We use the Gherkin (Cucumber) syntax to specify tags.
190
192
  def matching_tags?(tag_expr, tags)
191
- Gherkin::TagExpression.new(tag_expr).eval(tags.map do |t|
193
+ Gherkin::TagExpression.new(tag_expr).evaluate(tags.map do |t|
192
194
  Gherkin::Formatter::Model::Tag.new(t, 1)
193
195
  end)
194
196
  end
@@ -1,4 +1,4 @@
1
1
  module FoodCritic
2
2
  # The current version of foodcritic
3
- VERSION = '2.0.1'
3
+ VERSION = '2.1.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foodcritic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-31 00:00:00.000000000 Z
12
+ date: 2013-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gherkin
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.11.1
21
+ version: 2.11.7
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 2.11.1
29
+ version: 2.11.7
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: nokogiri
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +114,40 @@ executables:
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
+ - chef_dsl_metadata/chef_10.20.0.json
118
+ - chef_dsl_metadata/chef_10.12.0.json
119
+ - chef_dsl_metadata/chef_10.18.2.json
120
+ - chef_dsl_metadata/chef_0.10.10.json
121
+ - chef_dsl_metadata/chef_0.9.4.json
122
+ - chef_dsl_metadata/chef_0.10.8.json
123
+ - chef_dsl_metadata/chef_10.14.4.json
124
+ - chef_dsl_metadata/chef_0.9.12.json
125
+ - chef_dsl_metadata/chef_10.22.0.json
126
+ - chef_dsl_metadata/chef_0.10.6.json
127
+ - chef_dsl_metadata/chef_11.0.0.json
128
+ - chef_dsl_metadata/chef_0.9.8.json
129
+ - chef_dsl_metadata/chef_11.4.0.json
130
+ - chef_dsl_metadata/chef_0.8.14.json
131
+ - chef_dsl_metadata/chef_0.9.18.json
132
+ - chef_dsl_metadata/chef_10.16.0.json
133
+ - chef_dsl_metadata/chef_0.9.16.json
134
+ - chef_dsl_metadata/chef_0.9.2.json
135
+ - chef_dsl_metadata/chef_0.9.6.json
136
+ - chef_dsl_metadata/chef_10.16.6.json
137
+ - chef_dsl_metadata/chef_10.16.4.json
138
+ - chef_dsl_metadata/chef_0.9.14.json
139
+ - chef_dsl_metadata/chef_10.18.0.json
140
+ - chef_dsl_metadata/chef_0.10.2.json
141
+ - chef_dsl_metadata/chef_0.9.0.json
142
+ - chef_dsl_metadata/chef_0.8.16.json
143
+ - chef_dsl_metadata/chef_0.10.4.json
144
+ - chef_dsl_metadata/chef_0.10.0.json
145
+ - chef_dsl_metadata/chef_10.16.2.json
146
+ - chef_dsl_metadata/chef_10.24.0.json
147
+ - chef_dsl_metadata/chef_10.14.2.json
148
+ - chef_dsl_metadata/chef_10.14.0.json
149
+ - chef_dsl_metadata/chef_11.2.0.json
150
+ - chef_dsl_metadata/chef_0.9.10.json
117
151
  - lib/foodcritic/dsl.rb
118
152
  - lib/foodcritic/command_line.rb
119
153
  - lib/foodcritic/rake_task.rb
@@ -130,7 +164,6 @@ files:
130
164
  - lib/foodcritic/version.rb
131
165
  - lib/foodcritic/notifications.rb
132
166
  - lib/foodcritic.rb
133
- - chef_dsl_metadata.json
134
167
  - bin/foodcritic
135
168
  homepage: http://acrmp.github.com/foodcritic
136
169
  licenses:
@@ -153,11 +186,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
186
  version: '0'
154
187
  segments:
155
188
  - 0
156
- hash: 118769465480030125
189
+ hash: 1124034577266906098
157
190
  requirements: []
158
191
  rubyforge_project:
159
192
  rubygems_version: 1.8.25
160
193
  signing_key:
161
194
  specification_version: 3
162
- summary: foodcritic-2.0.1
195
+ summary: foodcritic-2.1.0
163
196
  test_files: []