]> git.openstreetmap.org Git - rails.git/commitdiff
Fix Lint/DuplicateBranch rubocop warnings
authorTom Hughes <tom@compton.nu>
Tue, 8 Mar 2022 18:51:39 +0000 (18:51 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 8 Mar 2022 19:05:37 +0000 (19:05 +0000)
.rubocop_todo.yml
app/controllers/api_controller.rb
app/controllers/diary_entries_controller.rb
app/controllers/geocoder_controller.rb
app/helpers/browse_tags_helper.rb

index 95e3be8febbabc95db4766080f68b8722b857ec1..64781f9192182e6cf25894c52ef6e79dfba67dfb 100644 (file)
@@ -54,15 +54,6 @@ Lint/AssignmentInCondition:
     - 'lib/osm.rb'
     - 'script/deliver-message'
 
-# Offense count: 7
-# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
-Lint/DuplicateBranch:
-  Exclude:
-    - 'app/controllers/api_controller.rb'
-    - 'app/controllers/diary_entries_controller.rb'
-    - 'app/controllers/geocoder_controller.rb'
-    - 'app/helpers/browse_tags_helper.rb'
-
 # Offense count: 665
 # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
 Metrics/AbcSize:
index a138976409bba94bb259fbc1caac61935aa1f325..2d8d51dd8507719f653228b39e358a6c86b6e72c 100644 (file)
@@ -31,9 +31,8 @@ class ApiController < ApplicationController
         # as XML for backwards compatibility - all other formats are discarded
         # which will result in a 406 Not Acceptable response being sent
         formats = mimetypes.map do |mime|
-          if mime.symbol == :xml then :xml
+          if mime.symbol == :xml || mime == "*/*" then :xml
           elsif mime.symbol == :json then :json
-          elsif mime == "*/*" then :xml
           end
         end
       else
index 312e1e54caf3464649fc52e71ff34e5a8fec32f4..467c4a38f280db468be0b611d6c336eee83eedd8 100644 (file)
@@ -60,9 +60,8 @@ class DiaryEntriesController < ApplicationController
     @title = t "diary_entries.edit.title"
     @diary_entry = DiaryEntry.find(params[:id])
 
-    if current_user != @diary_entry.user
-      redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
-    elsif params[:diary_entry] && @diary_entry.update(entry_params)
+    if current_user != @diary_entry.user ||
+       (params[:diary_entry] && @diary_entry.update(entry_params))
       redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
     else
       set_map_location
index 8d651fe0f1345b27cbaeff18044e19164d99a992..7417cab762fdcdbbe3852d2a96cd73b3b973707e 100644 (file)
@@ -18,9 +18,8 @@ class GeocoderController < ApplicationController
       @sources.push "geonames_reverse" if Settings.key?(:geonames_username)
     elsif @params[:query]
       case @params[:query]
-      when /^\d{5}(-\d{4})?$/
-        @sources.push "osm_nominatim"
-      when /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
+      when /^\d{5}(-\d{4})?$/,
+           /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
         @sources.push "osm_nominatim"
       when /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i
         @sources.push "ca_postcode"
@@ -291,19 +290,16 @@ class GeocoderController < ApplicationController
     if query = params[:query]
       query.strip!
 
-      if latlon = query.match(/^([NS])\s*(\d{1,3}(\.\d*)?)\W*([EW])\s*(\d{1,3}(\.\d*)?)$/).try(:captures) # [NSEW] decimal degrees
-        params.merge!(nsew_to_decdeg(latlon)).delete(:query)
-      elsif latlon = query.match(/^(\d{1,3}(\.\d*)?)\s*([NS])\W*(\d{1,3}(\.\d*)?)\s*([EW])$/).try(:captures) # decimal degrees [NSEW]
+      if latlon = query.match(/^([NS])\s*(\d{1,3}(\.\d*)?)\W*([EW])\s*(\d{1,3}(\.\d*)?)$/).try(:captures) || # [NSEW] decimal degrees
+                  query.match(/^(\d{1,3}(\.\d*)?)\s*([NS])\W*(\d{1,3}(\.\d*)?)\s*([EW])$/).try(:captures)    # decimal degrees [NSEW]
         params.merge!(nsew_to_decdeg(latlon)).delete(:query)
 
-      elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\W*([EW])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?$/).try(:captures) # [NSEW] degrees, decimal minutes
-        params.merge!(ddm_to_decdeg(latlon)).delete(:query)
-      elsif latlon = query.match(/^(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([NS])\W*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW]
+      elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\W*([EW])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?$/).try(:captures) || # [NSEW] degrees, decimal minutes
+                     query.match(/^(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([NS])\W*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([EW])$/).try(:captures)    # degrees, decimal minutes [NSEW]
         params.merge!(ddm_to_decdeg(latlon)).delete(:query)
 
-      elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds
-        params.merge!(dms_to_decdeg(latlon)).delete(:query)
-      elsif latlon = query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW]
+      elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?$/).try(:captures) || # [NSEW] degrees, minutes, decimal seconds
+                     query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([EW])$/).try(:captures)    # degrees, minutes, decimal seconds [NSEW]
         params.merge!(dms_to_decdeg(latlon)).delete(:query)
 
       elsif latlon = query.match(/^([+-]?\d+(\.\d*)?)(?:\s+|\s*,\s*)([+-]?\d+(\.\d*)?)$/)
index d96bbef64b349d96f8582988e1bf2d6393889000..e7562081dfd0415b2684ec0c0516607b11582a77 100644 (file)
@@ -47,11 +47,10 @@ module BrowseTagsHelper
     # the correct page.
     lookup_us = lookup.tr(" ", "_")
 
-    if page = WIKI_PAGES.dig(locale, type, lookup_us)
-      url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
-    elsif page = WIKI_PAGES.dig("en", type, lookup_us)
-      url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
-    end
+    page = WIKI_PAGES.dig(locale, type, lookup_us) ||
+           WIKI_PAGES.dig("en", type, lookup_us)
+
+    url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}" if page
 
     url
   end