From 307adfed3045a1673b09bccce74acaaf530d3c9b Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 20 Oct 2016 21:56:11 +0100 Subject: [PATCH] Fix rubocop warnings --- .rubocop_todo.yml | 35 ++++++++++---------- cookbooks/accounts/recipes/default.rb | 4 +-- cookbooks/apache/providers/module.rb | 4 +-- cookbooks/chef/libraries/compare_versions.rb | 8 ++--- cookbooks/exim/recipes/default.rb | 4 +-- cookbooks/hardware/attributes/default.rb | 4 +-- cookbooks/hardware/recipes/default.rb | 8 ++--- cookbooks/imagery/resources/layer.rb | 4 +-- cookbooks/munin/recipes/default.rb | 4 +-- cookbooks/nodejs/recipes/default.rb | 4 +-- cookbooks/systemd/resources/service.rb | 6 ++-- cookbooks/tile/files/default/ruby/expire.rb | 12 ++----- cookbooks/tools/recipes/default.rb | 4 +-- 13 files changed, 36 insertions(+), 65 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 13b8fc9df..f5b756028 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,45 +1,47 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2015-08-18 22:54:59 +0100 using RuboCop version 0.33.0. +# on 2016-10-20 21:45:03 +0100 using RuboCop version 0.44.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -Lint/HandleExceptions: - Exclude: - - 'cookbooks/networking/definitions/firewall_rule.rb' - # Offense count: 22 Metrics/AbcSize: - Max: 66 + Max: 57 + +# Offense count: 27 +# Configuration parameters: CountComments. +Metrics/BlockLength: + Max: 356 # Offense count: 3 Metrics/CyclomaticComplexity: Max: 8 -# Offense count: 338 -# Configuration parameters: AllowURI, URISchemes. +# Offense count: 475 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives. +# URISchemes: http, https Metrics/LineLength: Max: 696 -# Offense count: 23 +# Offense count: 24 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 40 + Max: 24 # Offense count: 1 Metrics/PerceivedComplexity: Max: 9 -# Offense count: 14 +# Offense count: 13 Style/Documentation: Exclude: + - 'spec/**/*' + - 'test/**/*' - 'cookbooks/chef/libraries/compare_versions.rb' - 'cookbooks/chef/libraries/edit_file.rb' - 'cookbooks/chef/libraries/random_password.rb' - - 'cookbooks/chef/libraries/remote_directory.rb' - 'cookbooks/chef/libraries/subversion.rb' - 'cookbooks/hardware/libraries/sensors.rb' - 'cookbooks/munin/libraries/expand.rb' @@ -50,13 +52,12 @@ Style/Documentation: - 'cookbooks/tile/files/default/ruby/expire.rb' - 'cookbooks/wordpress/libraries/wordpress.rb' -# Offense count: 19 +# Offense count: 14 # Cop supports --auto-correct. # Configuration parameters: MaxLineLength. Style/IfUnlessModifier: Exclude: - 'cookbooks/accounts/recipes/default.rb' - - 'cookbooks/apache/providers/conf.rb' - 'cookbooks/apache/providers/module.rb' - 'cookbooks/chef/libraries/compare_versions.rb' - 'cookbooks/exim/recipes/default.rb' @@ -65,11 +66,9 @@ Style/IfUnlessModifier: - 'cookbooks/munin/recipes/default.rb' - 'cookbooks/nodejs/recipes/default.rb' - 'cookbooks/tile/files/default/ruby/expire.rb' - - 'cookbooks/tile/recipes/default.rb' - 'cookbooks/tools/recipes/default.rb' - - 'cookbooks/web/recipes/cgimap.rb' -# Offense count: 28 +# Offense count: 37 # Cop supports --auto-correct. Style/NumericLiterals: MinDigits: 11 diff --git a/cookbooks/accounts/recipes/default.rb b/cookbooks/accounts/recipes/default.rb index e043d9e3e..d6c7806fd 100644 --- a/cookbooks/accounts/recipes/default.rb +++ b/cookbooks/accounts/recipes/default.rb @@ -78,9 +78,7 @@ search(:accounts, "*:*").each do |account| end end - if details[:status] == "administrator" - administrators.push(name.to_s) - end + administrators.push(name.to_s) if details[:status] == "administrator" else user name.to_s do action :remove diff --git a/cookbooks/apache/providers/module.rb b/cookbooks/apache/providers/module.rb index 252b5e816..d3f069b7f 100644 --- a/cookbooks/apache/providers/module.rb +++ b/cookbooks/apache/providers/module.rb @@ -24,9 +24,7 @@ end use_inline_resources action :install do - unless installed? - package package_name - end + package package_name unless installed? if new_resource.conf # ~FC023 template available_name("conf") do diff --git a/cookbooks/chef/libraries/compare_versions.rb b/cookbooks/chef/libraries/compare_versions.rb index cf6ab1ea2..45653935f 100644 --- a/cookbooks/chef/libraries/compare_versions.rb +++ b/cookbooks/chef/libraries/compare_versions.rb @@ -1,13 +1,9 @@ class Chef class Util def self.compare_versions(a, b) - if a.is_a?(String) - a = a.split(".").map(&:to_i) - end + a = a.split(".").map(&:to_i) if a.is_a?(String) - if b.is_a?(String) - b = b.split(".").map(&:to_i) - end + b = b.split(".").map(&:to_i) if b.is_a?(String) a <=> b end diff --git a/cookbooks/exim/recipes/default.rb b/cookbooks/exim/recipes/default.rb index 4e7c4638b..2aabb40ff 100644 --- a/cookbooks/exim/recipes/default.rb +++ b/cookbooks/exim/recipes/default.rb @@ -23,9 +23,7 @@ package "exim4" package "openssl" package "ssl-cert" -if File.exist?("/var/run/clamav/clamd.ctl") - package "exim4-daemon-heavy" -end +package "exim4-daemon-heavy" if File.exist?("/var/run/clamav/clamd.ctl") group "ssl-cert" do action :modify diff --git a/cookbooks/hardware/attributes/default.rb b/cookbooks/hardware/attributes/default.rb index f77967a20..ce7aae863 100644 --- a/cookbooks/hardware/attributes/default.rb +++ b/cookbooks/hardware/attributes/default.rb @@ -30,9 +30,7 @@ end if node[:kernel] && node[:kernel][:modules] raidmods = node[:kernel][:modules].keys & %w(cciss hpsa mptsas mpt2sas mpt3sas megaraid_mm megaraid_sas aacraid) - unless raidmods.empty? - default[:apt][:sources] |= ["hwraid"] - end + default[:apt][:sources] |= ["hwraid"] unless raidmods.empty? end if node[:kernel][:modules].include?("ipmi_si") diff --git a/cookbooks/hardware/recipes/default.rb b/cookbooks/hardware/recipes/default.rb index 7d326d68b..5d1757b46 100644 --- a/cookbooks/hardware/recipes/default.rb +++ b/cookbooks/hardware/recipes/default.rb @@ -31,9 +31,7 @@ end case node[:cpu][:"0"][:vendor_id] when "AuthenticAMD" - if node[:lsb][:release].to_f >= 14.04 - package "amd64-microcode" - end + package "amd64-microcode" if node[:lsb][:release].to_f >= 14.04 end if node[:dmi] && node[:dmi][:system] @@ -184,9 +182,7 @@ service "haveged" do action [:enable, :start] end -if node[:kernel][:modules].include?("ipmi_si") - package "ipmitool" -end +package "ipmitool" if node[:kernel][:modules].include?("ipmi_si") if node[:lsb][:release].to_f >= 12.10 package "irqbalance" diff --git a/cookbooks/imagery/resources/layer.rb b/cookbooks/imagery/resources/layer.rb index 60712a635..aee757e6e 100644 --- a/cookbooks/imagery/resources/layer.rb +++ b/cookbooks/imagery/resources/layer.rb @@ -34,9 +34,9 @@ property :background_colour, String property :resample, String, :default => "average" property :imagemode, String property :extension, String, :default => "png" -property :max_zoom, Fixnum, :default => 18 +property :max_zoom, Integer, :default => 18 property :url_aliases, [String, Array], :default => [] -property :revision, Fixnum, :default => 0 +property :revision, Integer, :default => 0 property :overlay, [TrueClass, FalseClass], :default => false property :default_layer, [TrueClass, FalseClass], :default => false diff --git a/cookbooks/munin/recipes/default.rb b/cookbooks/munin/recipes/default.rb index fb9807931..3b41eb8e9 100644 --- a/cookbooks/munin/recipes/default.rb +++ b/cookbooks/munin/recipes/default.rb @@ -291,9 +291,7 @@ Dir.glob("/sys/class/hwmon/hwmon*").each do |hwmon| sensors_volt = true unless Dir.glob("#{hwmon}/in*_input").empty? end -if sensors_fan || sensors_temp || sensors_volt - package "lm-sensors" -end +package "lm-sensors" if sensors_fan || sensors_temp || sensors_volt if sensors_fan munin_plugin "sensors_fan" do diff --git a/cookbooks/nodejs/recipes/default.rb b/cookbooks/nodejs/recipes/default.rb index 2fa43d631..f6f054fe0 100644 --- a/cookbooks/nodejs/recipes/default.rb +++ b/cookbooks/nodejs/recipes/default.rb @@ -22,6 +22,4 @@ package "npm" package "g++" package "make" -if node[:lsb][:release].to_f >= 14.04 - package "nodejs-legacy" -end +package "nodejs-legacy" if node[:lsb][:release].to_f >= 14.04 diff --git a/cookbooks/systemd/resources/service.rb b/cookbooks/systemd/resources/service.rb index df62481a5..943ce031b 100644 --- a/cookbooks/systemd/resources/service.rb +++ b/cookbooks/systemd/resources/service.rb @@ -26,7 +26,7 @@ property :wants, [String, Array] property :type, String, :default => "simple", :is => %w(simple forking oneshot dbus notify idle) -property :limit_nofile, Fixnum +property :limit_nofile, Integer property :environment, Hash, :default => {} property :environment_file, [String, Hash] property :user, String @@ -37,7 +37,7 @@ property :exec_start_post, String property :exec_stop, String property :exec_reload, String property :runtime_directory, String -property :runtime_directory_mode, Fixnum +property :runtime_directory_mode, Integer property :standard_input, String, :is => %w(null tty tty-force tty-fail socket) property :standard_output, String, @@ -51,7 +51,7 @@ property :private_devices, [TrueClass, FalseClass] property :private_network, [TrueClass, FalseClass] property :protect_system, [TrueClass, FalseClass, String] property :protect_home, [TrueClass, FalseClass, String] -property :timeout_sec, Fixnum +property :timeout_sec, Integer property :pid_file, String action :create do diff --git a/cookbooks/tile/files/default/ruby/expire.rb b/cookbooks/tile/files/default/ruby/expire.rb index 8a212aa92..3d693ad5b 100755 --- a/cookbooks/tile/files/default/ruby/expire.rb +++ b/cookbooks/tile/files/default/ruby/expire.rb @@ -103,12 +103,8 @@ module Expire # added, deleted or modified - the tile will need updating anyway. doc.find("//node").each do |node| lat = node["lat"].to_f - if lat < -85 - lat = -85 - end - if lat > 85 - lat = 85 - end + lat = -85 if lat < -85 + lat = 85 if lat > 85 point = Proj4::Point.new(Math::PI * node["lon"].to_f / 180, Math::PI * lat / 180) nodes[node["id"].to_i] = tile_from_latlon(point, max_zoom) @@ -186,9 +182,7 @@ module Expire lon, lat = @cache.sysread(8).unpack("ll") - if lon != -2147483648 && lat != -2147483648 - node = Node.new(lon, lat) - end + node = Node.new(lon, lat) if lon != -2147483648 && lat != -2147483648 end node diff --git a/cookbooks/tools/recipes/default.rb b/cookbooks/tools/recipes/default.rb index d58523af1..b751792d2 100644 --- a/cookbooks/tools/recipes/default.rb +++ b/cookbooks/tools/recipes/default.rb @@ -35,9 +35,7 @@ package "sysv-rc-conf" package "iotop" package "lvm2" -if node[:lsb][:release].to_f <= 11.04 - package "lslk" -end +package "lslk" if node[:lsb][:release].to_f <= 11.04 package "rsyslog" -- 2.43.2