miyohideの日記

技術的なメモなどを記しています

2023年4月14日 rubocopのMetrics/AbcSize

rubocopのMetrics/AbcSize

自作のRailsアプリに対してRubocopをかけてみたら以下の警告が。

app/controllers/todos_controller.rb:42:3: C: Metrics/AbcSize: Assignment Branch Condition size for update is too high. [<2, 19, 2> 19.21/17]
  def update ...

調べてみるとABC Sizeの警告だそうで。

docs.rubocop.org

ちなみに対象のコードはこれ。

  def update
    respond_to do |format|
      if @todo.update(todo_params)
        format.html { redirect_to todo_url(@todo), notice: 'Todo was successfully updated.' }
        format.turbo_stream { flash.now.notice = 'Todo updated!' }
        format.json { render :show, status: :ok, location: @todo }
      else
        format.html { render :edit, status: :unprocessable_entity }
        format.turbo_stream { render :edit, status: :unprocessable_entity }
        format.json { render json: @todo.errors, status: :unprocessable_entity }
      end
    end
  end

設定変更して無効化してもいいんだけれども、どうしようかなぁ。