module RuboCop::Chef::CookbookOnly

Mixin for cops that skips non-cookbook files

The criteria for whether cookstyle analyzes a certain ruby file is configured via ‘AllCops/Chef`. For example, if you want to customize your project to scan all files within a `test/` directory then you could add this to your configuration:

@example configuring analyzed paths

AllCops:
  Chef:
    Patterns:
    - '_spec.rb$'
    - '(?:^|/)spec/'

Constants

COOKBOOK_SEGMENTS
DEFAULT_CONFIGURATION

Public Instance Methods

relevant_file?(file) click to toggle source
Calls superclass method
# File lib/rubocop/chef/cookbook_only.rb, line 24
def relevant_file?(file)
  cookbook_pattern =~ file && super
end

Private Instance Methods

cookbook_pattern() click to toggle source
# File lib/rubocop/chef/cookbook_only.rb, line 30
def cookbook_pattern
  patterns = []
  COOKBOOK_SEGMENTS.each do |segment|
    next unless self.class.cookbook_only_segments[segment.to_sym]

    cookbook_pattern_config(segment).each do |pattern|
      patterns << Regexp.new(pattern)
    end
  end
  Regexp.union(patterns)
end
cookbook_pattern_config(segment) click to toggle source
# File lib/rubocop/chef/cookbook_only.rb, line 42
def cookbook_pattern_config(segment)
  config_key = "Chef#{segment.capitalize}"
  config
    .for_all_cops
    .fetch(config_key, DEFAULT_CONFIGURATION.fetch(config_key))
    .fetch('Patterns')
end