foodcritic 16.0.0 → 16.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -254,14 +254,20 @@ module FoodCritic
254
254
  line: pos["line"].to_i, column: pos["column"].to_i }
255
255
  end
256
256
 
257
+ # Returns a global LRU cache holding the AST of a file
258
+ # @since 16.1
259
+ # @param size [Integer] the size of the cache (will be resized)
260
+ def ast_cache(size = nil)
261
+ @@ast_cache ||= Rufus::Lru::Hash.new(size || 5)
262
+ if size && @@ast_cache.maxsize != size
263
+ @@ast_cache.maxsize = size
264
+ end
265
+ @@ast_cache
266
+ end
267
+
257
268
  # Read the AST for the given Ruby source file
258
269
  def read_ast(file)
259
- @ast_cache ||= Rufus::Lru::Hash.new(5)
260
- if @ast_cache.include?(file)
261
- @ast_cache[file]
262
- else
263
- @ast_cache[file] = uncached_read_ast(file)
264
- end
270
+ ast_cache[file] ||= uncached_read_ast(file)
265
271
  end
266
272
 
267
273
  # Retrieve a single-valued attribute from the specified resource.
@@ -517,7 +523,7 @@ module FoodCritic
517
523
  # those exist in cookbooks, but are not longer part of chef 14+
518
524
  # this prevents false positives in FC019 anytime node.set is found
519
525
  def node_method?(meth, cookbook_dir)
520
- chef_dsl_methods.include?(meth) || meth == :set || meth == :set_unless ||
526
+ chef_node_methods.include?(meth) || meth == :set || meth == :set_unless ||
521
527
  patched_node_method?(meth, cookbook_dir)
522
528
  end
523
529
 
@@ -24,6 +24,7 @@ module FoodCritic
24
24
  environment_paths: [],
25
25
  exclude_paths: ["test/**/*", "spec/**/*", "features/**/*"],
26
26
  progress: true,
27
+ ast_cache_size: 5,
27
28
  }
28
29
  @parser = OptionParser.new do |opts|
29
30
  opts.banner = "foodcritic [cookbook_paths]"
@@ -50,6 +51,10 @@ module FoodCritic
50
51
  "Specify file with rules to be used or ignored ") do |c|
51
52
  @options[:rule_file] = c
52
53
  end
54
+ opts.on("-s", "--ast-cache-size NUM", Integer,
55
+ "Change the size of the AST cache.") do |s|
56
+ @options[:ast_cache_size] = s
57
+ end
53
58
  opts.on("-B", "--cookbook-path PATH",
54
59
  "Cookbook path(s) to check.") do |b|
55
60
  @options[:cookbook_paths] << b
@@ -9,7 +9,7 @@ module FoodCritic
9
9
 
10
10
  # The default version that will be used to determine relevant rules. This
11
11
  # can be over-ridden at the command line with the `--chef-version` option.
12
- DEFAULT_CHEF_VERSION = "15.0.293".freeze
12
+ DEFAULT_CHEF_VERSION = "15.1.36".freeze
13
13
  attr_reader :chef_version
14
14
 
15
15
  # Perform a lint check. This method is intended for use by the command-line
@@ -68,6 +68,7 @@ module FoodCritic
68
68
  options = setup_defaults(options)
69
69
  @options = options
70
70
  @chef_version = options[:chef_version] || DEFAULT_CHEF_VERSION
71
+ ast_cache(options[:ast_cache_size])
71
72
 
72
73
  warnings = []; last_dir = nil; matched_rule_tags = Set.new
73
74
  load_rules
@@ -0,0 +1,14 @@
1
+ rule "FC123", "Content of files/ is larger than 1MB" do
2
+ tags %w{files}
3
+ cookbook do |path|
4
+ values = []
5
+ Dir.foreach(File.join(path, "files")) do |file|
6
+ next if ['.', '..'].member?(file)
7
+ size = File.size(File.join(path,'files',file))
8
+ if size > 1024*1024 # 1 megabyte
9
+ values += [file_match(File.join(path,'files',file))]
10
+ end
11
+ end
12
+ values
13
+ end
14
+ end
@@ -1,4 +1,4 @@
1
1
  module FoodCritic
2
2
  # The current version of foodcritic
3
- VERSION = "16.0.0".freeze
3
+ VERSION = "16.1.0".freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foodcritic
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.0.0
4
+ version: 16.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Crump
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-14 00:00:00.000000000 Z
11
+ date: 2019-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber-core
@@ -173,7 +173,7 @@ files:
173
173
  - LICENSE
174
174
  - bin/foodcritic
175
175
  - chef_dsl_metadata/chef_14.12.9.json
176
- - chef_dsl_metadata/chef_15.0.293.json
176
+ - chef_dsl_metadata/chef_15.1.36.json
177
177
  - foodcritic.gemspec
178
178
  - lib/foodcritic.rb
179
179
  - lib/foodcritic/api.rb
@@ -298,6 +298,7 @@ files:
298
298
  - lib/foodcritic/rules/fc120.rb
299
299
  - lib/foodcritic/rules/fc121.rb
300
300
  - lib/foodcritic/rules/fc122.rb
301
+ - lib/foodcritic/rules/fc123.rb
301
302
  - lib/foodcritic/template.rb
302
303
  - lib/foodcritic/version.rb
303
304
  - lib/foodcritic/xml.rb
@@ -324,5 +325,5 @@ requirements: []
324
325
  rubygems_version: 3.0.3
325
326
  signing_key:
326
327
  specification_version: 4
327
- summary: foodcritic-16.0.0
328
+ summary: foodcritic-16.1.0
328
329
  test_files: []