From c92e033cdd3e1f5c20a8b297a2e72d26f8ddd26f Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Tue, 7 Feb 2023 19:10:25 -0500 Subject: Apply Rubocop Performance/BindCall (#23437) --- lib/active_record/database_tasks_extensions.rb | 2 +- lib/rails/engine_extensions.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/active_record/database_tasks_extensions.rb b/lib/active_record/database_tasks_extensions.rb index e274f476d..d52186113 100644 --- a/lib/active_record/database_tasks_extensions.rb +++ b/lib/active_record/database_tasks_extensions.rb @@ -11,7 +11,7 @@ module ActiveRecord ActiveRecord::Base.establish_connection(db_config) Mastodon::Snowflake.define_timestamp_id - original_load_schema.bind(self).call(db_config, *args) + original_load_schema.bind_call(self, db_config, *args) Mastodon::Snowflake.ensure_id_sequences_exist end diff --git a/lib/rails/engine_extensions.rb b/lib/rails/engine_extensions.rb index 4848b15f2..4e3767db9 100644 --- a/lib/rails/engine_extensions.rb +++ b/lib/rails/engine_extensions.rb @@ -2,7 +2,7 @@ module Rails module EngineExtensions # Rewrite task loading code to filter digitalocean.rake task def run_tasks_blocks(app) - Railtie.instance_method(:run_tasks_blocks).bind(self).call(app) + Railtie.instance_method(:run_tasks_blocks).bind_call(self, app) paths["lib/tasks"].existent.reject { |ext| ext.end_with?('digitalocean.rake') }.sort.each { |ext| load(ext) } end end -- cgit From 203739dd3adbfccf96c237bd8f4cf9cefc67ff94 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Tue, 7 Feb 2023 20:36:20 -0500 Subject: Apply Rubocop Performance/StringIdentifierArgument (#23444) --- app/lib/scope_transformer.rb | 2 +- lib/mastodon/statuses_cli.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/app/lib/scope_transformer.rb b/app/lib/scope_transformer.rb index fdfc6cf13..adcb711f8 100644 --- a/app/lib/scope_transformer.rb +++ b/app/lib/scope_transformer.rb @@ -28,7 +28,7 @@ class ScopeTransformer < Parslet::Transform def merge!(other_scope) raise ArgumentError unless other_scope.namespace == namespace && other_scope.term == term - @access.concat(other_scope.instance_variable_get('@access')) + @access.concat(other_scope.instance_variable_get(:@access)) @access.uniq! @access.sort! diff --git a/lib/mastodon/statuses_cli.rb b/lib/mastodon/statuses_cli.rb index d4c2e6cf2..baab83e29 100644 --- a/lib/mastodon/statuses_cli.rb +++ b/lib/mastodon/statuses_cli.rb @@ -93,7 +93,7 @@ module Mastodon c.table_name = 'statuses_to_be_deleted' end - Object.const_set('StatusToBeDeleted', klass) + Object.const_set(:StatusToBeDeleted, klass) scope = StatusToBeDeleted processed = 0 @@ -175,7 +175,7 @@ module Mastodon c.table_name = 'conversations_to_be_deleted' end - Object.const_set('ConversationsToBeDeleted', klass) + Object.const_set(:ConversationsToBeDeleted, klass) scope = ConversationsToBeDeleted processed = 0 -- cgit From f68bb52556fe90d7adad8db9ba8b801a22281f30 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Wed, 8 Feb 2023 01:07:36 -0500 Subject: Apply Rubocop Style/NegatedIfElseCondition (#23451) --- app/controllers/api/v1/streaming_controller.rb | 6 +++--- app/models/user.rb | 2 +- app/services/fetch_oembed_service.rb | 2 +- app/services/verify_link_service.rb | 2 +- lib/tasks/mastodon.rake | 12 ++++++------ 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/app/controllers/api/v1/streaming_controller.rb b/app/controllers/api/v1/streaming_controller.rb index 7cd60615a..b23a60170 100644 --- a/app/controllers/api/v1/streaming_controller.rb +++ b/app/controllers/api/v1/streaming_controller.rb @@ -2,10 +2,10 @@ class Api::V1::StreamingController < Api::BaseController def index - if Rails.configuration.x.streaming_api_base_url != request.host - redirect_to streaming_api_url, status: 301 - else + if Rails.configuration.x.streaming_api_base_url == request.host not_found + else + redirect_to streaming_api_url, status: 301 end end diff --git a/app/models/user.rb b/app/models/user.rb index d40044da3..c767f8984 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -265,7 +265,7 @@ class User < ApplicationRecord end def inactive_message - !approved? ? :pending : super + approved? ? super : :pending end def approve! diff --git a/app/services/fetch_oembed_service.rb b/app/services/fetch_oembed_service.rb index 7d0879c79..9851ac098 100644 --- a/app/services/fetch_oembed_service.rb +++ b/app/services/fetch_oembed_service.rb @@ -82,7 +82,7 @@ class FetchOEmbedService return if @endpoint_url.blank? body = Request.new(:get, @endpoint_url).perform do |res| - res.code != 200 ? nil : res.body_with_limit + res.code == 200 ? res.body_with_limit : nil end validate(parse_for_format(body)) if body.present? diff --git a/app/services/verify_link_service.rb b/app/services/verify_link_service.rb index f83a664d4..707aeb4e0 100644 --- a/app/services/verify_link_service.rb +++ b/app/services/verify_link_service.rb @@ -19,7 +19,7 @@ class VerifyLinkService < BaseService def perform_request! @body = Request.new(:get, @url).add_headers('Accept' => 'text/html').perform do |res| - res.code != 200 ? nil : res.body_with_limit + res.code == 200 ? res.body_with_limit : nil end end diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index 876383d7f..1184e5273 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -463,10 +463,10 @@ namespace :mastodon do prompt.say 'Running `RAILS_ENV=production rails db:setup` ...' prompt.say "\n\n" - if !system(env.transform_values(&:to_s).merge({ 'RAILS_ENV' => 'production', 'SAFETY_ASSURED' => '1' }), 'rails db:setup') - prompt.error 'That failed! Perhaps your configuration is not right' - else + if system(env.transform_values(&:to_s).merge({ 'RAILS_ENV' => 'production', 'SAFETY_ASSURED' => '1' }), 'rails db:setup') prompt.ok 'Done!' + else + prompt.error 'That failed! Perhaps your configuration is not right' end end @@ -479,10 +479,10 @@ namespace :mastodon do prompt.say 'Running `RAILS_ENV=production rails assets:precompile` ...' prompt.say "\n\n" - if !system(env.transform_values(&:to_s).merge({ 'RAILS_ENV' => 'production' }), 'rails assets:precompile') - prompt.error 'That failed! Maybe you need swap space?' - else + if system(env.transform_values(&:to_s).merge({ 'RAILS_ENV' => 'production' }), 'rails assets:precompile') prompt.say 'Done!' + else + prompt.error 'That failed! Maybe you need swap space?' end end end -- cgit From 11557d1c5a4ecb44cf602eabf0c9bd2882514b3a Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Wed, 8 Feb 2023 04:38:07 -0500 Subject: Apply Rubocop Rails/RootPublicPath (#23447) --- lib/mastodon/premailer_webpack_strategy.rb | 2 +- lib/tasks/assets.rake | 2 +- lib/tasks/branding.rake | 4 ++-- lib/tasks/emojis.rake | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/mastodon/premailer_webpack_strategy.rb b/lib/mastodon/premailer_webpack_strategy.rb index 56ef09c1a..4356b7285 100644 --- a/lib/mastodon/premailer_webpack_strategy.rb +++ b/lib/mastodon/premailer_webpack_strategy.rb @@ -13,7 +13,7 @@ module PremailerWebpackStrategy HTTP.get(url).to_s else url = url[1..-1] if url.start_with?('/') - File.read(Rails.root.join('public', url)) + File.read(Rails.public_path.join(url)) end css.gsub(/url\(\//, "url(#{asset_host}/") diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index b642510a1..1d2270572 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -8,7 +8,7 @@ end namespace :assets do desc 'Generate static pages' task generate_static_pages: :environment do - render_static_page 'errors/500', layout: 'error', dest: Rails.root.join('public', 'assets', '500.html') + render_static_page 'errors/500', layout: 'error', dest: Rails.public_path.join('assets', '500.html') end end diff --git a/lib/tasks/branding.rake b/lib/tasks/branding.rake index 2eec7c9e1..d1c1c9ded 100644 --- a/lib/tasks/branding.rake +++ b/lib/tasks/branding.rake @@ -54,7 +54,7 @@ namespace :branding do rsvg_convert.run(size: size, input: favicon_source, output: output_path) end - convert.run(input: favicons, output: Rails.root.join('public', 'favicon.ico')) + convert.run(input: favicons, output: Rails.public_path.join('favicon.ico')) apple_icon_sizes.each do |size| rsvg_convert.run(size: size, input: app_icon_source, output: output_dest.join("apple-touch-icon-#{size}x#{size}.png")) @@ -69,7 +69,7 @@ namespace :branding do task generate_app_badge: :environment do rsvg_convert = Terrapin::CommandLine.new('rsvg-convert', '--stylesheet :stylesheet -w :size -h :size --keep-aspect-ratio :input -o :output') badge_source = Rails.root.join('app', 'javascript', 'images', 'logo-symbol-icon.svg') - output_dest = Rails.root.join('public') + output_dest = Rails.public_path stylesheet = Rails.root.join('lib', 'assets', 'wordmark.light.css') rsvg_convert.run(stylesheet: stylesheet, input: badge_source, size: 192, output: output_dest.join('badge.png')) diff --git a/lib/tasks/emojis.rake b/lib/tasks/emojis.rake index 473aee9cc..02d772b48 100644 --- a/lib/tasks/emojis.rake +++ b/lib/tasks/emojis.rake @@ -1,8 +1,8 @@ # frozen_string_literal: true def gen_border(codepoint, color) - input = Rails.root.join('public', 'emoji', "#{codepoint}.svg") - dest = Rails.root.join('public', 'emoji', "#{codepoint}_border.svg") + input = Rails.public_path.join('emoji', "#{codepoint}.svg") + dest = Rails.public_path.join('emoji', "#{codepoint}_border.svg") doc = File.open(input) { |f| Nokogiri::XML(f) } svg = doc.at_css('svg') if svg.key?('viewBox') @@ -69,7 +69,7 @@ namespace :emojis do end end - existence_maps = grouped_codes.map { |c| c.index_with { |cc| File.exist?(Rails.root.join('public', 'emoji', "#{codepoints_to_filename(cc)}.svg")) } } + existence_maps = grouped_codes.map { |c| c.index_with { |cc| File.exist?(Rails.public_path.join('emoji', "#{codepoints_to_filename(cc)}.svg")) } } map = {} existence_maps.each do |group| -- cgit