]> git.openstreetmap.org Git - rails.git/commitdiff
Fix new rubocop warnings
authorTom Hughes <tom@compton.nu>
Mon, 11 Jan 2021 19:14:00 +0000 (19:14 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 11 Jan 2021 19:17:31 +0000 (19:17 +0000)
16 files changed:
.rubocop_todo.yml
app/controllers/api/changesets_controller.rb
app/controllers/geocoder_controller.rb
app/controllers/redactions_controller.rb
app/models/old_node.rb
app/models/old_relation.rb
app/models/old_way.rb
app/models/report.rb
app/views/users/_contact.html.erb
config/initializers/oauth.rb
config/initializers/strong_migrations.rb
script/statistics
test/controllers/api/tracepoints_controller_test.rb
test/controllers/geocoder_controller_test.rb
test/controllers/traces_controller_test.rb
test/factories/diary_entry_subscriptions.rb

index afce190d47e79432ecdb805d99b74dd1080ab8bc..9aea439cb01f5b435f6bec0a8dce68197b5af69a 100644 (file)
@@ -1,6 +1,6 @@
 # This configuration was generated by
 # `rubocop --auto-gen-config`
-# on 2020-09-02 06:16:56 UTC using RuboCop version 0.90.0.
+# on 2021-01-11 19:00:54 UTC using RuboCop version 1.8.1.
 # The point is for the user to remove these configuration records
 # one by one as the offenses are removed from the code base.
 # Note that changes in the inspected code, or installation of new
@@ -13,12 +13,12 @@ require:
   - rubocop-performance
   - rubocop-rails
 
-# Offense count: 568
+# Offense count: 544
 # Cop supports --auto-correct.
 # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
 # URISchemes: http, https
 Layout/LineLength:
-  Max: 250
+  Max: 248
 
 # Offense count: 36
 # Configuration parameters: AllowSafeAssignment.
@@ -39,14 +39,24 @@ Lint/AssignmentInCondition:
     - 'lib/osm.rb'
     - 'script/deliver-message'
 
-# Offense count: 682
-# Configuration parameters: IgnoredMethods.
+# Offense count: 8
+# 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'
+    - 'lib/password_hash.rb'
+
+# Offense count: 487
+# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
 Metrics/AbcSize:
   Max: 194
 
-# Offense count: 72
-# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
-# ExcludedMethods: refine
+# Offense count: 62
+# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
+# IgnoredMethods: refine
 Metrics/BlockLength:
   Max: 71
 
@@ -55,41 +65,40 @@ Metrics/BlockLength:
 Metrics/BlockNesting:
   Max: 5
 
-# Offense count: 25
+# Offense count: 24
 # Configuration parameters: CountComments, CountAsOne.
 Metrics/ClassLength:
-  Max: 644
+  Max: 582
 
-# Offense count: 68
+# Offense count: 52
 # Configuration parameters: IgnoredMethods.
 Metrics/CyclomaticComplexity:
   Max: 26
 
-# Offense count: 735
-# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
+# Offense count: 553
+# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
 Metrics/MethodLength:
   Max: 179
 
-# Offense count: 4
-# Configuration parameters: CountKeywordArgs.
+# Offense count: 1
+# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
 Metrics/ParameterLists:
-  Max: 9
+  Max: 6
 
-# Offense count: 69
+# Offense count: 56
 # Configuration parameters: IgnoredMethods.
 Metrics/PerceivedComplexity:
   Max: 26
 
-# Offense count: 540
+# Offense count: 365
 Minitest/MultipleAssertions:
   Max: 81
 
-# Offense count: 6
+# Offense count: 4
 Naming/AccessorMethodName:
   Exclude:
     - 'app/controllers/application_controller.rb'
     - 'app/helpers/title_helper.rb'
-    - 'app/models/old_way.rb'
     - 'lib/osm.rb'
 
 # Offense count: 8
@@ -100,7 +109,6 @@ Naming/AccessorMethodName:
 # MethodDefinitionMacros: define_method, define_singleton_method
 Naming/PredicateName:
   Exclude:
-    - 'spec/**/*'
     - 'app/models/changeset.rb'
     - 'app/models/old_node.rb'
     - 'app/models/old_relation.rb'
@@ -126,7 +134,7 @@ Rails/HasAndBelongsToMany:
     - 'app/models/changeset.rb'
     - 'app/models/user.rb'
 
-# Offense count: 4
+# Offense count: 3
 # Configuration parameters: Include.
 # Include: app/helpers/**/*.rb
 Rails/HelperInstanceVariable:
@@ -144,7 +152,7 @@ Rails/NotNullColumn:
     - 'db/migrate/025_add_end_time_to_changesets.rb'
     - 'db/migrate/20120404205604_add_user_and_description_to_redaction.rb'
 
-# Offense count: 19
+# Offense count: 8
 Rails/OutputSafety:
   Exclude:
     - 'app/controllers/users_controller.rb'
@@ -152,22 +160,22 @@ Rails/OutputSafety:
     - 'lib/rich_text.rb'
     - 'test/helpers/application_helper_test.rb'
 
-# Offense count: 95
+# Offense count: 80
 # Cop supports --auto-correct.
 # Configuration parameters: EnforcedStyle.
 # SupportedStyles: strict, flexible
 Rails/TimeZone:
   Enabled: false
 
-# Offense count: 572
+# Offense count: 558
 # Cop supports --auto-correct.
 # Configuration parameters: EnforcedStyle.
 # SupportedStyles: always, always_true, never
 Style/FrozenStringLiteralComment:
   Enabled: false
 
-# Offense count: 78
+# Offense count: 54
 # Cop supports --auto-correct.
 # Configuration parameters: Strict.
 Style/NumericLiterals:
-  MinDigits: 11
+  MinDigits: 15
index a236083db2813f09bab39b03bd7b7eb0ba629172..29a57570d154383dbbbf3381be8ba6a86508ea54 100644 (file)
@@ -319,9 +319,7 @@ module Api
       end
       # stupid Time seems to throw both of these for bad parsing, so
       # we have to catch both and ensure the correct code path is taken.
-    rescue ArgumentError => e
-      raise OSM::APIBadUserInput, e.message.to_s
-    rescue RuntimeError => e
+    rescue ArgumentError, RuntimeError => e
       raise OSM::APIBadUserInput, e.message.to_s
     end
 
index 7d05b6765b3be1a965dd6f1d7a911fec06151b74..bc1220af8faa767a16a3f464b9792f5f24052b24 100644 (file)
@@ -319,11 +319,11 @@ class GeocoderController < ApplicationController
   def nsew_to_decdeg(captures)
     begin
       Float(captures[0])
-      lat = !captures[2].casecmp("s").zero? ? captures[0].to_f : -captures[0].to_f
-      lon = !captures[5].casecmp("w").zero? ? captures[3].to_f : -captures[3].to_f
+      lat = captures[2].casecmp("s").zero? ? -captures[0].to_f : captures[0].to_f
+      lon = captures[5].casecmp("w").zero? ? -captures[3].to_f : captures[3].to_f
     rescue StandardError
-      lat = !captures[0].casecmp("s").zero? ? captures[1].to_f : -captures[1].to_f
-      lon = !captures[3].casecmp("w").zero? ? captures[4].to_f : -captures[4].to_f
+      lat = captures[0].casecmp("s").zero? ? -captures[1].to_f : captures[1].to_f
+      lon = captures[3].casecmp("w").zero? ? -captures[4].to_f : captures[4].to_f
     end
     { :lat => lat, :lon => lon }
   end
@@ -331,11 +331,11 @@ class GeocoderController < ApplicationController
   def ddm_to_decdeg(captures)
     begin
       Float(captures[0])
-      lat = !captures[3].casecmp("s").zero? ? captures[0].to_f + captures[1].to_f / 60 : -(captures[0].to_f + captures[1].to_f / 60)
-      lon = !captures[7].casecmp("w").zero? ? captures[4].to_f + captures[5].to_f / 60 : -(captures[4].to_f + captures[5].to_f / 60)
+      lat = captures[3].casecmp("s").zero? ? -(captures[0].to_f + captures[1].to_f / 60) : captures[0].to_f + captures[1].to_f / 60
+      lon = captures[7].casecmp("w").zero? ? -(captures[4].to_f + captures[5].to_f / 60) : captures[4].to_f + captures[5].to_f / 60
     rescue StandardError
-      lat = !captures[0].casecmp("s").zero? ? captures[1].to_f + captures[2].to_f / 60 : -(captures[1].to_f + captures[2].to_f / 60)
-      lon = !captures[4].casecmp("w").zero? ? captures[5].to_f + captures[6].to_f / 60 : -(captures[5].to_f + captures[6].to_f / 60)
+      lat = captures[0].casecmp("s").zero? ? -(captures[1].to_f + captures[2].to_f / 60) : captures[1].to_f + captures[2].to_f / 60
+      lon = captures[4].casecmp("w").zero? ? -(captures[5].to_f + captures[6].to_f / 60) : captures[5].to_f + captures[6].to_f / 60
     end
     { :lat => lat, :lon => lon }
   end
@@ -343,11 +343,11 @@ class GeocoderController < ApplicationController
   def dms_to_decdeg(captures)
     begin
       Float(captures[0])
-      lat = !captures[4].casecmp("s").zero? ? captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60 : -(captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60)
-      lon = !captures[9].casecmp("w").zero? ? captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60 : -(captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60)
+      lat = captures[4].casecmp("s").zero? ? -(captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60) : captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60
+      lon = captures[9].casecmp("w").zero? ? -(captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60) : captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60
     rescue StandardError
-      lat = !captures[0].casecmp("s").zero? ? captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60 : -(captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60)
-      lon = !captures[5].casecmp("w").zero? ? captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60 : -(captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60)
+      lat = captures[0].casecmp("s").zero? ? -(captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60) : captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60
+      lon = captures[5].casecmp("w").zero? ? -(captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60) : captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60
     end
     { :lat => lat, :lon => lon }
   end
index 45a41058c04f77cc785775060e30a4663777a9d4..30425bd429babe42827509eb30c331e00a4cc3d1 100644 (file)
@@ -23,7 +23,7 @@ class RedactionsController < ApplicationController
     @redaction.user = current_user
     @redaction.title = params[:redaction][:title]
     @redaction.description = params[:redaction][:description]
-    # note that the description format will default to 'markdown'
+    # NOTE: the description format will default to 'markdown'
 
     if @redaction.save
       flash[:notice] = t(".flash")
@@ -38,7 +38,7 @@ class RedactionsController < ApplicationController
   def edit; end
 
   def update
-    # note - don't update the user ID
+    # NOTE: don't update the user ID
     @redaction.title = params[:redaction][:title]
     @redaction.description = params[:redaction][:description]
 
index 12099498e2de71edd681634fcbc64827a5e24390..fe1a900136466472cb258198c3caa6a0b796fdd4 100644 (file)
@@ -32,7 +32,7 @@ class OldNode < ApplicationRecord
   self.table_name = "nodes"
   self.primary_keys = "node_id", "version"
 
-  # note this needs to be included after the table name changes, or
+  # NOTE: this needs to be included after the table name changes, or
   # the queries generated by Redactable will use the wrong table name.
   include Redactable
 
index f35678a19a262938a11f1a21198502cd27a07750..bfbe673b0881865611bcdfa64b2d2fa6188d04e4 100644 (file)
@@ -27,7 +27,7 @@ class OldRelation < ApplicationRecord
   self.table_name = "relations"
   self.primary_keys = "relation_id", "version"
 
-  # note this needs to be included after the table name changes, or
+  # NOTE: this needs to be included after the table name changes, or
   # the queries generated by Redactable will use the wrong table name.
   include Redactable
 
index 1ee6935ed6c0b0b505d1fdc1eb147041f2174804..247123005c3d4464ec1b49a52254e12ad4ff91c9 100644 (file)
@@ -27,7 +27,7 @@ class OldWay < ApplicationRecord
   self.table_name = "ways"
   self.primary_keys = "way_id", "version"
 
-  # note this needs to be included after the table name changes, or
+  # NOTE: this needs to be included after the table name changes, or
   # the queries generated by Redactable will use the wrong table name.
   include Redactable
 
index 9afedb04ee29a68a0cabf434b549a22ff6dbd1f8..346c5eea95c3d13205f1bb5ad5bc3d4b6ce9436e 100644 (file)
@@ -32,8 +32,7 @@ class Report < ApplicationRecord
 
   def self.categories_for(reportable)
     case reportable.class.name
-    when "DiaryEntry" then %w[spam offensive threat other]
-    when "DiaryComment" then %w[spam offensive threat other]
+    when "DiaryEntry", "DiaryComment" then %w[spam offensive threat other]
     when "User" then %w[spam offensive threat vandal other]
     when "Note" then %w[spam personal abusive other]
     else %w[other]
index d46a619843f02d95f0c5d878025cac6df3fd7cbe..a5b29411c64e30d34cae1ca6a6d571562320e689 100644 (file)
@@ -22,7 +22,7 @@
       <% changeset = contact.changesets.first %>
       <% if changeset %>
         <%= t("users.show.latest edit", :ago => time_ago_in_words(changeset.created_at, :scope => :'datetime.distance_in_words_ago')) %>
-        <% comment = changeset.tags["comment"].to_s != "" ? changeset.tags["comment"] : t("browse.no_comment") %>
+        <% comment = changeset.tags["comment"].to_s == "" ? t("browse.no_comment") : changeset.tags["comment"] %>
         <q><%= link_to(comment,
                        { :controller => "browse", :action => "changeset", :id => changeset.id },
                        { :title => t("changesets.changeset.view_changeset_details") }) %></q>
index 2e2f45ab88e1c46667b09719f07ca7880d238936..c897785518cd484a0d7b742e5cc47545356d2910 100644 (file)
@@ -35,12 +35,12 @@ module OpenStreetMap
     module ClassMethods
       def included(controller)
         controller.class_eval do
-          def self.before_filter(*names, &blk)
-            before_action(*names, &blk)
+          def self.before_filter(...)
+            before_action(...)
           end
 
-          def self.skip_before_filter(*names, &blk)
-            skip_before_action(*names, &blk)
+          def self.skip_before_filter(...)
+            skip_before_action(...)
           end
         end
 
index b1f4707b50272c6767fc9184341d3acd1ca0e4bf..a2a56074f6916e7d57a557908218b03f9a6399b8 100644 (file)
@@ -1 +1 @@
-StrongMigrations.start_after = 20190518115041 # rubocop:disable Style/NumericLiterals
+StrongMigrations.start_after = 20190518115041
index 33205fe62f39193ccf0ea47af843de891ffb8243..cd9e9afa7f96c25b90a4b1eaca3719a94890dec7 100755 (executable)
@@ -86,7 +86,7 @@ rescue StandardError => e
   puts "<p><em>Exception: #{e}</em><br />#{e.backtrace.join('<br />')}</p>"
 end
 
-puts "<p>Report took #{(Time.new - start_time)} seconds to run</p>"
+puts "<p>Report took #{Time.new - start_time} seconds to run</p>"
 puts "</body>"
 puts "</html>"
 
index fbe0450f2459491f801c9ca6e8720b6c35a578c9..d3fb195feb6ce42950b00bdbc03e83e645707679 100644 (file)
@@ -105,7 +105,7 @@ module Api
       assert_equal "The parameter bbox is required, and must be of the form min_lon,min_lat,max_lon,max_lat", @response.body, "A bbox param was expected"
     end
 
-    def test_traces_page_less_than_0
+    def test_traces_page_less_than_zero
       -10.upto(-1) do |i|
         get trackpoints_path(:page => i, :bbox => "-0.1,-0.1,0.1,0.1")
         assert_response :bad_request
index a7541c0759aa03db4a23754af12fc59f1f4840e3..d0f0ce086ef4fe4b93988057e43c761ab335c81e 100644 (file)
@@ -479,7 +479,7 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest
         assert_select "li.search_results_entry", results.count
 
         results.each do |result|
-          attrs = result.collect { |k, v| "[data-#{k}='#{v}']" }.join("")
+          attrs = result.collect { |k, v| "[data-#{k}='#{v}']" }.join
           assert_select "li.search_results_entry a.set_position#{attrs}", result[:name]
         end
       end
index 364142dd9a669b4aaf52352d16dc57c46419c7ea..36bee9c95135e1e85b9a1282d0dc84a9d2785daa 100644 (file)
@@ -761,7 +761,9 @@ class TracesControllerTest < ActionDispatch::IntegrationTest
     assert_response :success
     assert_template "index"
 
-    if !traces.empty?
+    if traces.empty?
+      assert_select "h4", /Nothing here yet/
+    else
       assert_select "table#trace_list tbody", :count => 1 do
         assert_select "tr", :count => traces.length do |rows|
           traces.zip(rows).each do |trace, row|
@@ -772,8 +774,6 @@ class TracesControllerTest < ActionDispatch::IntegrationTest
           end
         end
       end
-    else
-      assert_select "h4", /Nothing here yet/
     end
   end
 
index ced3454792d3efbec37dbf6f3d458aaddbb0ca8c..b5fc8405da114a630646cb6f519c055633e8bfdf 100644 (file)
@@ -1,4 +1,3 @@
 FactoryBot.define do
-  factory :diary_entry_subscription do
-  end
+  factory :diary_entry_subscription
 end