From: Tom Hughes Date: Sat, 14 Feb 2015 13:07:17 +0000 (+0000) Subject: Rubocop cleanups X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/9bca5f05185dde08efcf2d5f1a2bf66c8cdc9f00?ds=sidebyside;hp=db1258aa91142e37e5dcded368a25ec2c937f473 Rubocop cleanups --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 155b7d135..07185ec2c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,11 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 15 -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Enabled: false - # Offense count: 2 Lint/HandleExceptions: Enabled: false @@ -36,12 +31,6 @@ Metrics/MethodLength: Metrics/PerceivedComplexity: Max: 9 -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles. -Style/AccessModifierIndentation: - EnforcedStyle: outdent - # Offense count: 14 Style/Documentation: Enabled: false diff --git a/cookbooks/hardware/libraries/sensors.rb b/cookbooks/hardware/libraries/sensors.rb index 0a55eae39..6508ffb7d 100644 --- a/cookbooks/hardware/libraries/sensors.rb +++ b/cookbooks/hardware/libraries/sensors.rb @@ -8,18 +8,11 @@ class Chef if attributes[:ignore] results << "ignore #{sensor}" else - if label = attributes[:label] - resuls << "label #{sensor} \"#{label}\"" - end - - if compute = attributes[:compute] - resuls << "compute #{sensor} #{compute}" - end + results << "label #{sensor} \"#{attributes[:label]}\"" if attributes[:label] + results << "compute #{sensor} #{attributes[:compute]}" if attributes[:compute] attribute_names.each do |name| - if value = attributes[name] - results << "set #{sensor}_#{name} #{value}" - end + results << "set #{sensor}_#{name} #{attributes[name]}" if attributes[name] end end end diff --git a/cookbooks/mysql/libraries/mysql.rb b/cookbooks/mysql/libraries/mysql.rb index 769df807e..91eb6f9d1 100644 --- a/cookbooks/mysql/libraries/mysql.rb +++ b/cookbooks/mysql/libraries/mysql.rb @@ -104,7 +104,9 @@ class Chef end query("SELECT * FROM db").each do |record| - next unless database = @databases[record[:db]] + database = @databases[record[:db]] + + next unless database user = "'#{record[:user]}'@'#{record[:host]}'" diff --git a/cookbooks/mysql/providers/database.rb b/cookbooks/mysql/providers/database.rb index 647925f26..6e488ce47 100644 --- a/cookbooks/mysql/providers/database.rb +++ b/cookbooks/mysql/providers/database.rb @@ -22,7 +22,7 @@ def load_current_resource @current_resource = Chef::Resource::MysqlDatabase.new(new_resource.name) @current_resource.database(new_resource.database) - if mysql_database = @mysql.databases[@current_resource.database] + if (mysql_database = @mysql.databases[@current_resource.database]) @current_resource.permissions(mysql_database[:permissions]) end @current_resource diff --git a/cookbooks/mysql/providers/user.rb b/cookbooks/mysql/providers/user.rb index 05fd01eb8..a966679af 100644 --- a/cookbooks/mysql/providers/user.rb +++ b/cookbooks/mysql/providers/user.rb @@ -22,7 +22,7 @@ def load_current_resource @current_resource = Chef::Resource::MysqlUser.new(new_resource.name) @current_resource.user(new_resource.user) - if mysql_user = @mysql.users[@current_resource.user] + if (mysql_user = @mysql.users[@current_resource.user]) Chef::MySQL::USER_PRIVILEGES.each do |privilege| @current_resource.send(privilege, mysql_user[privilege]) end diff --git a/cookbooks/nodejs/providers/package.rb b/cookbooks/nodejs/providers/package.rb index 5e3ca0684..3a3304063 100644 --- a/cookbooks/nodejs/providers/package.rb +++ b/cookbooks/nodejs/providers/package.rb @@ -27,7 +27,7 @@ def load_current_resource @current_resource = Chef::Resource::NodejsPackage.new(new_resource.name) @current_resource.package_name(new_resource.package_name) - if package = @packages[@current_resource.package_name] + if (package = @packages[@current_resource.package_name]) @current_resource.version(package["version"]) end @current_resource diff --git a/cookbooks/openvpn/recipes/default.rb b/cookbooks/openvpn/recipes/default.rb index 9b01bfdb9..9b96183ee 100644 --- a/cookbooks/openvpn/recipes/default.rb +++ b/cookbooks/openvpn/recipes/default.rb @@ -26,7 +26,9 @@ service "openvpn" do end node[:openvpn][:tunnels].each do |name, details| - if peer = search(:node, "fqdn:#{details[:peer][:host]}").first + peer = search(:node, "fqdn:#{details[:peer][:host]}").first + + if peer if peer[:openvpn] && !details[:peer][:address] node.default[:openvpn][:tunnels][name][:peer][:address] = peer[:openvpn][:address] end diff --git a/cookbooks/postgresql/libraries/postgresql.rb b/cookbooks/postgresql/libraries/postgresql.rb index 05bf158f2..0b405e89b 100644 --- a/cookbooks/postgresql/libraries/postgresql.rb +++ b/cookbooks/postgresql/libraries/postgresql.rb @@ -105,7 +105,7 @@ class Chef end end - private + private def parse_acl(acl) acl.sub(/^\{(.*)\}$/, "\\1").split(",").each_with_object({}) do |entry, permissions| diff --git a/cookbooks/postgresql/providers/database.rb b/cookbooks/postgresql/providers/database.rb index c2b000d13..31704314b 100644 --- a/cookbooks/postgresql/providers/database.rb +++ b/cookbooks/postgresql/providers/database.rb @@ -23,7 +23,7 @@ def load_current_resource @current_resource = Chef::Resource::PostgresqlDatabase.new(new_resource.name) @current_resource.database(new_resource.database) @current_resource.cluster(new_resource.cluster) - if pg_database = @pg.databases[@current_resource.database] + if (pg_database = @pg.databases[@current_resource.database]) @current_resource.owner(pg_database[:owner]) @current_resource.encoding(pg_database[:encoding]) @current_resource.encoding(pg_database[:collate]) diff --git a/cookbooks/postgresql/providers/table.rb b/cookbooks/postgresql/providers/table.rb index b1dc85f7b..f162347dd 100644 --- a/cookbooks/postgresql/providers/table.rb +++ b/cookbooks/postgresql/providers/table.rb @@ -26,7 +26,7 @@ def load_current_resource @current_resource.cluster(new_resource.cluster) @current_resource.database(new_resource.database) @current_resource.schema(new_resource.schema) - if pg_table = @tables[@name] + if (pg_table = @tables[@name]) @current_resource.owner(pg_table[:owner]) @current_resource.permissions(pg_table[:permissions]) end diff --git a/cookbooks/postgresql/providers/user.rb b/cookbooks/postgresql/providers/user.rb index 791368255..4f21b4d29 100644 --- a/cookbooks/postgresql/providers/user.rb +++ b/cookbooks/postgresql/providers/user.rb @@ -23,7 +23,7 @@ def load_current_resource @current_resource = Chef::Resource::PostgresqlUser.new(new_resource.name) @current_resource.user(new_resource.user) @current_resource.cluster(new_resource.cluster) - if pg_user = @pg.users[@current_resource.user] + if (pg_user = @pg.users[@current_resource.user]) @current_resource.superuser(pg_user[:superuser]) @current_resource.createdb(pg_user[:createdb]) @current_resource.createrole(pg_user[:createrole]) diff --git a/cookbooks/tile/files/default/ruby/expire.rb b/cookbooks/tile/files/default/ruby/expire.rb index 7757386c5..f99d646e0 100755 --- a/cookbooks/tile/files/default/ruby/expire.rb +++ b/cookbooks/tile/files/default/ruby/expire.rb @@ -131,7 +131,7 @@ module Expire # this is a node referenced but not added, modified or deleted, so it should # still be in the node cache. - if entry = node_cache[node_id] + if (entry = node_cache[node_id]) point = Proj4::Point.new(entry.lon, entry.lat) nodes[node_id] = tile_from_merc(point, max_zoom) end diff --git a/cookbooks/wordpress/definitions/wordpress_plugin.rb b/cookbooks/wordpress/definitions/wordpress_plugin.rb index b165eb2ba..7be7a0038 100644 --- a/cookbooks/wordpress/definitions/wordpress_plugin.rb +++ b/cookbooks/wordpress/definitions/wordpress_plugin.rb @@ -36,7 +36,9 @@ define :wordpress_plugin, :action => [:enable] do files_mode 0755 end else - unless repository = params[:repository] + repository = params[:repository] + + unless params version = params[:version] || Chef::Wordpress.current_plugin_version(name) if version =~ /trunk/ diff --git a/cookbooks/wordpress/definitions/wordpress_theme.rb b/cookbooks/wordpress/definitions/wordpress_theme.rb index 91ca9de3d..0720a8f1f 100644 --- a/cookbooks/wordpress/definitions/wordpress_theme.rb +++ b/cookbooks/wordpress/definitions/wordpress_theme.rb @@ -36,7 +36,9 @@ define :wordpress_theme, :action => [:enable] do files_mode 0644 end else - unless repository = params[:repository] + repository = params[:repository] + + unless repository version = params[:version] || node[:wordpress][:plugins][name][:version] repository = "http://themes.svn.wordpress.org/#{name}/#{version}" end diff --git a/cookbooks/wordpress/libraries/wordpress.rb b/cookbooks/wordpress/libraries/wordpress.rb index f8046aaaa..06a375fe9 100644 --- a/cookbooks/wordpress/libraries/wordpress.rb +++ b/cookbooks/wordpress/libraries/wordpress.rb @@ -19,7 +19,7 @@ class Chef end end - private + private def self.core_version_check api_get("http://api.wordpress.org/core/version-check/1.6")