]> git.openstreetmap.org Git - rails.git/commitdiff
Fix rubocop warnings
authorTom Hughes <tom@compton.nu>
Wed, 4 Dec 2019 19:25:06 +0000 (19:25 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 4 Dec 2019 19:31:53 +0000 (19:31 +0000)
24 files changed:
.rubocop.yml
.rubocop_todo.yml
app/controllers/api/amf_controller.rb
app/controllers/api_controller.rb
app/controllers/users_controller.rb
app/mailers/application_mailer.rb [new file with mode: 0644]
app/mailers/notifier.rb
config/environments/development.rb
config/initializers/assets.rb
config/initializers/banners.rb
config/initializers/config.rb
config/initializers/omniauth.rb
config/initializers/wiki_pages.rb
db/migrate/034_create_languages.rb
lib/country.rb
lib/id.rb
lib/potlatch.rb
lib/tasks/add_version_to_nodes.rake
lib/tasks/auto_annotate_models.rake
lib/tasks/eslint.rake
lib/tasks/testing.rake
test/controllers/api/traces_controller_test.rb
test/controllers/traces_controller_test.rb
test/models/trace_test.rb

index 18bf69b9b85be093b8e2f81147cd08180a7d869a..c211cc2fdb02707384d2dd0286ff88349d3e08a4 100644 (file)
@@ -35,7 +35,7 @@ Naming/FileName:
     - 'script/locale/reload-languages'
     - 'script/update-spam-blocks'
 
-Naming/UncommunicativeMethodParamName:
+Naming/MethodParameterName:
   Enabled: false
 
 Rails/CreateTableWithTimestamps:
index 518e1eda47fde8461c99941b0e88ab12c2aace70..054e10cda85f1b763b58440f18122fc0bd244617 100644 (file)
@@ -27,7 +27,7 @@ Lint/AssignmentInCondition:
 
 # Offense count: 4
 # Configuration parameters: AllowComments.
-Lint/HandleExceptions:
+Lint/SuppressedException:
   Exclude:
     - 'app/controllers/api/amf_controller.rb'
     - 'app/controllers/users_controller.rb'
index e5648989b97a9a02fa8573e7c5ba64f55c0ca153..4dbc16fd287dd7a88f2f90703ecbdb19e4d7e53a 100644 (file)
@@ -226,14 +226,14 @@ module Api
       loaded_lang = "en"
 
       # Load English defaults
-      en = YAML.safe_load(File.open(Rails.root.join("config", "potlatch", "locales", "en.yml")))["en"]
+      en = YAML.safe_load(File.open(Rails.root.join("config/potlatch/locales/en.yml")))["en"]
 
       if lang == "en"
-        return [loaded_lang, en]
+        [loaded_lang, en]
       else
         # Use English as a fallback
         begin
-          other = YAML.safe_load(File.open(Rails.root.join("config", "potlatch", "locales", "#{lang}.yml")))[lang]
+          other = YAML.safe_load(File.open(Rails.root.join("config/potlatch/locales/#{lang}.yml")))[lang]
           loaded_lang = lang
         rescue StandardError
           other = en
@@ -241,7 +241,7 @@ module Api
 
         # We have to return a flat list and some of the keys won't be
         # translated (probably)
-        return [loaded_lang, en.merge(other)]
+        [loaded_lang, en.merge(other)]
       end
     end
 
@@ -876,7 +876,7 @@ module Api
     end
 
     def getlocales
-      @getlocales ||= 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
 
     ##
index df7cfe93be97d9ffa704db88d759be75523ffc32..44efdc0711f2cb39d53e8b59d33d58e8583dca5b 100644 (file)
@@ -12,7 +12,7 @@ class ApiController < ApplicationController
       # no auth, the user does not exist or the password was wrong
       response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
       render :plain => errormessage, :status => :unauthorized
-      return false
+      false
     end
   end
 
index 345bae2616607dde518f25de11b968ae8c08380e..a61a10d94f5c098606a3dffd7d59e5854fc61a88 100644 (file)
@@ -376,7 +376,7 @@ class UsersController < ApplicationController
     @user = User.find_by(:display_name => params[:display_name])
 
     if @user &&
-       (@user.visible? || (current_user&.administrator?))
+       (@user.visible? || current_user&.administrator?)
       @title = @user.display_name
     else
       render_unknown_user params[:display_name]
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
new file mode 100644 (file)
index 0000000..ead50cd
--- /dev/null
@@ -0,0 +1,2 @@
+class ApplicationMailer < ActionMailer::Base
+end
index 6e0c81a39177337b6f6ad57ddeb6b2d11e36644a..b125999810b0571127e752a544ff2c7db15d1098 100644 (file)
@@ -1,4 +1,4 @@
-class Notifier < ActionMailer::Base
+class Notifier < ApplicationMailer
   include ActionView::Helpers::AssetUrlHelper
 
   self.delivery_job = ActionMailer::MailDeliveryJob
@@ -177,7 +177,7 @@ class Notifier < ActionMailer::Base
   end
 
   def attach_project_logo
-    attachments.inline["logo.png"] = File.read(Rails.root.join("app", "assets", "images", "osm_logo_30.png"))
+    attachments.inline["logo.png"] = File.read(Rails.root.join("app/assets/images/osm_logo_30.png"))
   end
 
   def attach_user_avatar(user)
@@ -187,9 +187,9 @@ class Notifier < ActionMailer::Base
   def user_avatar_file(user)
     avatar = user&.avatar
     if avatar&.attached?
-      return avatar.variant(:resize => "50x50>").blob.download
+      avatar.variant(:resize => "50x50>").blob.download
     else
-      return File.read(Rails.root.join("app", "assets", "images", "avatar_small.png"))
+      File.read(Rails.root.join("app/assets/images/avatar_small.png"))
     end
   end
 
index 14bf9b54d800e89624e9f062212d7bd6c11f2c45..778e629eb49a987d1ac4620ffaaa9948e7ad0789 100644 (file)
@@ -14,7 +14,7 @@ Rails.application.configure do
 
   # Enable/disable caching. By default caching is disabled.
   # Run rails dev:cache to toggle caching.
-  if Rails.root.join("tmp", "caching-dev.txt").exist?
+  if Rails.root.join("tmp/caching-dev.txt").exist?
     config.action_controller.perform_caching = true
     config.action_controller.enable_fragment_cache_logging = true
 
index 15644963510fff77f0782ad83745b64362a8f937..85ce74f153ee1c2a9f3b95930cd74e32c5522847 100644 (file)
@@ -4,7 +4,7 @@
 Rails.application.config.assets.version = "1.0"
 
 # Location of manifest file.
-Rails.application.config.assets.manifest = Rails.root.join("tmp", "manifest.json")
+Rails.application.config.assets.manifest = Rails.root.join("tmp/manifest.json")
 
 # Add additional assets to the asset load path.
 Rails.application.config.assets.paths << Rails.root.join("config")
index 8eda290c57d2e1d7c5d6fe9cabc21df2155d9d21..c7ff281f30d721f2c31263bbbdeb703e01417d44 100644 (file)
@@ -1,5 +1,5 @@
 begin
-  BANNERS = YAML.load_file(Rails.root.join("config", "banners.yml")).deep_symbolize_keys
+  BANNERS = YAML.load_file(Rails.root.join("config/banners.yml")).deep_symbolize_keys
 rescue StandardError
   BANNERS = {}.freeze
 end
index 271bd79e7c881349f924b8d2e7b81b03d0bbf8b4..b74ba57e635340cb82c9335abbe0de89f5f6df41 100644 (file)
@@ -2,7 +2,7 @@
 # Otherwise, admins might not be aware that they are now silently ignored
 # and major problems could occur
 # rubocop:disable Rails/Output, Rails/Exit
-if File.exist?(Rails.root.join("config", "application.yml"))
+if File.exist?(Rails.root.join("config/application.yml"))
   puts "The config/application.yml file is no longer supported."
   puts ""
   puts "Default settings are now found in config/settings.yml and you"
index a61fe960ccafb8dd24fcb25b84796ad82e261348..7889fca815b8aab7387efecc792c91b19ef30489 100644 (file)
@@ -16,7 +16,7 @@ if Settings.key?(:memcache_servers)
 else
   require "openid/store/filesystem"
 
-  openid_store = OpenID::Store::Filesystem.new(Rails.root.join("tmp", "openids"))
+  openid_store = OpenID::Store::Filesystem.new(Rails.root.join("tmp/openids"))
 end
 
 openid_options = { :name => "openid", :store => openid_store }
index c679cd4e2df24bf9aa9b42f14531f8ae08f253e5..6720ee77886fa7ad892ded0b7133bf6710a1e13b 100644 (file)
@@ -1 +1 @@
-WIKI_PAGES = YAML.load_file(Rails.root.join("config", "wiki_pages.yml"))
+WIKI_PAGES = YAML.load_file(Rails.root.join("config/wiki_pages.yml"))
index 459d7f64770a1f88da2f57f5b976457cb8a3f1e7..20b80ec5b7b5a006badd62664e30ab7964ed0191 100644 (file)
@@ -10,7 +10,7 @@ class CreateLanguages < ActiveRecord::Migration[4.2]
 
     add_primary_key :languages, [:code]
 
-    Language.load(Rails.root.join("config", "languages.yml"))
+    Language.load(Rails.root.join("config/languages.yml"))
 
     add_foreign_key :users, :languages, :column => :locale, :primary_key => :code, :name => "users_locale_fkey"
     add_foreign_key :diary_entries, :languages, :column => :language_code, :primary_key => :code, :name => "diary_entries_language_code_fkey"
index ab88072ecd048d9b86faadcc198f653ae29ffc98..f6f6791252524e4e1e739d923de3aec138859f75 100644 (file)
@@ -19,7 +19,7 @@ class Country
 
   def self.load_countries
     countries = {}
-    xml = REXML::Document.new(File.read(Rails.root.join("config", "countries.xml")))
+    xml = REXML::Document.new(File.read(Rails.root.join("config/countries.xml")))
 
     xml.elements.each("geonames/country") do |ele|
       code = ele.get_text("countryCode").to_s
index 3adfecf65b4792854dc65e2f33b7e67a8a600f78..4e6cf3b7c8475e403da4322677f9dbb40c27f189 100644 (file)
--- a/lib/id.rb
+++ b/lib/id.rb
@@ -1,3 +1,3 @@
 module ID
-  LOCALES = Locale.list(Rails.root.join("vendor", "assets", "iD", "iD", "locales").entries.map { |p| p.basename.to_s[/(.*).json/] && Regexp.last_match(1) }.compact)
+  LOCALES = Locale.list(Rails.root.join("vendor/assets/iD/iD/locales").entries.map { |p| p.basename.to_s[/(.*).json/] && Regexp.last_match(1) }.compact)
 end
index 0b01daf2964bad39810e284874c9d30a950660bf..f481e4412da7517b835b9d3200158fb6ff05fee4 100644 (file)
@@ -178,7 +178,7 @@ module Potlatch
       presettype = ""
       presetcategory = ""
       #  StringIO.open(txt) do |file|
-      File.open(Rails.root.join("config", "potlatch", "presets.txt")) do |file|
+      File.open(Rails.root.join("config/potlatch/presets.txt")) do |file|
         file.each_line do |line|
           t = line.chomp
           if t =~ %r{(\w+)/(\w+)}
@@ -202,7 +202,7 @@ module Potlatch
       colours = {}
       casing = {}
       areas = {}
-      File.open(Rails.root.join("config", "potlatch", "colours.txt")) do |file|
+      File.open(Rails.root.join("config/potlatch/colours.txt")) do |file|
         file.each_line do |line|
           next unless line.chomp =~ /(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/
 
@@ -217,7 +217,7 @@ module Potlatch
       relcolours = {}
       relalphas = {}
       relwidths = {}
-      File.open(Rails.root.join("config", "potlatch", "relation_colours.txt")) do |file|
+      File.open(Rails.root.join("config/potlatch/relation_colours.txt")) do |file|
         file.each_line do |line|
           next unless line.chomp =~ /(\w+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/
 
@@ -231,7 +231,7 @@ module Potlatch
       # Read POI presets
       icon_list = []
       icon_tags = {}
-      File.open(Rails.root.join("config", "potlatch", "icon_presets.txt")) do |file|
+      File.open(Rails.root.join("config/potlatch/icon_presets.txt")) do |file|
         file.each_line do |line|
           (icon, tags) = line.chomp.split("\t")
           icon_list.push(icon)
@@ -242,7 +242,7 @@ module Potlatch
 
       # Read auto-complete
       autotags = { "point" => {}, "way" => {}, "POI" => {} }
-      File.open(Rails.root.join("config", "potlatch", "autocomplete.txt")) do |file|
+      File.open(Rails.root.join("config/potlatch/autocomplete.txt")) do |file|
         file.each_line do |line|
           next unless line.chomp =~ %r{^([\w:]+)/(\w+)\s+(.+)$}
 
index 11f639abd191a123d0b9db061b1631dbe38cc980..4762116f2c198dba6ed3606748ef7ae5b878def9 100644 (file)
@@ -1,6 +1,6 @@
 namespace "db" do
   desc "Adds a version number to the nodes table"
-  task :node_version do
+  task :node_version => :environment do
     require File.dirname(__FILE__) + "/../../config/environment"
 
     increment = 1000
index 954acbf227dc1a6309c5d47ff341d9e249ae9f3b..70bc391a0ab0672d944dadfa7ad1ec2535babeb8 100644 (file)
@@ -2,7 +2,7 @@
 # NOTE: are sensitive to local FS writes, and besides -- it's just not proper
 # NOTE: to have a dev-mode tool do its thing in production.
 if Rails.env.development?
-  task :set_annotation_options do
+  task :set_annotation_options => :environment do
     # You can override any of these by setting an environment variable of the
     # same name.
     Annotate.set_defaults(
index 311d79c76ab9bb5057d7a3e8bc9af28fd3e45aa4..320651b5a3fd615818d56f600e5df359d2b69393 100644 (file)
@@ -2,11 +2,11 @@ task "eslint" => "eslint:check"
 
 namespace "eslint" do
   def yarn_path
-    Rails.root.join("bin", "yarn").to_s
+    Rails.root.join("bin/yarn").to_s
   end
 
   def config_file
-    Rails.root.join("config", "eslint.json").to_s
+    Rails.root.join("config/eslint.json").to_s
   end
 
   def js_files
index c9b384cfe48e8ee9c4067949759dd20021bf5cd9..720530256e59494ceac956fb43d828c177031e90 100644 (file)
@@ -1,4 +1,4 @@
-task "test" do
+task :test => :environment do
   Rails::TestUnit::Runner.rake_run(["test/system"]) unless ENV.key?("TEST")
 end
 
index 80b9d1a8458a445e2719c2059a8c2eefe72d49d9..53964b2db0f4ebccfe36ba57ded0e80d8ac29e71 100644 (file)
@@ -178,7 +178,7 @@ module Api
     # Test creating a trace through the api
     def test_create
       # Get file to use
-      fixture = Rails.root.join("test", "gpx", "fixtures", "a.gpx")
+      fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
       file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
       user = create(:user)
 
index 059242af9957357f460078dd9981a9d6765d4c4d..312d451d7e328cc37ea8d052effada071d4a88e6 100644 (file)
@@ -532,7 +532,7 @@ class TracesControllerTest < ActionController::TestCase
   # Test creating a trace
   def test_create_post
     # Get file to use
-    fixture = Rails.root.join("test", "gpx", "fixtures", "a.gpx")
+    fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
     file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
     user = create(:user)
 
@@ -564,7 +564,7 @@ class TracesControllerTest < ActionController::TestCase
   # Test creating a trace with validation errors
   def test_create_post_with_validation_errors
     # Get file to use
-    fixture = Rails.root.join("test", "gpx", "fixtures", "a.gpx")
+    fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
     file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
     user = create(:user)
 
index 42bfa6ddafaf7737c8152440ea1bc7092f3fe136..e0c65e33eeb58884dd23a9ebdbc1d7a909a53660 100644 (file)
@@ -157,7 +157,7 @@ class TraceTest < ActiveSupport::TestCase
   end
 
   def test_large_picture
-    picture = File.read(Rails.root.join("test", "gpx", "fixtures", "a.gif"), :mode => "rb")
+    picture = File.read(Rails.root.join("test/gpx/fixtures/a.gif"), :mode => "rb")
 
     trace = Trace.create
     trace.large_picture = picture
@@ -168,7 +168,7 @@ class TraceTest < ActiveSupport::TestCase
   end
 
   def test_icon_picture
-    picture = File.read(Rails.root.join("test", "gpx", "fixtures", "a_icon.gif"), :mode => "rb")
+    picture = File.read(Rails.root.join("test/gpx/fixtures/a_icon.gif"), :mode => "rb")
 
     trace = Trace.create
     trace.icon_picture = picture
@@ -184,7 +184,7 @@ class TraceTest < ActiveSupport::TestCase
 
   def test_import_removes_previous_tracepoints
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace = create(:trace, :fixture => "a")
       # Tracepoints don't have a primary key, so we use a specific latitude to
       # check for successful deletion
@@ -199,7 +199,7 @@ class TraceTest < ActiveSupport::TestCase
 
   def test_import_creates_tracepoints
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace = create(:trace, :fixture => "a")
       assert_equal 0, Tracepoint.where(:gpx_id => trace.id).count
 
@@ -216,7 +216,7 @@ class TraceTest < ActiveSupport::TestCase
 
   def test_import_creates_icon
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace = create(:trace, :fixture => "a")
       icon_path = File.join(Settings.gpx_image_dir, "#{trace.id}_icon.gif")
       FileUtils.rm(icon_path)
@@ -230,7 +230,7 @@ class TraceTest < ActiveSupport::TestCase
 
   def test_import_creates_large_picture
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace = create(:trace, :fixture => "a")
       large_picture_path = File.join(Settings.gpx_image_dir, "#{trace.id}.gif")
       FileUtils.rm(large_picture_path)
@@ -244,7 +244,7 @@ class TraceTest < ActiveSupport::TestCase
 
   def test_import_handles_bz2
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace = create(:trace, :fixture => "c")
 
       trace.import
@@ -255,7 +255,7 @@ class TraceTest < ActiveSupport::TestCase
 
   def test_import_handles_plain
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace = create(:trace, :fixture => "a")
 
       trace.import
@@ -266,7 +266,7 @@ class TraceTest < ActiveSupport::TestCase
 
   def test_import_handles_plain_with_bom
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace = create(:trace, :fixture => "b")
 
       trace.import
@@ -279,7 +279,7 @@ class TraceTest < ActiveSupport::TestCase
     trace = create(:trace, :fixture => "d")
 
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace.import
 
       assert_equal 1, trace.size
@@ -292,7 +292,7 @@ class TraceTest < ActiveSupport::TestCase
     trace = create(:trace, :fixture => "f")
 
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace.import
 
       assert_equal 2, trace.size
@@ -305,7 +305,7 @@ class TraceTest < ActiveSupport::TestCase
     trace = create(:trace, :fixture => "g")
 
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace.import
 
       assert_equal 2, trace.size
@@ -318,7 +318,7 @@ class TraceTest < ActiveSupport::TestCase
     trace = create(:trace, :fixture => "h")
 
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace.import
 
       assert_equal 2, trace.size
@@ -331,7 +331,7 @@ class TraceTest < ActiveSupport::TestCase
     trace = create(:trace, :fixture => "i")
 
     FakeFS do
-      FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
+      FakeFS::FileSystem.clone(Rails.root.join("test/gpx"))
       trace.import
 
       assert_equal 2, trace.size