Skip to content

Commit

Permalink
Switch to using cookstyle (DataDog#565)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeffbyrnes authored and olivielpeau committed Oct 29, 2018
1 parent dd42829 commit d607fc9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 51 deletions.
54 changes: 10 additions & 44 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,27 @@
# 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.
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down
2 changes: 1 addition & 1 deletion providers/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions recipes/_agent6_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
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']
Expand Down
4 changes: 2 additions & 2 deletions recipes/dd-agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
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|
Expand Down
4 changes: 2 additions & 2 deletions recipes/dd-handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
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|
Expand All @@ -61,7 +61,7 @@ def extra_endpoints
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),
Expand Down

0 comments on commit d607fc9

Please sign in to comment.