From: Tom Hughes Date: Mon, 31 Oct 2016 21:24:10 +0000 (+0000) Subject: Fix rubocop warnings X-Git-Tag: live~3681 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/282ff4936cc1831fcbe9de0dd2d30c6bccd62b19 Fix rubocop warnings --- diff --git a/app/helpers/user_roles_helper.rb b/app/helpers/user_roles_helper.rb index b6961cd8b..7093a96b2 100644 --- a/app/helpers/user_roles_helper.rb +++ b/app/helpers/user_roles_helper.rb @@ -1,6 +1,8 @@ module UserRolesHelper def role_icons(user) - UserRole::ALL_ROLES.reduce("".html_safe) { |a, e| a + " " + role_icon(user, e) } + UserRole::ALL_ROLES.reduce("".html_safe) do |acc, elem| + acc + " " + role_icon(user, elem) + end end def role_icon(user, role) diff --git a/app/models/relation.rb b/app/models/relation.rb index ed37d159a..e5e4ec894 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -370,7 +370,7 @@ class Relation < ActiveRecord::Base # materially change the rest of the relation. any_relations = changed_members.collect { |_id, type| type == "relation" } - .inject(false) { |a, e| a || e } + .inject(false) { |acc, elem| acc || elem } update_members = if tags_changed || any_relations # add all non-relation bounding boxes to the changeset diff --git a/app/models/user.rb b/app/models/user.rb index 2cdb94046..e6d7a4e46 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -216,8 +216,8 @@ class User < ActiveRecord::Base def spam_score changeset_score = changesets.size * 50 trace_score = traces.size * 50 - diary_entry_score = diary_entries.inject(0) { |a, e| a + e.body.spam_score } - diary_comment_score = diary_comments.inject(0) { |a, e| a + e.body.spam_score } + diary_entry_score = diary_entries.inject(0) { |acc, elem| acc + elem.body.spam_score } + diary_comment_score = diary_comments.inject(0) { |acc, elem| acc + elem.body.spam_score } score = description.spam_score / 4.0 score += diary_entries.where("created_at > ?", 1.day.ago).count * 10 diff --git a/config/initializers/konacha.rb b/config/initializers/konacha.rb index f97b19aaf..f0145f5e0 100644 --- a/config/initializers/konacha.rb +++ b/config/initializers/konacha.rb @@ -1,5 +1,7 @@ -Konacha.configure do |config| - require "capybara/poltergeist" - config.spec_dir = "test/javascripts" - config.driver = :poltergeist -end if defined?(Konacha) +if defined?(Konacha) + Konacha.configure do |config| + require "capybara/poltergeist" + config.spec_dir = "test/javascripts" + config.driver = :poltergeist + end +end diff --git a/lib/bounding_box.rb b/lib/bounding_box.rb index 9f6c3d9d5..11e831cfe 100644 --- a/lib/bounding_box.rb +++ b/lib/bounding_box.rb @@ -43,14 +43,22 @@ class BoundingBox # only try to expand the bbox if there is a value for every coordinate # which there will be from the previous line as long as array does not contain a nil if bbox.complete? - @min_lon = [-SCALED_LON_LIMIT, - bbox.min_lon + margin * (min_lon - max_lon)].max if bbox.min_lon < min_lon - @min_lat = [-SCALED_LAT_LIMIT, - bbox.min_lat + margin * (min_lat - max_lat)].max if bbox.min_lat < min_lat - @max_lon = [+SCALED_LON_LIMIT, - bbox.max_lon + margin * (max_lon - min_lon)].min if bbox.max_lon > max_lon - @max_lat = [+SCALED_LAT_LIMIT, - bbox.max_lat + margin * (max_lat - min_lat)].min if bbox.max_lat > max_lat + if bbox.min_lon < min_lon + @min_lon = [-SCALED_LON_LIMIT, + bbox.min_lon + margin * (min_lon - max_lon)].max + end + if bbox.min_lat < min_lat + @min_lat = [-SCALED_LAT_LIMIT, + bbox.min_lat + margin * (min_lat - max_lat)].max + end + if bbox.max_lon > max_lon + @max_lon = [+SCALED_LON_LIMIT, + bbox.max_lon + margin * (max_lon - min_lon)].min + end + if bbox.max_lat > max_lat + @max_lat = [+SCALED_LAT_LIMIT, + bbox.max_lat + margin * (max_lat - min_lat)].min + end end self end diff --git a/lib/classic_pagination/pagination.rb b/lib/classic_pagination/pagination.rb index 36653ee02..f12ff095f 100644 --- a/lib/classic_pagination/pagination.rb +++ b/lib/classic_pagination/pagination.rb @@ -93,9 +93,10 @@ module ActionController valid_options << :actions unless in_action unknown_option_keys = options.keys - valid_options - raise ActionController::ActionControllerError, - "Unknown options: #{unknown_option_keys.join(', ')}" unless - unknown_option_keys.empty? + unless unknown_option_keys.empty? + raise ActionController::ActionControllerError, + "Unknown options: #{unknown_option_keys.join(', ')}" + end options[:singular_name] ||= ActiveSupport::Inflector.singularize(collection_id.to_s) options[:class_name] ||= ActiveSupport::Inflector.camelize(options[:singular_name]) diff --git a/lib/diff_reader.rb b/lib/diff_reader.rb index c6e4780eb..c2e7f1839 100644 --- a/lib/diff_reader.rb +++ b/lib/diff_reader.rb @@ -85,8 +85,10 @@ class DiffReader def with_model with_element do |model_name, _model_attributes| model = MODELS[model_name] - raise OSM::APIBadUserInput.new("Unexpected element type #{model_name}, " + - "expected node, way or relation.") if model.nil? + if model.nil? + raise OSM::APIBadUserInput.new("Unexpected element type #{model_name}, " + + "expected node, way or relation.") + end # new in libxml-ruby >= 2, expand returns an element not associated # with a document. this means that there's no encoding parameter, # which means basically nothing works.