]> git.openstreetmap.org Git - rails.git/commitdiff
Fix some rubocop todos
authorTom Hughes <tom@compton.nu>
Fri, 31 Jul 2020 21:45:53 +0000 (22:45 +0100)
committerTom Hughes <tom@compton.nu>
Fri, 31 Jul 2020 21:45:53 +0000 (22:45 +0100)
.rubocop_todo.yml
app/controllers/api/ways_controller.rb
app/helpers/browse_tags_helper.rb
app/validators/characters_validator.rb
app/validators/whitespace_validator.rb

index 060da18d4e18c2cb4d347e3d4413fa9a54b2d008..f04b39c2583d5c20f024c799a867c6d8910076ec 100644 (file)
@@ -98,14 +98,6 @@ Naming/PredicateName:
     - 'app/models/user.rb'
     - 'lib/classic_pagination/pagination.rb'
 
-# Offense count: 5
-# Cop supports --auto-correct.
-Performance/RegexpMatch:
-  Exclude:
-    - 'app/helpers/browse_tags_helper.rb'
-    - 'app/validators/characters_validator.rb'
-    - 'app/validators/whitespace_validator.rb'
-
 # Offense count: 5
 # Configuration parameters: Database, Include.
 # SupportedDatabases: mysql, postgresql
@@ -190,12 +182,6 @@ Style/FormatStringToken:
 Style/FrozenStringLiteralComment:
   Enabled: false
 
-# Offense count: 2
-# Cop supports --auto-correct.
-Style/IfUnlessModifier:
-  Exclude:
-    - 'app/controllers/api/ways_controller.rb'
-
 # Offense count: 78
 # Cop supports --auto-correct.
 # Configuration parameters: Strict.
index 3b58f208b14e729a696a0f7e2e0ba0cd6ada631e..a0feabff3a82a504b9a31f5dfd397601e99d8e27 100644 (file)
@@ -43,9 +43,7 @@ module Api
       way = Way.find(params[:id])
       new_way = Way.from_xml(request.raw_post)
 
-      unless new_way && new_way.id == way.id
-        raise OSM::APIBadUserInput, "The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})"
-      end
+      raise OSM::APIBadUserInput, "The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})" unless new_way && new_way.id == way.id
 
       way.update_from(new_way, current_user)
       render :plain => way.version.to_s
@@ -90,9 +88,7 @@ module Api
     end
 
     def index
-      unless params["ways"]
-        raise OSM::APIBadUserInput, "The parameter ways is required, and must be of the form ways=id[,id[,id...]]"
-      end
+      raise OSM::APIBadUserInput, "The parameter ways is required, and must be of the form ways=id[,id[,id...]]" unless params["ways"]
 
       ids = params["ways"].split(",").collect(&:to_i)
 
index 5acbba9c7eaeed49df17baa9af3f3f5e2fe38ea9..3f720d0e9e1a486175dcf8de955ff46934a9a63b 100644 (file)
@@ -58,7 +58,7 @@ module BrowseTagsHelper
 
   def wikipedia_link(key, value)
     # Some k/v's are wikipedia=http://en.wikipedia.org/wiki/Full%20URL
-    return nil if value =~ %r{^https?://}
+    return nil if %r{^https?://}.match?(value)
 
     if key == "wikipedia"
       # This regex should match Wikipedia language codes, everything
index ee5b1206a08354c3406e2e383c331fe1089c23bf..ee5b5bcf3b4463815421cf9c4201fff0bcacf620 100644 (file)
@@ -3,10 +3,10 @@ class CharactersValidator < ActiveModel::EachValidator
   INVALID_URL_CHARS = "/;.,?%#".freeze
 
   def validate_each(record, attribute, value)
-    record.errors[attribute] << (options[:message] || I18n.t("validations.invalid_characters")) if value =~ /[#{INVALID_CHARS}]/
+    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 value =~ /[#{INVALID_URL_CHARS}]/
+      record.errors[attribute] << (options[:message] || I18n.t("validations.url_characters", :characters => INVALID_URL_CHARS)) if /[#{INVALID_URL_CHARS}]/.match?(value)
     end
   end
 end
index d177df92a6c5979f715a705aae27e63ffa58aa3f..333ad0e05f76a327fb53e72fa168ea267b6ccea2 100644 (file)
@@ -1,11 +1,11 @@
 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 value =~ /\A\s/
+      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 value =~ /\s\z/
+      record.errors[attribute] << (options[:message] || I18n.t("validations.trailing_whitespace")) if /\s\z/.match?(value)
     end
   end
 end