From bcc4b1078cf44515ef1b4193b004cb94ecfd288c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 26 Aug 2024 03:35:07 -0400 Subject: [PATCH] Fix `Rails/RootPathnameMethods` cop (#31582) --- db/seeds.rb | 2 +- lib/tasks/branding.rake | 2 +- lib/tasks/icons.rake | 2 +- lib/tasks/repo.rake | 2 +- spec/rails_helper.rb | 2 +- spec/spec_helper.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 370790e51..9d25ef0a4 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true Chewy.strategy(:mastodon) do - Dir[Rails.root.join('db', 'seeds', '*.rb')].each do |seed| + Rails.root.glob('db/seeds/*.rb').each do |seed| load seed end end diff --git a/lib/tasks/branding.rake b/lib/tasks/branding.rake index be72454ce..1e2af1b44 100644 --- a/lib/tasks/branding.rake +++ b/lib/tasks/branding.rake @@ -15,7 +15,7 @@ namespace :branding do output_dest = Rails.root.join('app', 'javascript', 'images', 'mailer') # Displayed size is 64px, at 3x it's 192px - Dir[Rails.root.join('app', 'javascript', 'images', 'icons', '*.svg')].each do |path| + Rails.root.glob('app/javascript/images/icons/*.svg').each do |path| rsvg_convert.run(input: path, size: 192, output: output_dest.join("#{File.basename(path, '.svg')}.png")) end diff --git a/lib/tasks/icons.rake b/lib/tasks/icons.rake index 374ea149f..96e0a1431 100644 --- a/lib/tasks/icons.rake +++ b/lib/tasks/icons.rake @@ -20,7 +20,7 @@ end def find_used_icons icons_by_weight_and_size = {} - Dir[Rails.root.join('app', 'javascript', '**', '*.*s*')].map do |path| + Rails.root.glob('app/javascript/**/*.*s*').map do |path| File.open(path, 'r') do |file| pattern = %r{\Aimport .* from '@/material-icons/(?[0-9]+)-(?[0-9]+)px/(?[^-]*)(?-fill)?.svg\?react';} file.each_line do |line| diff --git a/lib/tasks/repo.rake b/lib/tasks/repo.rake index b90b48934..539c44273 100644 --- a/lib/tasks/repo.rake +++ b/lib/tasks/repo.rake @@ -98,7 +98,7 @@ namespace :repo do 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| + locales_in_files = Rails.root.glob('config/locales/*.yml').map do |path| file_name = File.basename(path, '.yml') file_name.gsub(/\A(doorkeeper|devise|activerecord|simple_form)\./, '').to_sym end.uniq.compact diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index d4b9bddf9..9af2d1e33 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -44,7 +44,7 @@ require 'chewy/rspec' require 'email_spec/rspec' require 'test_prof/recipes/rspec/before_all' -Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } +Rails.root.glob('spec/support/**/*.rb').each { |f| require f } ActiveRecord::Migration.maintain_test_schema! WebMock.disable_net_connect!( diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1f9cc40f1..496ebfd09 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,7 +28,7 @@ RSpec.configure do |config| end config.after :suite do - FileUtils.rm_rf(Dir[Rails.root.join('spec', 'test_files')]) + FileUtils.rm_rf(Rails.root.glob('spec/test_files')) end # Use the GitHub Annotations formatter for CI