Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Autofix Rubocop Rails/RootPathnameMethods (mastodon#23760)
Browse files Browse the repository at this point in the history
  • Loading branch information
nschonni authored Feb 22, 2023
1 parent 48aeab9 commit 8fd3fc4
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 22 deletions.
12 changes: 0 additions & 12 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/mastodon/premailer_webpack_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def load(url)
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}/")
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/emojis.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/mastodon.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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:'
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/repo.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/fabricators/custom_emoji_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/fabricators/site_upload_fabricator.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def sign_in(resource, _deprecated = nil, scope: nil)
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!
Expand Down

0 comments on commit 8fd3fc4

Please sign in to comment.