From 8df838bf09d95282ba29ddde8b504e0affc5f06e Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 14 Nov 2017 19:11:00 +0000 Subject: [PATCH] Fix rubocop warnings --- .rubocop.yml | 2 +- cookbooks/accounts/recipes/default.rb | 1 - cookbooks/civicrm/recipes/default.rb | 2 +- cookbooks/hardware/recipes/default.rb | 2 +- cookbooks/imagery/recipes/gb_os_sv.rb | 2 -- cookbooks/kibana/recipes/default.rb | 2 -- cookbooks/munin/files/default/plugins/api_calls_ | 2 +- cookbooks/munin/files/default/plugins/api_calls_num | 2 +- cookbooks/munin/files/default/plugins/api_calls_status | 2 +- cookbooks/munin/files/default/plugins/api_waits_ | 2 +- cookbooks/munin/files/default/plugins/passenger_memory | 6 +++--- cookbooks/munin/files/default/plugins/passenger_processes | 6 +++--- cookbooks/munin/files/default/plugins/passenger_queues | 6 +++--- cookbooks/munin/files/default/plugins/passenger_requests | 6 +++--- cookbooks/mysql/libraries/mysql.rb | 4 ++-- .../files/default/replication-bin/replicate-changesets | 2 +- cookbooks/wordpress/providers/site.rb | 4 ++-- roles/paulla.rb | 2 -- roles/teleservice.rb | 2 -- 19 files changed, 24 insertions(+), 33 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 07985407d..9d9ce40b0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,7 +13,7 @@ Layout/ExtraSpacing: Layout/IndentHeredoc: EnforcedStyle: squiggly -Style/FileName: +Naming/FileName: Exclude: - 'cookbooks/trac/files/default/trac-authenticate' - 'cookbooks/planet/files/default/replication-bin/replicate-changesets' diff --git a/cookbooks/accounts/recipes/default.rb b/cookbooks/accounts/recipes/default.rb index c6424b3ed..76c3a8460 100644 --- a/cookbooks/accounts/recipes/default.rb +++ b/cookbooks/accounts/recipes/default.rb @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Cookbook Name:: accounts # Recipe:: default diff --git a/cookbooks/civicrm/recipes/default.rb b/cookbooks/civicrm/recipes/default.rb index e6d1c0015..46df483cd 100644 --- a/cookbooks/civicrm/recipes/default.rb +++ b/cookbooks/civicrm/recipes/default.rb @@ -129,7 +129,7 @@ directory extensions_directory do mode 0o755 end -node[:civicrm][:extensions].each do |_, details| +node[:civicrm][:extensions].each_value do |details| git "#{extensions_directory}/#{details[:name]}" do action :sync repository details[:repository] diff --git a/cookbooks/hardware/recipes/default.rb b/cookbooks/hardware/recipes/default.rb index 4710e5ef5..41eae5a5b 100644 --- a/cookbooks/hardware/recipes/default.rb +++ b/cookbooks/hardware/recipes/default.rb @@ -424,7 +424,7 @@ if disks.count.positive? # an Areca controller as they only allow one thing to # talk to the controller at a time and smartd will # throw errors if it clashes with munin - disks = disks.reject { |disk| disk[:smart] && disk[:smart].start_with?("areca,") } + disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") } disks.each do |disk| munin_plugin "smart_#{disk[:munin]}" do diff --git a/cookbooks/imagery/recipes/gb_os_sv.rb b/cookbooks/imagery/recipes/gb_os_sv.rb index 4dcf0bd0b..9b7599bed 100644 --- a/cookbooks/imagery/recipes/gb_os_sv.rb +++ b/cookbooks/imagery/recipes/gb_os_sv.rb @@ -1,5 +1,3 @@ -# coding: utf-8 - # # Cookbook Name:: imagery # Recipe:: gb_os_sv diff --git a/cookbooks/kibana/recipes/default.rb b/cookbooks/kibana/recipes/default.rb index 9f17df934..cc9b7f020 100644 --- a/cookbooks/kibana/recipes/default.rb +++ b/cookbooks/kibana/recipes/default.rb @@ -1,5 +1,3 @@ -# coding: utf-8 - # # Cookbook Name:: kibana # Recipe:: default diff --git a/cookbooks/munin/files/default/plugins/api_calls_ b/cookbooks/munin/files/default/plugins/api_calls_ index 79c306635..ea95ed137 100755 --- a/cookbooks/munin/files/default/plugins/api_calls_ +++ b/cookbooks/munin/files/default/plugins/api_calls_ @@ -62,7 +62,7 @@ else end end - CALL_TYPES.keys.each do |type| + CALL_TYPES.each_key do |type| count = counts[type] || 0 puts "#{type}.value #{count}" end diff --git a/cookbooks/munin/files/default/plugins/api_calls_num b/cookbooks/munin/files/default/plugins/api_calls_num index e2f74d9ff..e776505d2 100755 --- a/cookbooks/munin/files/default/plugins/api_calls_num +++ b/cookbooks/munin/files/default/plugins/api_calls_num @@ -27,7 +27,7 @@ if ARGV[0] == "config" else statistics = JSON.parse(File.read("/srv/www.openstreetmap.org/rails/tmp/statistics.json")) - CALL_TYPES.keys.each do |type| + CALL_TYPES.each_key do |type| count = statistics["uri"][type.to_s] || 0 puts "#{type}.value #{count}" end diff --git a/cookbooks/munin/files/default/plugins/api_calls_status b/cookbooks/munin/files/default/plugins/api_calls_status index 0d7c9b645..4a9623f9b 100755 --- a/cookbooks/munin/files/default/plugins/api_calls_status +++ b/cookbooks/munin/files/default/plugins/api_calls_status @@ -40,7 +40,7 @@ if ARGV[0] == "config" else statistics = JSON.parse(File.read("/srv/www.openstreetmap.org/rails/tmp/statistics.json")) - HTTP_STATUSES.keys.each do |code| + HTTP_STATUSES.each_key do |code| count = statistics["status"][code] || 0 puts "http#{code}.value #{count}" end diff --git a/cookbooks/munin/files/default/plugins/api_waits_ b/cookbooks/munin/files/default/plugins/api_waits_ index f5bbd1104..f575dad1c 100755 --- a/cookbooks/munin/files/default/plugins/api_waits_ +++ b/cookbooks/munin/files/default/plugins/api_waits_ @@ -63,7 +63,7 @@ else end end - CALL_TYPES.keys.each do |type| + CALL_TYPES.each_key do |type| count = counts[type] || [0] avg = count.inject(0) { |acc, elem| acc + elem } / (1.0 * count.length) puts "#{type}.value #{avg}" diff --git a/cookbooks/munin/files/default/plugins/passenger_memory b/cookbooks/munin/files/default/plugins/passenger_memory index 7017c63e0..dd0f66381 100755 --- a/cookbooks/munin/files/default/plugins/passenger_memory +++ b/cookbooks/munin/files/default/plugins/passenger_memory @@ -6,20 +6,20 @@ require "English" def output_config - puts <<~END + puts <<~CONFIG graph_args --base 1024 -l 0 --vertical-label bytes --upper-limit 4056231936 graph_category passenger graph_title Passenger memory memory.label memory - END + CONFIG exit 0 end def output_values status = `/usr/sbin/passenger-memory-stats | tail -1` unless $CHILD_STATUS.success? - $stderr.puts "failed executing passenger-memory-stats" + warn "failed executing passenger-memory-stats" exit 1 end status =~ /(\d+\.\d+)/ diff --git a/cookbooks/munin/files/default/plugins/passenger_processes b/cookbooks/munin/files/default/plugins/passenger_processes index b8a06cf3a..0611ccc0e 100755 --- a/cookbooks/munin/files/default/plugins/passenger_processes +++ b/cookbooks/munin/files/default/plugins/passenger_processes @@ -3,7 +3,7 @@ require "English" def output_config - puts <<~END + puts <<~CONFIG graph_category passenger graph_title Passenger processes graph_order active inactive @@ -14,14 +14,14 @@ def output_config active.draw AREA inactive.label idle servers inactive.draw STACK - END + CONFIG exit 0 end def output_values status = `/usr/sbin/passenger-status` unless $CHILD_STATUS.success? - $stderr.puts "failed executing passenger-status" + warn "failed executing passenger-status" exit 1 end status =~ /active\s+=\s+(\d+)/ diff --git a/cookbooks/munin/files/default/plugins/passenger_queues b/cookbooks/munin/files/default/plugins/passenger_queues index 8d4159b46..0850ed273 100755 --- a/cookbooks/munin/files/default/plugins/passenger_queues +++ b/cookbooks/munin/files/default/plugins/passenger_queues @@ -3,20 +3,20 @@ require "English" def output_config - puts <<~END + puts <<~CONFIG graph_category passenger graph_title Passenger queues graph_vlabel count global.label global - END + CONFIG exit 0 end def output_values status = `/usr/sbin/passenger-status` unless $CHILD_STATUS.success? - $stderr.puts "failed executing passenger-status" + warn "failed executing passenger-status" exit 1 end status =~ /Requests in top-level queue :\s+(\d+)/ diff --git a/cookbooks/munin/files/default/plugins/passenger_requests b/cookbooks/munin/files/default/plugins/passenger_requests index 3eeb776d6..dac457e33 100755 --- a/cookbooks/munin/files/default/plugins/passenger_requests +++ b/cookbooks/munin/files/default/plugins/passenger_requests @@ -3,7 +3,7 @@ require "English" def output_config - puts <<~END + puts <<~CONFIG graph_args --base 1000 graph_category passenger graph_title Passenger requests @@ -13,14 +13,14 @@ def output_config requests.type DERIVE requests.max 1000000 requests.min 0 - END + CONFIG exit 0 end def output_values status = `/usr/sbin/passenger-status` unless $CHILD_STATUS.success? - $stderr.puts "failed executing passenger-status" + warn "failed executing passenger-status" exit 1 end total_requests = 0 diff --git a/cookbooks/mysql/libraries/mysql.rb b/cookbooks/mysql/libraries/mysql.rb index dc692a780..7c45022fd 100644 --- a/cookbooks/mysql/libraries/mysql.rb +++ b/cookbooks/mysql/libraries/mysql.rb @@ -55,7 +55,7 @@ class Chef def query(sql, options = {}) # Run the query - result = execute(options.merge(:command => sql, :xml => :true)) + result = execute(options.merge(:command => sql, :xml => true)) # Parse the output document = REXML::Document.new(result.stdout) @@ -119,7 +119,7 @@ class Chef def canonicalise_user(user) local, host = user.split("@") - host = "%" unless host + host ||= "%" local = "'#{local}'" unless local =~ /^'.*'$/ host = "'#{host}'" unless host =~ /^'.*'$/ diff --git a/cookbooks/planet/files/default/replication-bin/replicate-changesets b/cookbooks/planet/files/default/replication-bin/replicate-changesets index 3cf54291f..92103bb1f 100755 --- a/cookbooks/planet/files/default/replication-bin/replicate-changesets +++ b/cookbooks/planet/files/default/replication-bin/replicate-changesets @@ -277,7 +277,7 @@ class Replicator move_tmp_files_into_place! fl.flock(File::LOCK_UN) - rescue + rescue StandardError STDERR.puts("Error! Couldn't update state.") fl.flock(File::LOCK_UN) raise diff --git a/cookbooks/wordpress/providers/site.rb b/cookbooks/wordpress/providers/site.rb index 4b389a4be..79f96b5d2 100644 --- a/cookbooks/wordpress/providers/site.rb +++ b/cookbooks/wordpress/providers/site.rb @@ -155,14 +155,14 @@ action :create do interpreter "php" cwd site_directory user "wordpress" - code <<-EOS + code <<-WP_FAIL2BAN - EOS + WP_FAIL2BAN subscribes :run, "wordpress_plugin[wp-fail2ban]" end end diff --git a/roles/paulla.rb b/roles/paulla.rb index 3d542df25..b84b86c96 100644 --- a/roles/paulla.rb +++ b/roles/paulla.rb @@ -1,5 +1,3 @@ -# coding: utf-8 - name "paulla" description "Role applied to all servers at PauLLA" diff --git a/roles/teleservice.rb b/roles/teleservice.rb index 6bb0b45da..ea2dece10 100644 --- a/roles/teleservice.rb +++ b/roles/teleservice.rb @@ -1,5 +1,3 @@ -# coding: utf-8 - name "teleservice" description "Role applied to all servers at Teleservice" -- 2.39.5