]> git.openstreetmap.org Git - rails.git/commitdiff
Fix rubocop Style/SoleNestedConditional warnings
authorTom Hughes <tom@compton.nu>
Wed, 2 Sep 2020 17:54:55 +0000 (18:54 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 2 Sep 2020 17:54:55 +0000 (18:54 +0100)
.rubocop_todo.yml
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

index 2d638e1e144c35e27393fdf5e30873c1da1c5308..61109ddc9b7320ae231dd71692ff57edd3685265 100644 (file)
@@ -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:
index 5e0a7ee708f532d4d98b0e97ea32f425c8bd1587..058c442d50999aef995831cc9598bb9e8906c8b9 100644 (file)
@@ -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
 
index e239da16160081552a18b453f7a2fc887d445a17..991925102c4fa9813ca4bccdae1e2f2a7f180df2 100644 (file)
@@ -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
index ee5b5bcf3b4463815421cf9c4201fff0bcacf620..94d340731ada18edf952ccaf887b3fe1396af246 100644 (file)
@@ -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
index 333ad0e05f76a327fb53e72fa168ea267b6ccea2..3032c109eb03c1bae7bbc6fcc16b3546c055dd73 100644 (file)
@@ -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
index 53e730afc8398f1ad2de5adc571b7d76d3a88d85..c59c1a90159fae9990d0fc499ed0437427d1f405 100644 (file)
@@ -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