LoginSignup
1
0

More than 1 year has passed since last update.

Rubocop のエラー解決法。Style/RedundantFetchBlock: in 'config/puma.rb' について

Last updated at Posted at 2021-04-30

そもそも、RedundantFetchBlock とは?

Redundant の語源

Re / d / und / ant

Re (繰り返し) + und(波)+ ant (名詞化させる接尾辞)

つまり「波が繰り返していること」

要するに「あふれていること」

もっとコンパクトに言うと「氾濫」

だから、RedundantFetchBlock とは、FetchBlock が「氾濫」していることを指している。

※ d は発音をスムーズに繋げるためのもので、ここでは無視。

エラー内容

$ rubocop --auto-gen-config

このコマンドを打つと、.rubocop_todo.yml に直すべき課題が与えられる。

rubocop_todo.yml
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: SafeForConstants.
Style/RedundantFetchBlock:
  Exclude:
    - 'config/puma.rb'

今回は、Style/RedundantFetchBlock: という課題が与えられた。

Exclude: で示されている 'config/puma.rb' を見に行こう。

config/puma.rb
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
port        ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }
plugin :tmp_restart

今回、「氾濫」しているというのは、2つ。

1行目

max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }

4行目

port        ENV.fetch("PORT") { 3000 }

これらを以下のように書き換える。

1行目(変更後)

max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)

4行目(変更後)

port        ENV.fetch('PORT', 3000)

修正したコード全文

config/puma.rb
max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
threads min_threads_count, max_threads_count
port        ENV.fetch('PORT', 3000)
environment ENV.fetch('RAILS_ENV') { 'development' }
pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }

これで氾濫は治まった。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0