From 78b9d92207bb215459ecff466c3efe2fa6466ab3 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 11 Nov 2020 16:14:24 +0000 Subject: [PATCH] Prefer keyword arguments when method has optional boolean arguments --- .rubocop_todo.yml | 3 --- app/controllers/api/notes_controller.rb | 4 ++-- app/controllers/application_controller.rb | 10 +++++----- app/controllers/browse_controller.rb | 2 +- app/controllers/changeset_comments_controller.rb | 2 +- app/controllers/changesets_controller.rb | 2 +- app/controllers/users_controller.rb | 2 +- app/helpers/browse_helper.rb | 2 +- app/views/browse/changeset.html.erb | 6 +++--- 9 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f6d11c58f..67ef880c5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -176,9 +176,6 @@ Style/NumericLiterals: # Offense count: 20 Style/OptionalBooleanParameter: Exclude: - - 'app/controllers/api/notes_controller.rb' - - 'app/controllers/application_controller.rb' - - 'app/helpers/browse_helper.rb' - 'app/models/changeset.rb' - 'app/models/node.rb' - 'app/models/relation.rb' diff --git a/app/controllers/api/notes_controller.rb b/app/controllers/api/notes_controller.rb index f4d1d0dac..f480b9706 100644 --- a/app/controllers/api/notes_controller.rb +++ b/app/controllers/api/notes_controller.rb @@ -240,7 +240,7 @@ module Api @note.status = "hidden" @note.save - add_comment(@note, comment, "hidden", false) + add_comment(@note, comment, "hidden", :notify => false) end # Return a copy of the updated note @@ -369,7 +369,7 @@ module Api ## # Add a comment to a note - def add_comment(note, text, event, notify = true) + def add_comment(note, text, event, notify: true) attributes = { :visible => true, :event => event, :body => text } if current_user diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 052858932..9f2d79eaa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -84,7 +84,7 @@ class ApplicationController < ActionController::Base end end - def check_database_readable(need_api = false) + def check_database_readable(need_api: false) if Settings.status == "database_offline" || (need_api && Settings.status == "api_offline") if request.xhr? report_error "Database offline for maintenance", :service_unavailable @@ -94,7 +94,7 @@ class ApplicationController < ActionController::Base end end - def check_database_writable(need_api = false) + def check_database_writable(need_api: false) if Settings.status == "database_offline" || Settings.status == "database_readonly" || (need_api && (Settings.status == "api_offline" || Settings.status == "api_readonly")) if request.xhr? @@ -171,7 +171,7 @@ class ApplicationController < ActionController::Base end end - def preferred_languages(reset = false) + def preferred_languages(reset: false) @preferred_languages = nil if reset @preferred_languages ||= if params[:locale] Locale.list(params[:locale]) @@ -184,13 +184,13 @@ class ApplicationController < ActionController::Base helper_method :preferred_languages - def set_locale(reset = false) + def set_locale(reset: false) if current_user&.languages&.empty? && !http_accept_language.user_preferred_languages.empty? current_user.languages = http_accept_language.user_preferred_languages current_user.save end - I18n.locale = Locale.available.preferred(preferred_languages(reset)) + I18n.locale = Locale.available.preferred(preferred_languages(:reset => reset)) response.headers["Vary"] = "Accept-Language" response.headers["Content-Language"] = I18n.locale.to_s diff --git a/app/controllers/browse_controller.rb b/app/controllers/browse_controller.rb index 1bbf85adc..50d0ae0a5 100644 --- a/app/controllers/browse_controller.rb +++ b/app/controllers/browse_controller.rb @@ -3,7 +3,7 @@ class BrowseController < ApplicationController before_action :authorize_web before_action :set_locale - before_action -> { check_database_readable(true) } + before_action -> { check_database_readable(:need_api => true) } before_action :require_oauth around_action :web_timeout authorize_resource :class => false diff --git a/app/controllers/changeset_comments_controller.rb b/app/controllers/changeset_comments_controller.rb index 4abffb90e..0b5f6059a 100644 --- a/app/controllers/changeset_comments_controller.rb +++ b/app/controllers/changeset_comments_controller.rb @@ -4,7 +4,7 @@ class ChangesetCommentsController < ApplicationController authorize_resource - before_action -> { check_database_readable(true) } + before_action -> { check_database_readable(:need_api => true) } around_action :web_timeout ## diff --git a/app/controllers/changesets_controller.rb b/app/controllers/changesets_controller.rb index 5b6d3e010..7796dfeb2 100644 --- a/app/controllers/changesets_controller.rb +++ b/app/controllers/changesets_controller.rb @@ -6,7 +6,7 @@ class ChangesetsController < ApplicationController before_action :authorize_web before_action :set_locale - before_action -> { check_database_readable(true) }, :only => [:index, :feed] + before_action -> { check_database_readable(:need_api => true) }, :only => [:index, :feed] authorize_resource diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 288fb2d5c..7f12720a6 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -652,7 +652,7 @@ class UsersController < ApplicationController if user.save session[:fingerprint] = user.fingerprint - set_locale(true) + set_locale(:reset => true) if user.new_email.blank? || user.new_email == user.email flash.now[:notice] = t "users.account.flash update success" diff --git a/app/helpers/browse_helper.rb b/app/helpers/browse_helper.rb index 1e9465f80..0f533770b 100644 --- a/app/helpers/browse_helper.rb +++ b/app/helpers/browse_helper.rb @@ -1,5 +1,5 @@ module BrowseHelper - def printable_name(object, version = false) + def printable_name(object, version: false) id = if object.id.is_a?(Array) object.id[0] else diff --git a/app/views/browse/changeset.html.erb b/app/views/browse/changeset.html.erb index 35cd4477b..f58c465a7 100644 --- a/app/views/browse/changeset.html.erb +++ b/app/views/browse/changeset.html.erb @@ -90,7 +90,7 @@ <% end %> @@ -102,7 +102,7 @@ <% end %> @@ -114,7 +114,7 @@ <% end %> -- 2.39.5