From 77f9aec772eb4bb1a413e310dd30a8532dccab5c Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 31 Jul 2020 22:45:53 +0100 Subject: [PATCH] Fix some rubocop todos --- .rubocop_todo.yml | 14 -------------- app/controllers/api/ways_controller.rb | 8 ++------ app/helpers/browse_tags_helper.rb | 2 +- app/validators/characters_validator.rb | 4 ++-- app/validators/whitespace_validator.rb | 4 ++-- 5 files changed, 7 insertions(+), 25 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 060da18d4..f04b39c25 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/app/controllers/api/ways_controller.rb b/app/controllers/api/ways_controller.rb index 3b58f208b..a0feabff3 100644 --- a/app/controllers/api/ways_controller.rb +++ b/app/controllers/api/ways_controller.rb @@ -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) diff --git a/app/helpers/browse_tags_helper.rb b/app/helpers/browse_tags_helper.rb index 5acbba9c7..3f720d0e9 100644 --- a/app/helpers/browse_tags_helper.rb +++ b/app/helpers/browse_tags_helper.rb @@ -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 diff --git a/app/validators/characters_validator.rb b/app/validators/characters_validator.rb index ee5b1206a..ee5b5bcf3 100644 --- a/app/validators/characters_validator.rb +++ b/app/validators/characters_validator.rb @@ -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 diff --git a/app/validators/whitespace_validator.rb b/app/validators/whitespace_validator.rb index d177df92a..333ad0e05 100644 --- a/app/validators/whitespace_validator.rb +++ b/app/validators/whitespace_validator.rb @@ -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 -- 2.45.1