From 1f2ac59d1d24d75c510412e63070d83af13c6757 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 26 Mar 2018 19:00:03 +0100 Subject: [PATCH] Fix new rubocop warnings --- .rubocop.yml | 3 +++ app/controllers/amf_controller.rb | 22 +++++++++---------- app/controllers/application_controller.rb | 14 ++++++------ app/controllers/changeset_controller.rb | 6 ++--- app/controllers/diary_entry_controller.rb | 6 ++--- app/controllers/oauth_clients_controller.rb | 2 +- app/controllers/swf_controller.rb | 16 +++++++------- app/controllers/user_blocks_controller.rb | 2 +- app/models/client_application.rb | 2 +- app/models/oauth_token.rb | 2 +- app/models/user.rb | 2 +- app/models/user_block.rb | 2 +- config/initializers/piwik.rb | 2 +- .../020_populate_node_tags_and_remove.rb | 4 ++-- lib/osm.rb | 4 ++-- lib/potlatch.rb | 14 ++++++------ script/rails | 4 ++-- test/test_helper.rb | 2 +- 18 files changed, 56 insertions(+), 53 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5e7be9797..6f721998d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -38,6 +38,9 @@ Naming/FileName: - 'script/locale/reload-languages' - 'script/update-spam-blocks' +Naming/UncommunicativeMethodParamName: + Enabled: false + Rails/ApplicationRecord: Enabled: false diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 9f909ea10..495a658b4 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -110,17 +110,17 @@ class AmfController < ApplicationController def amf_handle_error(call, rootobj, rootid) yield rescue OSM::APIAlreadyDeletedError => ex - return [-4, ex.object, ex.object_id] + [-4, ex.object, ex.object_id] rescue OSM::APIVersionMismatchError => ex - return [-3, [rootobj, rootid], [ex.type.downcase, ex.id, ex.latest]] + [-3, [rootobj, rootid], [ex.type.downcase, ex.id, ex.latest]] rescue OSM::APIUserChangesetMismatchError => ex - return [-2, ex.to_s] + [-2, ex.to_s] rescue OSM::APIBadBoundingBox => ex - return [-2, "Sorry - I can't get the map for that area. The server said: #{ex}"] + [-2, "Sorry - I can't get the map for that area. The server said: #{ex}"] rescue OSM::APIError => ex - return [-1, ex.to_s] + [-1, ex.to_s] rescue StandardError => ex - return [-2, "An unusual error happened (in #{call}). The server said: #{ex}"] + [-2, "An unusual error happened (in #{call}). The server said: #{ex}"] end def amf_handle_error_with_timeout(call, rootobj, rootid) @@ -437,9 +437,9 @@ class AmfController < ApplicationController revdates.collect! { |d| [(d + 1).strftime("%d %b %Y, %H:%M:%S")] + revusers[d.to_i] } revdates.uniq! - return ["way", wayid, revdates] + ["way", wayid, revdates] rescue ActiveRecord::RecordNotFound - return ["way", wayid, []] + ["way", wayid, []] end # Find history of a node. Returns 'node', id, and an array of previous versions as above. @@ -448,9 +448,9 @@ class AmfController < ApplicationController history = Node.find(nodeid).old_nodes.unredacted.reverse.collect do |old_node| [(old_node.timestamp + 1).strftime("%d %b %Y, %H:%M:%S")] + change_user(old_node) end - return ["node", nodeid, history] + ["node", nodeid, history] rescue ActiveRecord::RecordNotFound - return ["node", nodeid, []] + ["node", nodeid, []] end def change_user(obj) @@ -865,7 +865,7 @@ class AmfController < ApplicationController end def getlocales - @locales ||= Locale.list(Dir.glob(Rails.root.join("config", "potlatch", "locales", "*")).collect { |f| File.basename(f, ".yml") }) + @getlocales ||= Locale.list(Dir.glob(Rails.root.join("config", "potlatch", "locales", "*")).collect { |f| File.basename(f, ".yml") }) end ## diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a24df48e0..c354b5386 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -296,13 +296,13 @@ class ApplicationController < ActionController::Base end def preferred_languages - @languages ||= if params[:locale] - Locale.list(params[:locale]) - elsif current_user - current_user.preferred_languages - else - Locale.list(http_accept_language.user_preferred_languages) - end + @preferred_languages ||= if params[:locale] + Locale.list(params[:locale]) + elsif current_user + current_user.preferred_languages + else + Locale.list(http_accept_language.user_preferred_languages) + end end helper_method :preferred_languages diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index 0a63d5253..56fab0fc4 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -507,7 +507,7 @@ class ChangesetController < ApplicationController # restrict changes to those closed during a particular time period def conditions_time(changesets, time) if time.nil? - return changesets + changesets elsif time.count(",") == 1 # if there is a range, i.e: comma separated, then the first is # low, second is high - same as with bounding boxes. @@ -517,10 +517,10 @@ class ChangesetController < ApplicationController raise OSM::APIBadUserInput, "bad time range" if times.size != 2 from, to = times.collect { |t| Time.parse(t) } - return changesets.where("closed_at >= ? and created_at <= ?", from, to) + changesets.where("closed_at >= ? and created_at <= ?", from, to) else # if there is no comma, assume its a lower limit on time - return changesets.where("closed_at >= ?", Time.parse(time)) + changesets.where("closed_at >= ?", Time.parse(time)) 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. diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index 5bd95775d..7f5f4fb3a 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -48,7 +48,7 @@ class DiaryEntryController < ApplicationController if current_user != @diary_entry.user redirect_to :action => "view", :id => params[:id] - elsif params[:diary_entry] && @diary_entry.update_attributes(entry_params) + elsif params[:diary_entry] && @diary_entry.update(entry_params) redirect_to :action => "view", :id => params[:id] end @@ -192,13 +192,13 @@ class DiaryEntryController < ApplicationController def hide entry = DiaryEntry.find(params[:id]) - entry.update_attributes(:visible => false) + entry.update(:visible => false) redirect_to :action => "list", :display_name => entry.user.display_name end def hidecomment comment = DiaryComment.find(params[:comment]) - comment.update_attributes(:visible => false) + comment.update(:visible => false) redirect_to :action => "view", :display_name => comment.diary_entry.user.display_name, :id => comment.diary_entry.id end diff --git a/app/controllers/oauth_clients_controller.rb b/app/controllers/oauth_clients_controller.rb index 76fdd6421..eb427e090 100644 --- a/app/controllers/oauth_clients_controller.rb +++ b/app/controllers/oauth_clients_controller.rb @@ -40,7 +40,7 @@ class OauthClientsController < ApplicationController def update @client_application = current_user.client_applications.find(params[:id]) - if @client_application.update_attributes(application_params) + if @client_application.update(application_params) flash[:notice] = t "oauth_clients.update.flash" redirect_to :action => "show", :id => @client_application.id else diff --git a/app/controllers/swf_controller.rb b/app/controllers/swf_controller.rb index 329de0dfc..96237f029 100644 --- a/app/controllers/swf_controller.rb +++ b/app/controllers/swf_controller.rb @@ -10,10 +10,10 @@ class SwfController < ApplicationController # ==================================================================== # Public methods - # ---- trackpoints compile SWF of trackpoints + # ---- trackpoints compile SWF of trackpoints def trackpoints - # - Initialise + # - Initialise baselong = params["baselong"].to_f basey = params["basey"].to_f @@ -23,7 +23,7 @@ class SwfController < ApplicationController params["xmax"], params["ymax"]) start = params["start"].to_i - # - Begin movie + # - Begin movie bounds_left = 0 bounds_right = 320 * 20 @@ -31,13 +31,13 @@ class SwfController < ApplicationController bounds_top = 240 * 20 m = "" - m += swf_record(9, 255.chr + 155.chr + 155.chr) # Background + m += swf_record(9, 255.chr + 155.chr + 155.chr) # Background absx = 0 absy = 0 xl = yb = 9999999 xr = yt = -9999999 - # - Send SQL for GPS tracks + # - Send SQL for GPS tracks b = "" lasttime = 0 @@ -84,7 +84,7 @@ class SwfController < ApplicationController m += swf_record(2, pack_u16(1) + pack_rect(xl, xr, yb, yt) + r) m += swf_record(4, pack_u16(1) + pack_u16(1)) - # - Create Flash header and write to browser + # - Create Flash header and write to browser m += swf_record(1, "") # Show frame m += swf_record(0, "") # End @@ -108,7 +108,7 @@ class SwfController < ApplicationController s += 2.chr # Two line styles s += pack_u16(0) + 0.chr + 255.chr + 255.chr # Width 5, RGB #00FFFF s += pack_u16(0) + 255.chr + 0.chr + 255.chr # Width 5, RGB #FF00FF - s += 34.chr # 2 fill, 2 line index bits + s += 34.chr # 2 fill, 2 line index bits s end @@ -120,7 +120,7 @@ class SwfController < ApplicationController d = "001001" # Line style change, moveTo l = [length_sb(x), length_sb(y)].max d += format("%05b%0*b%0*b", l, l, x, l, y) - d += col # Select line style + d += col # Select line style d end diff --git a/app/controllers/user_blocks_controller.rb b/app/controllers/user_blocks_controller.rb index d5820568e..c41501367 100644 --- a/app/controllers/user_blocks_controller.rb +++ b/app/controllers/user_blocks_controller.rb @@ -60,7 +60,7 @@ class UserBlocksController < ApplicationController if @user_block.creator != current_user flash[:error] = t("user_block.update.only_creator_can_edit") redirect_to :action => "edit" - elsif @user_block.update_attributes( + elsif @user_block.update( :ends_at => Time.now.getutc + @block_period.hours, :reason => params[:user_block][:reason], :needs_view => params[:user_block][:needs_view] diff --git a/app/models/client_application.rb b/app/models/client_application.rb index c95ffc322..ef1a0110e 100644 --- a/app/models/client_application.rb +++ b/app/models/client_application.rb @@ -72,7 +72,7 @@ class ClientApplication < ActiveRecord::Base end def credentials - @oauth_client ||= OAuth::Consumer.new(key, secret) + @credentials ||= OAuth::Consumer.new(key, secret) end def create_request_token(_params = {}) diff --git a/app/models/oauth_token.rb b/app/models/oauth_token.rb index fd332723f..5eeda48ba 100644 --- a/app/models/oauth_token.rb +++ b/app/models/oauth_token.rb @@ -52,7 +52,7 @@ class OauthToken < ActiveRecord::Base end def invalidate! - update_attributes(:invalidated_at => Time.now) + update(:invalidated_at => Time.now) end def authorized? diff --git a/app/models/user.rb b/app/models/user.rb index 908a3d013..da3964142 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -189,7 +189,7 @@ class User < ActiveRecord::Base end def preferred_languages - @locales ||= Locale.list(languages) + @preferred_languages ||= Locale.list(languages) end def nearby(radius = NEARBY_RADIUS, num = NEARBY_USERS) diff --git a/app/models/user_block.rb b/app/models/user_block.rb index 4f9cf1128..9f32862af 100644 --- a/app/models/user_block.rb +++ b/app/models/user_block.rb @@ -63,7 +63,7 @@ class UserBlock < ActiveRecord::Base # revokes the block, allowing the user to use the API again. the argument # is the user object who is revoking the ban. def revoke!(revoker) - update_attributes( + update( :ends_at => Time.now.getutc, :revoker_id => revoker.id, :needs_view => false diff --git a/config/initializers/piwik.rb b/config/initializers/piwik.rb index 2de98ce06..1b9fa73c1 100644 --- a/config/initializers/piwik.rb +++ b/config/initializers/piwik.rb @@ -1,5 +1,5 @@ require "yaml" -if File.exist?(piwik_file = File.expand_path("../../piwik.yml", __FILE__)) +if File.exist?(piwik_file = File.expand_path("../piwik.yml", __dir__)) PIWIK = YAML.load_file(piwik_file) end diff --git a/db/migrate/020_populate_node_tags_and_remove.rb b/db/migrate/020_populate_node_tags_and_remove.rb index 2a81a2b9a..6366a33ce 100644 --- a/db/migrate/020_populate_node_tags_and_remove.rb +++ b/db/migrate/020_populate_node_tags_and_remove.rb @@ -38,8 +38,8 @@ class PopulateNodeTagsAndRemove < ActiveRecord::Migration[5.0] create_table :node_tags, :id => false do |t| t.column :id, :bigint, :null => false t.column :version, :bigint, :null => false - t.column :k, :string, :default => "", :null => false - t.column :v, :string, :default => "", :null => false + t.column :k, :string, :default => "", :null => false + t.column :v, :string, :default => "", :null => false end # now get the data back diff --git a/lib/osm.rb b/lib/osm.rb index 66428c13c..71e12534f 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -514,9 +514,9 @@ module OSM country = "GB" if country == "UK" end - return country + country rescue StandardError - return nil + nil end def self.ip_location(ip_address) diff --git a/lib/potlatch.rb b/lib/potlatch.rb index 76944e394..6fe0b0152 100644 --- a/lib/potlatch.rb +++ b/lib/potlatch.rb @@ -40,7 +40,7 @@ module Potlatch break if key == "" arr[key] = getvalue(s) end - s.getbyte # skip the 9 'end of object' value + s.getbyte # skip the 9 'end of object' value arr end @@ -162,11 +162,11 @@ module Potlatch # The Potlatch class is a helper for Potlatch class Potlatch # ----- getpresets - # in: none - # does: reads tag preset menus, colours, and autocomplete config files - # out: [0] presets, [1] presetmenus, [2] presetnames, - # [3] colours, [4] casing, [5] areas, [6] autotags - # (all hashes) + # in: none + # does: reads tag preset menus, colours, and autocomplete config files + # out: [0] presets, [1] presetmenus, [2] presetnames, + # [3] colours, [4] casing, [5] areas, [6] autotags + # (all hashes) def self.get_presets Rails.logger.info(" Message: getpresets") @@ -176,7 +176,7 @@ module Potlatch presetnames = { "point" => {}, "way" => {}, "POI" => {} } presettype = "" presetcategory = "" - # StringIO.open(txt) do |file| + # StringIO.open(txt) do |file| File.open(Rails.root.join("config", "potlatch", "presets.txt")) do |file| file.each_line do |line| t = line.chomp diff --git a/script/rails b/script/rails index 9a5a81dcf..4cea4ea17 100755 --- a/script/rails +++ b/script/rails @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -APP_PATH = File.expand_path("../../config/application", __FILE__) -require File.expand_path("../../config/boot", __FILE__) +APP_PATH = File.expand_path("../config/application", __dir__) +require File.expand_path("../config/boot", __dir__) require "rails/commands" diff --git a/test/test_helper.rb b/test/test_helper.rb index c9ec46dcf..385a2f682 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,7 +2,7 @@ require "coveralls" Coveralls.wear!("rails") ENV["RAILS_ENV"] = "test" -require File.expand_path("../../config/environment", __FILE__) +require File.expand_path("../config/environment", __dir__) require "rails/test_help" require "webmock/minitest" -- 2.43.2