From 8fd3fc404dd848253767252bbd76275e091832b1 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Tue, 21 Feb 2023 19:57:15 -0500 Subject: [PATCH] Autofix Rubocop Rails/RootPathnameMethods (#23760) --- .rubocop_todo.yml | 12 ------------ lib/mastodon/premailer_webpack_strategy.rb | 2 +- lib/tasks/emojis.rake | 2 +- lib/tasks/mastodon.rake | 2 +- lib/tasks/repo.rake | 6 +++--- spec/fabricators/custom_emoji_fabricator.rb | 2 +- spec/fabricators/site_upload_fabricator.rb | 2 +- spec/rails_helper.rb | 4 ++-- 8 files changed, 10 insertions(+), 22 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a72606b35..bbf01bacf 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1801,18 +1801,6 @@ Rails/ReversibleMigration: - 'db/migrate/20180617162849_remove_unused_indexes.rb' - 'db/migrate/20220827195229_change_canonical_email_blocks_nullable.rb' -# Offense count: 10 -# This cop supports unsafe autocorrection (--autocorrect-all). -Rails/RootPathnameMethods: - Exclude: - - 'lib/mastodon/premailer_webpack_strategy.rb' - - 'lib/tasks/emojis.rake' - - 'lib/tasks/mastodon.rake' - - 'lib/tasks/repo.rake' - - 'spec/fabricators/custom_emoji_fabricator.rb' - - 'spec/fabricators/site_upload_fabricator.rb' - - 'spec/rails_helper.rb' - # Offense count: 141 # Configuration parameters: ForbiddenMethods, AllowedMethods. # ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all diff --git a/lib/mastodon/premailer_webpack_strategy.rb b/lib/mastodon/premailer_webpack_strategy.rb index 4356b7285..5c297d4d0 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.public_path.join(url)) + Rails.public_path.join(url).read end css.gsub(/url\(\//, "url(#{asset_host}/") diff --git a/lib/tasks/emojis.rake b/lib/tasks/emojis.rake index 02d772b48..c743f8a55 100644 --- a/lib/tasks/emojis.rake +++ b/lib/tasks/emojis.rake @@ -69,7 +69,7 @@ namespace :emojis do end end - existence_maps = grouped_codes.map { |c| c.index_with { |cc| File.exist?(Rails.public_path.join('emoji', "#{codepoints_to_filename(cc)}.svg")) } } + existence_maps = grouped_codes.map { |c| c.index_with { |cc| Rails.public_path.join('emoji', "#{codepoints_to_filename(cc)}.svg").exist? } } map = {} existence_maps.each do |group| diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index 0a3946ac7..6c0e66922 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -445,7 +445,7 @@ namespace :mastodon do generated_header << "# using docker-compose or not.\n\n" end - File.write(Rails.root.join('.env.production'), "#{generated_header}#{env_contents}\n") + Rails.root.join('.env.production').write("#{generated_header}#{env_contents}\n") if using_docker prompt.ok 'Below is your configuration, save it to an .env.production file outside Docker:' diff --git a/lib/tasks/repo.rake b/lib/tasks/repo.rake index 795b54c59..5d1b4f754 100644 --- a/lib/tasks/repo.rake +++ b/lib/tasks/repo.rake @@ -5,7 +5,7 @@ REPOSITORY_NAME = 'mastodon/mastodon' namespace :repo do desc 'Generate the AUTHORS.md file' task :authors do - file = File.open(Rails.root.join('AUTHORS.md'), 'w') + file = Rails.root.join('AUTHORS.md').open('w') file << <<~HEADER Authors @@ -87,8 +87,8 @@ namespace :repo do task check_locales_files: :environment do pastel = Pastel.new - missing_yaml_files = I18n.available_locales.reject { |locale| File.exist?(Rails.root.join('config', 'locales', "#{locale}.yml")) } - missing_json_files = I18n.available_locales.reject { |locale| File.exist?(Rails.root.join('app', 'javascript', 'mastodon', 'locales', "#{locale}.json")) } + missing_yaml_files = I18n.available_locales.reject { |locale| Rails.root.join('config', 'locales', "#{locale}.yml").exist? } + missing_json_files = I18n.available_locales.reject { |locale| Rails.root.join('app', 'javascript', 'mastodon', 'locales', "#{locale}.json").exist? } locales_in_files = Dir[Rails.root.join('config', 'locales', '*.yml')].map do |path| file_name = File.basename(path) diff --git a/spec/fabricators/custom_emoji_fabricator.rb b/spec/fabricators/custom_emoji_fabricator.rb index 298a50b4b..fa570eec6 100644 --- a/spec/fabricators/custom_emoji_fabricator.rb +++ b/spec/fabricators/custom_emoji_fabricator.rb @@ -3,5 +3,5 @@ Fabricator(:custom_emoji) do shortcode 'coolcat' domain nil - image { File.open(Rails.root.join('spec', 'fixtures', 'files', 'emojo.png')) } + image { Rails.root.join('spec', 'fixtures', 'files', 'emojo.png').open } end diff --git a/spec/fabricators/site_upload_fabricator.rb b/spec/fabricators/site_upload_fabricator.rb index b6841dea3..ad1b777cc 100644 --- a/spec/fabricators/site_upload_fabricator.rb +++ b/spec/fabricators/site_upload_fabricator.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true Fabricator(:site_upload) do - file { File.open(File.join(Rails.root, 'spec', 'fabricators', 'assets', 'utah_teapot.png')) } + file { Rails.root.join('spec', 'fabricators', 'assets', 'utah_teapot.png').open } end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index faae02df0..70d3a968c 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -73,11 +73,11 @@ end RSpec::Matchers.define_negated_matcher :not_change, :change def request_fixture(name) - File.read(Rails.root.join('spec', 'fixtures', 'requests', name)) + Rails.root.join('spec', 'fixtures', 'requests', name).read end def attachment_fixture(name) - File.open(Rails.root.join('spec', 'fixtures', 'files', name)) + Rails.root.join('spec', 'fixtures', 'files', name).open end def stub_jsonld_contexts!