Switch to using cookstyle
Maintain the current style choices, but does away with a lot of
unnecessary rule bending/exclusion.
Maintains backwards-compatible w/ ChefDK v2.x w/ the
Style/TrailingCommaInLiteral rule. However, this rule breaks newer
configurations, so it should eventually be removed.
MODIFY
.rubocop.yml
.rubocop.yml
# inherit_from: .rubocop_todo.yml
# Stylistic choices of this cookbook.
-AllCops:
- Exclude:
- - 'vendor/**/*' # ignore non-local files
- - Guardfile
-
-# We enjoy parameters lining up for visual comprehension
-Layout/SpaceBeforeFirstArg:
+# We still have HashRockets in a lot of places, ignore them.
+Style/HashSyntax:
Enabled: false
-# We like longer lines
-Metrics/LineLength:
- Max: 160
-
-# Exclude Rakefile and tests since there are long blocks that aren't worth shortening there
-# Also, slightly longer blocks are fine
-Metrics/BlockLength:
- Max: 30
- Exclude:
- - 'Rakefile'
- - 'spec/**/*.rb'
- - 'test/**/*.rb'
-
-
-# Slightly longer methods are fine
-Metrics/MethodLength:
- Max: 15
-
# We're fine with multi-line blocks defined with `{...}` instead of `do...end`
Style/BlockDelimiters:
Enabled: false
-Style/FrozenStringLiteralComment:
- Enabled: false
+Style/PercentLiteralDelimiters:
+ PreferredDelimiters:
+ default: '[]'
+ '%i': '[]'
+ '%w': '[]'
-Style/SafeNavigation:
+Style/TrailingCommaInArrayLiteral:
Enabled: false
-# TODO: add encoding headers
-Style/Encoding:
+Style/TrailingCommaInHashLiteral:
Enabled: false
-# Our code has names with dashes.
-Style/FileName:
- Enabled: false
-
-# We still have HashRockets in a lot of places, ignore them.
-Style/HashSyntax:
- Enabled: false
-
-# Increase readability of large numbers after 5 digits (ports) only.
-Style/NumericLiterals:
- MinDigits: 6
-
-# TODO: see if this should be replaced by Chef::Application.fatal!
-Style/SignalException:
+Style/TrailingCommaInLiteral:
Enabled: false
# Only enforce a wordlist for 5 or longer lists.

MODIFY
Rakefile
Rakefile
@@ -6,6 +6,7 @@ require 'foodcritic'
require 'kitchen/rake_tasks'
require 'rake/clean'
require 'rspec/core/rake_task'
+require 'cookstyle'
require 'rubocop/rake_task'
task :default => %i[

MODIFY
providers/monitor.rb
providers/monitor.rb
@@ -7,7 +7,7 @@ def whyrun_supported?
true
end
-action :add do # rubocop:disable Metrics/BlockLength
+action :add do
Chef::Log.debug "Adding monitoring for #{new_resource.name}"
template ::File.join(yaml_dir, "#{new_resource.name}.yaml") do
if node['platform_family'] == 'windows'

MODIFY
recipes/_agent6_config.rb
recipes/_agent6_config.rb
is_windows = node['platform_family'] == 'windows'
agent6_config_file = ::File.join(node['datadog']['agent6_config_dir'], 'datadog.yaml')
-template agent6_config_file do # rubocop:disable Metrics/BlockLength
- def template_vars # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
+template agent6_config_file do
+ def template_vars
additional_endpoints = {}
node['datadog']['extra_endpoints'].each do |_, endpoint|
next unless endpoint['enabled']

MODIFY
recipes/dd-agent.rb
recipes/dd-agent.rb
@@ -63,8 +63,8 @@ else
end
agent_config_file = ::File.join(node['datadog']['config_dir'], 'datadog.conf')
- template agent_config_file do # rubocop:disable Metrics/BlockLength
- def template_vars # rubocop:disable Metrics/AbcSize
+ template agent_config_file do
+ def template_vars
api_keys = [Chef::Datadog.api_key(node)]
dd_urls = [node['datadog']['url']]
node['datadog']['extra_endpoints'].each do |_, endpoint|

MODIFY
recipes/dd-handler.rb
recipes/dd-handler.rb
@@ -49,7 +49,7 @@ unless web_proxy['host'].nil?
end
# Create the handler to run at the end of the Chef execution
-chef_handler 'Chef::Handler::Datadog' do # rubocop:disable Metrics/BlockLength
+chef_handler 'Chef::Handler::Datadog' do
def extra_endpoints
extra_endpoints = []
node['datadog']['extra_endpoints'].each do |_, endpoint|
@@ -61,7 +61,7 @@ chef_handler 'Chef::Handler::Datadog' do # rubocop:disable Metrics/BlockLength
extra_endpoints
end
- def handler_config # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
+ def handler_config
extra_config = node['datadog']['handler_extra_config'].reject { |_, v| v.nil? }
config = extra_config.merge(
:api_key => Chef::Datadog.api_key(node),

Switch to using cookstyle (#565)

Maintain the current style choices, but does away with a lot of
unnecessary rule bending/exclusion.

Maintains backwards-compatible w/ ChefDK v2.x w/ the
Style/TrailingCommaInLiteral rule. However, this rule breaks newer
configurations, so it should eventually be removed.