Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate that all cops are in the config in CI + add missing Chef/CookbookUsesNodeSave #272

Merged
merged 4 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ task :vendor do
end

require 'cookstyle'
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:style) do |task|
task.options << '--display-cop-names'
task :style do
sh('bundle exec cookstyle')
end

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
spec.pattern = FileList['spec/cop/**/*.rb']
end

desc 'Run RSpec with code coverage'
Expand All @@ -36,9 +35,25 @@ task :coverage do
Rake::Task['spec'].execute
end

desc 'Run RuboCop over this gem'
task :internal_investigation do
sh('bundle exec rubocop --require rubocop-rspec')
desc 'Ensure that all cops are defined in the cookstyle.yml config'
task :validate_config do
require 'cookstyle'
require 'yaml'
status = 0
config = YAML.load_file('config/cookstyle.yml')

puts 'Checking that all cops are defined in config/cookstyle.yml:'

RuboCop::Cop::Chef.constants.each do |cop|
unless config["Chef/#{cop}"]
puts "Error: Chef/#{cop} not found in config/cookstyle.yml"
status = 1
end
end

puts 'All Cops found in the config. Good work.' if status == 0

exit status
end

begin
Expand All @@ -54,4 +69,4 @@ task :console do
ARGV.clear
IRB.start
end
task default: [:style, :spec]
task default: [:style, :spec, :validate_config]
7 changes: 7 additions & 0 deletions config/cookstyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ Chef/InvalidPlatformMetadata:
Include:
- '**/metadata.rb'

Chef/CookbookUsesNodeSave:
Description: Don't use node.save to save partial node data to the Chef Infra Server mid-run unless it's absolutely necessary. Node.save can result in failed Chef Infra runs appearing in search and increases load on the Chef Infra Server.
Enabled: true
VersionAdded: '5.5.0'
Exclude:
- '**/metadata.rb'

###############################
# Resolving Deprecations
###############################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
module RuboCop
module Cop
module Chef
# Do not use node.save with effortless as there is no server to save node state back to
# Don't use node.save to save partial node data to the Chef Infra Server mid-run unless it's
# absolutely necessary. Node.save can result in failed Chef Infra runs appearing in search and
# increases load on the Chef Infra Server."
#
# @example
#
# # bad
# node.save
class CookbookUsesNodeSave < Cop
MSG = 'Do not use node.save with Effortless as there is no server to save node state back to'.freeze
MSG = "Don't use node.save to save partial node data to the Chef Infra Server mid-run unless it's absolutely necessary. Node.save can result in failed Chef Infra runs appearing in search and increases load on the Chef Infra Server.".freeze

def_node_matcher :node_save?, <<-PATTERN
(send (send nil? :node) :save)
Expand Down