From fea1b5b88de731dd35d1f79d36ec40a8e8a1f6af Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 28 Dec 2021 18:46:05 +0000 Subject: [PATCH] Fix new rubocop warnings --- .rubocop_todo.yml | 44 ++++++++++++------- app/controllers/api/traces_controller.rb | 2 +- app/controllers/traces_controller.rb | 2 +- app/models/node.rb | 2 +- app/models/old_node.rb | 2 +- app/models/old_relation.rb | 2 +- app/models/old_way.rb | 2 +- app/models/relation.rb | 2 +- app/models/way.rb | 2 +- .../api/user_preferences/index.json.jbuilder | 2 +- db/migrate/20201214144017_expand_nonce_id.rb | 6 ++- 11 files changed, 41 insertions(+), 27 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 345eed674..d1f897bac 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2021-09-14 19:29:59 UTC using RuboCop version 1.21.0. +# on 2021-12-28 19:44:27 UTC using RuboCop version 1.24.0. # 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 @@ -14,7 +14,7 @@ require: - rubocop-rails - rubocop-rake -# Offense count: 524 +# Offense count: 544 # Cop supports --auto-correct. # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https @@ -38,9 +38,9 @@ Lint/AmbiguousOperatorPrecedence: # Configuration parameters: AllowSafeAssignment. Lint/AssignmentInCondition: Exclude: + - 'app/controllers/accounts_controller.rb' - 'app/controllers/api/traces_controller.rb' - 'app/controllers/api/user_preferences_controller.rb' - - 'app/controllers/accounts_controller.rb' - 'app/controllers/application_controller.rb' - 'app/controllers/geocoder_controller.rb' - 'app/controllers/notes_controller.rb' @@ -54,7 +54,7 @@ Lint/AssignmentInCondition: - 'lib/osm.rb' - 'script/deliver-message' -# Offense count: 8 +# Offense count: 7 # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. Lint/DuplicateBranch: Exclude: @@ -62,14 +62,13 @@ Lint/DuplicateBranch: - 'app/controllers/diary_entries_controller.rb' - 'app/controllers/geocoder_controller.rb' - 'app/helpers/browse_tags_helper.rb' - - 'lib/password_hash.rb' -# Offense count: 643 +# Offense count: 663 # Configuration parameters: IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: Max: 189 -# Offense count: 69 +# Offense count: 72 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. # IgnoredMethods: refine Metrics/BlockLength: @@ -83,14 +82,14 @@ Metrics/BlockNesting: # Offense count: 25 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 337 + Max: 313 -# Offense count: 58 +# Offense count: 57 # Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: Max: 25 -# Offense count: 716 +# Offense count: 739 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. Metrics/MethodLength: Max: 179 @@ -100,14 +99,14 @@ Metrics/MethodLength: Metrics/ParameterLists: Max: 6 -# Offense count: 62 +# Offense count: 59 # Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: Max: 26 -# Offense count: 528 +# Offense count: 549 Minitest/MultipleAssertions: - Max: 54 + Max: 52 # Offense count: 3 Naming/AccessorMethodName: @@ -131,6 +130,12 @@ Naming/PredicateName: - 'app/models/user.rb' - 'lib/classic_pagination/pagination.rb' +# Offense count: 2 +# Cop supports --auto-correct. +Performance/StringIdentifierArgument: + Exclude: + - 'test/controllers/accounts_controller_test.rb' + # Offense count: 5 # Configuration parameters: Database, Include. # SupportedDatabases: mysql, postgresql @@ -183,7 +188,12 @@ Rails/OutputSafety: - 'lib/rich_text.rb' - 'test/helpers/application_helper_test.rb' -# Offense count: 91 +# Offense count: 23 +# Cop supports --auto-correct. +Rails/RedundantPresenceValidationOnBelongsTo: + Enabled: false + +# Offense count: 90 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: strict, flexible @@ -199,15 +209,15 @@ Rake/Desc: - 'lib/tasks/subscribe_diary_authors.rake' - 'lib/tasks/subscribe_old_changesets.rake' -# Offense count: 602 +# Offense count: 609 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 73 +# Offense count: 72 # Cop supports --auto-correct. -# Configuration parameters: Strict. +# Configuration parameters: Strict, AllowedNumbers. Style/NumericLiterals: MinDigits: 15 diff --git a/app/controllers/api/traces_controller.rb b/app/controllers/api/traces_controller.rb index 43bbeeb1d..9894441ff 100644 --- a/app/controllers/api/traces_controller.rb +++ b/app/controllers/api/traces_controller.rb @@ -101,7 +101,7 @@ module Api filename = "/tmp/#{rand}" # ...and save the uploaded file to that location - File.open(filename, "wb") { |f| f.write(file.read) } + File.binwrite(filename, file.read) # Create the trace object, falsely marked as already # inserted to stop the import daemon trying to load it diff --git a/app/controllers/traces_controller.rb b/app/controllers/traces_controller.rb index 9ebad1613..43977c3ce 100644 --- a/app/controllers/traces_controller.rb +++ b/app/controllers/traces_controller.rb @@ -256,7 +256,7 @@ class TracesController < ApplicationController filename = "/tmp/#{rand}" # ...and save the uploaded file to that location - File.open(filename, "wb") { |f| f.write(file.read) } + File.binwrite(filename, file.read) # Create the trace object, falsely marked as already # inserted to stop the import daemon trying to load it diff --git a/app/models/node.rb b/app/models/node.rb index 8bfac993b..3214564c8 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -206,7 +206,7 @@ class Node < ApplicationRecord end def tags - @tags ||= node_tags.collect { |t| [t.k, t.v] }.to_h + @tags ||= node_tags.to_h { |t| [t.k, t.v] } end attr_writer :tags diff --git a/app/models/old_node.rb b/app/models/old_node.rb index 81d8e331f..3caf0442b 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -82,7 +82,7 @@ class OldNode < ApplicationRecord end def tags - @tags ||= old_tags.collect { |t| [t.k, t.v] }.to_h + @tags ||= old_tags.to_h { |t| [t.k, t.v] } end attr_writer :tags diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index d0a03ac25..29edb90ad 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -82,7 +82,7 @@ class OldRelation < ApplicationRecord end def tags - @tags ||= old_tags.collect { |t| [t.k, t.v] }.to_h + @tags ||= old_tags.to_h { |t| [t.k, t.v] } end attr_writer :members, :tags diff --git a/app/models/old_way.rb b/app/models/old_way.rb index 9acf8665d..7af8906b1 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -80,7 +80,7 @@ class OldWay < ApplicationRecord end def tags - @tags ||= old_tags.collect { |t| [t.k, t.v] }.to_h + @tags ||= old_tags.to_h { |t| [t.k, t.v] } end attr_writer :nds, :tags diff --git a/app/models/relation.rb b/app/models/relation.rb index 25564940b..a231feddb 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -130,7 +130,7 @@ class Relation < ApplicationRecord end def tags - @tags ||= relation_tags.collect { |t| [t.k, t.v] }.to_h + @tags ||= relation_tags.to_h { |t| [t.k, t.v] } end attr_writer :members, :tags diff --git a/app/models/way.rb b/app/models/way.rb index 724965ddf..933cb7c8b 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -112,7 +112,7 @@ class Way < ApplicationRecord end def tags - @tags ||= way_tags.collect { |t| [t.k, t.v] }.to_h + @tags ||= way_tags.to_h { |t| [t.k, t.v] } end attr_writer :nds, :tags diff --git a/app/views/api/user_preferences/index.json.jbuilder b/app/views/api/user_preferences/index.json.jbuilder index 064bf27f2..f4f0d284f 100644 --- a/app/views/api/user_preferences/index.json.jbuilder +++ b/app/views/api/user_preferences/index.json.jbuilder @@ -1,3 +1,3 @@ json.partial! "api/root_attributes" -json.preferences @user_preferences.map { |pref| [pref.k, pref.v] }.to_h +json.preferences(@user_preferences.to_h { |pref| [pref.k, pref.v] }) diff --git a/db/migrate/20201214144017_expand_nonce_id.rb b/db/migrate/20201214144017_expand_nonce_id.rb index 9416ffe6a..1baa286fb 100644 --- a/db/migrate/20201214144017_expand_nonce_id.rb +++ b/db/migrate/20201214144017_expand_nonce_id.rb @@ -1,7 +1,11 @@ class ExpandNonceId < ActiveRecord::Migration[6.0] - def change + def up safety_assured do change_column :oauth_nonces, :id, :bigint end end + + def down + raise ActiveRecord::IrreversibleMigration + end end -- 2.43.2