From 550b71ba4618e814236878e1720a471f7779c974 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 16 Jun 2023 15:55:57 +1200 Subject: [PATCH] refactor: prefer to always use `raise` (#437) --- .rubocop.yml | 4 ++-- ci/bin/build-and-test | 2 +- template.rb | 8 ++++---- .../app/controllers/active_storage/base_controller.rb | 2 +- variants/backend-base/config/initializers/check_env.rb | 4 ++-- variants/backend-base/rubocop.yml.tt | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index cdaf6081..caac2cfb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -46,9 +46,9 @@ Metrics/MethodLength: Naming/VariableNumber: Enabled: false -# We prefer that you use `fail` unless you're explicitly re-raising an exception. +# Just always use `raise` and stop thinking about it. Style/SignalException: - EnforcedStyle: semantic + EnforcedStyle: only_raise # We think that: # hash = { diff --git a/ci/bin/build-and-test b/ci/bin/build-and-test index f02ae1aa..749e9c2b 100755 --- a/ci/bin/build-and-test +++ b/ci/bin/build-and-test @@ -23,7 +23,7 @@ puts <<~EO_CONFIG_SUMMARY EO_CONFIG_SUMMARY puts "=" * 80 -fail "Missing config YML file" unless File.exist?(config_path) & File.file?(config_path) +raise "Missing config YML file" unless File.exist?(config_path) & File.file?(config_path) puts "Installing latest rails gem" system "gem install rails --no-document" diff --git a/template.rb b/template.rb index d0259cbc..23730249 100644 --- a/template.rb +++ b/template.rb @@ -297,16 +297,16 @@ def assert_valid_options next unless options.key?(key) actual = options[key] - fail Rails::Generators::Error, "Unsupported option: #{key}=#{actual}" unless actual == expected + raise Rails::Generators::Error, "Unsupported option: #{key}=#{actual}" unless actual == expected end end def assert_postgresql return if /^\s*gem ['"]pg['"]/.match?(File.read("Gemfile")) - fail Rails::Generators::Error, - "This template requires PostgreSQL, " \ - "but the pg gem isn't present in your Gemfile." + raise Rails::Generators::Error, + "This template requires PostgreSQL, " \ + "but the pg gem isn't present in your Gemfile." end def any_local_git_commits? diff --git a/variants/backend-base/app/controllers/active_storage/base_controller.rb b/variants/backend-base/app/controllers/active_storage/base_controller.rb index 7384d94a..3dd06016 100644 --- a/variants/backend-base/app/controllers/active_storage/base_controller.rb +++ b/variants/backend-base/app/controllers/active_storage/base_controller.rb @@ -20,7 +20,7 @@ class ActiveStorage::BaseController < ActionController::Base # rubocop:disable R # removed. If not then code should be added to only serve files appropriately. # https://edgeguides.rubyonrails.org/active_storage_overview.html#proxy-mode def authenticated? - fail StandardError, "No authentication is configured for ActiveStorage" + raise StandardError, "No authentication is configured for ActiveStorage" end end # :nocov: diff --git a/variants/backend-base/config/initializers/check_env.rb b/variants/backend-base/config/initializers/check_env.rb index 9bed9695..1f8819de 100644 --- a/variants/backend-base/config/initializers/check_env.rb +++ b/variants/backend-base/config/initializers/check_env.rb @@ -3,6 +3,6 @@ # RAILS_SECRET_KEY_BASE should be set to something other than its value in example.env if Rails.env.production? && Rails.root.join("example.env").read.include?(ENV.fetch("RAILS_SECRET_KEY_BASE")) - fail "RAILS_SECRET_KEY_BASE is unchanged from example.env. " \ - "Generate a new one with `bundle exec rails secret`" + raise "RAILS_SECRET_KEY_BASE is unchanged from example.env. " \ + "Generate a new one with `bundle exec rails secret`" end diff --git a/variants/backend-base/rubocop.yml.tt b/variants/backend-base/rubocop.yml.tt index 58f3155b..3f092122 100644 --- a/variants/backend-base/rubocop.yml.tt +++ b/variants/backend-base/rubocop.yml.tt @@ -80,9 +80,9 @@ Rails/SkipsModelValidations: Naming/VariableNumber: Enabled: false -# We prefer that you use `fail` unless you're explicitly re-raising an exception. +# Just always use `raise` and stop thinking about it. Style/SignalException: - EnforcedStyle: semantic + EnforcedStyle: only_raise # We think that: # hash = {