troessner / reek

Code smell detector for Ruby
https://github.com/troessner/reek
MIT License
4.05k stars 280 forks source link

False positives for InstanceVariableAssumption when using before_action #1133

Closed oliverklee closed 8 years ago

oliverklee commented 8 years ago

We have a controller that basically looks like this (simplified)

class UsersController < ApplicationController
  before_action :find_user, only: [:edit, :update, :destroy]

  def find_user
    @user = Identity::User.find(params.fetch(:id))
  end

  def update
    @user.save
  end
end

For this controller, Reek complains: InstanceVariableAssumption: Admin::UsersController assumes too much for instance variable '@user' [https://github.com/troessner/reek/blob/master/docs/Instance-Variable-Assumption.md]

I consider this a false positive. Reek should register the before_action that sets the user instance variable.

mvz commented 8 years ago

Hello @oliverklee, thanks for your bug report. Rails encourages some special patterns that will cause Reek to report smells. Please see the section Working with Rails in the README for details on which detectors we recommend you to disable.

oliverklee commented 8 years ago

@mvz Oh, I totally missed that addition to that section in the README. Thanks for the pointer!