From: Tom Hughes Date: Wed, 2 Sep 2020 17:54:55 +0000 (+0100) Subject: Fix rubocop Style/SoleNestedConditional warnings X-Git-Tag: live~1941 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/c2af89c00e5bcb20981e737abb779ef65acd7b3e Fix rubocop Style/SoleNestedConditional warnings --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2d638e1e1..61109ddc9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -217,16 +217,6 @@ Style/OptionalBooleanParameter: - 'test/models/trace_test.rb' - 'test/models/tracetag_test.rb' -# Offense count: 6 -# Configuration parameters: AllowModifier. -Style/SoleNestedConditional: - Exclude: - - 'app/controllers/user_blocks_controller.rb' - - 'app/models/old_way.rb' - - 'app/validators/characters_validator.rb' - - 'app/validators/whitespace_validator.rb' - - 'lib/classic_pagination/pagination.rb' - # Offense count: 28 # Cop supports --auto-correct. Style/StringConcatenation: diff --git a/app/controllers/user_blocks_controller.rb b/app/controllers/user_blocks_controller.rb index 5e0a7ee70..058c442d5 100644 --- a/app/controllers/user_blocks_controller.rb +++ b/app/controllers/user_blocks_controller.rb @@ -79,11 +79,9 @@ class UserBlocksController < ApplicationController ## # revokes the block, setting the end_time to now def revoke - if params[:confirm] - if @user_block.revoke! current_user - flash[:notice] = t ".flash" - redirect_to(@user_block) - end + if params[:confirm] && @user_block.revoke!(current_user) + flash[:notice] = t ".flash" + redirect_to(@user_block) end end diff --git a/app/models/old_way.rb b/app/models/old_way.rb index e239da161..991925102 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -124,12 +124,10 @@ class OldWay < ApplicationRecord curnode = Node.find(n) id = n reuse = curnode.visible - if oldnode.lat != curnode.lat || oldnode.lon != curnode.lon || oldnode.tags != curnode.tags - # node has changed: if it's in other ways, give it a new id - if curnode.ways - [way_id] - id = -1 - reuse = false - end + # if node has changed and it's in other ways, give it a new id + if !curnode.ways.all?(way_id) && (oldnode.lat != curnode.lat || oldnode.lon != curnode.lon || oldnode.tags != curnode.tags) + id = -1 + reuse = false end points << [oldnode.lon, oldnode.lat, id, curnode.version, oldnode.tags_as_hash, reuse] end diff --git a/app/validators/characters_validator.rb b/app/validators/characters_validator.rb index ee5b5bcf3..94d340731 100644 --- a/app/validators/characters_validator.rb +++ b/app/validators/characters_validator.rb @@ -4,9 +4,6 @@ class CharactersValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) record.errors[attribute] << (options[:message] || I18n.t("validations.invalid_characters")) if /[#{INVALID_CHARS}]/.match?(value) - - if options[:url_safe] - record.errors[attribute] << (options[:message] || I18n.t("validations.url_characters", :characters => INVALID_URL_CHARS)) if /[#{INVALID_URL_CHARS}]/.match?(value) - end + record.errors[attribute] << (options[:message] || I18n.t("validations.url_characters", :characters => INVALID_URL_CHARS)) if options[:url_safe] && /[#{INVALID_URL_CHARS}]/.match?(value) end end diff --git a/app/validators/whitespace_validator.rb b/app/validators/whitespace_validator.rb index 333ad0e05..3032c109e 100644 --- a/app/validators/whitespace_validator.rb +++ b/app/validators/whitespace_validator.rb @@ -1,11 +1,6 @@ class WhitespaceValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - unless options.fetch(:leading, true) - record.errors[attribute] << (options[:message] || I18n.t("validations.leading_whitespace")) if /\A\s/.match?(value) - end - - unless options.fetch(:trailing, true) - record.errors[attribute] << (options[:message] || I18n.t("validations.trailing_whitespace")) if /\s\z/.match?(value) - end + record.errors[attribute] << (options[:message] || I18n.t("validations.leading_whitespace")) if !options.fetch(:leading, true) && /\A\s/.match?(value) + record.errors[attribute] << (options[:message] || I18n.t("validations.trailing_whitespace")) if !options.fetch(:trailing, true) && /\s\z/.match?(value) end end diff --git a/lib/classic_pagination/pagination.rb b/lib/classic_pagination/pagination.rb index 53e730afc..c59c1a901 100644 --- a/lib/classic_pagination/pagination.rb +++ b/lib/classic_pagination/pagination.rb @@ -240,10 +240,8 @@ module ActionController # object, its +number+ attribute is used as the value; if the page does # not belong to this Paginator, an ArgumentError is raised. def current_page=(page) - if page.is_a? Page - raise ArgumentError, "Page/Paginator mismatch" unless - page.paginator == self - end + raise ArgumentError, "Page/Paginator mismatch" if page.is_a?(Page) && page.paginator != self + page = page.to_i @current_page_number = has_page_number?(page) ? page : 1 end