Questions tagged [reek]

Reek, the code smell detector for Ruby

Reek is a tool that examines Ruby classes, modules and methods and reports any Code Smells it finds.

24 questions
8
votes
3 answers

Boolean parameters in methods. Why not?

I'm using reek as an analyzing tool for best practices in my code. However recently I found that if in the method, I have boolean parameters, such as. def method (flag = true) reek gives me a warning. Why does reek tell me that it is a warning?
Jackie Chan
  • 2,654
  • 6
  • 35
  • 70
4
votes
2 answers

NilCheck fix on safe navigation operator (&.)

This simple method on a class just run the status method using the safe navigation operator. def current_status account&.status end But reek report this warning: MyClass#current_status performs a nil-check…
AndreDurao
  • 5,600
  • 7
  • 41
  • 61
4
votes
1 answer

How can I make this method more concise?

I get a warning when running reek on a Rails project: [36]:ArborReloaded::UserStoryService#destroy_stories has approx 8 statements (TooManyStatements) Here's the method: def destroy_stories(project_id, user_stories) errors = [] @project =…
3
votes
4 answers

Ruby: Using Reek as a Training Tool

Would Reek be useful in training a ruby noob in good practices or does it require an experienced ruby eye to use and interpret? I have mumble-muble years or programing experience but mostly in C variants. I've used Ruby lightly for the last few…
TechZen
  • 64,370
  • 15
  • 118
  • 145
3
votes
3 answers

InstanceVariableAssumption: UsersController assumes too much for instance variable '@user'

I'm following Michael Hartl tutorial Rails course. On chapter 7, I run Reek on UsersController and I got this following warning: app/controllers/users_controller.rb -- 1 warning: 1:InstanceVariableAssumption: UsersController assumes too much for …
truongnm
  • 2,311
  • 2
  • 31
  • 48
3
votes
1 answer

How to rectify DuplicateMethodCall from reek

How to rectify DuplicateMethodCall from reek on the following calls def to_str foo.blank? ? 'Value' : foo end How should I handle params[:some] should I declare it separately. if params[:some] == 'Action1' elsif params[:some] ==…
Sam
  • 8,387
  • 19
  • 62
  • 97
2
votes
1 answer

disable inline or per method reek code smell detector

Is there a way to disable warning from reek gem per method, per line or per block? What we have for rubocop for example # suppress warning Use snake_case for method names def fooBar(baz) # rubocop:disable Naming/MethodName baz end this example…
zhisme
  • 2,368
  • 2
  • 19
  • 28
2
votes
1 answer

Remove writable attribute warning - Reek

The model is defined as follows attr_accessor :delay_type, :stop_type This raises the following warning by reek Order#stop_type is a writable attribute Any idea on how to fix this?
prajeesh
  • 2,202
  • 6
  • 34
  • 59
2
votes
2 answers

refactoring Control Parameter

I'm using a tool for finding code smells in code called reek and I have a problem with one called Control Parameter def place_ship(ship, start_position, orientation) @row = start_position[:row] @column = start_position[:column] …
2
votes
1 answer

Rails - FeatureEnvy: ApplicationHelper#full_title refers to 'page_title' more than self (maybe move it to another class?)

I'm learning Rails course by Michael Hartl, on chapter 4, I have function full_title as following: app/helpers/application_helper.rb module ApplicationHelper def full_title page_title = "" base_title = t "app_name" page_title.empty? ?…
truongnm
  • 2,311
  • 2
  • 31
  • 48
2
votes
0 answers

Getting rid of FeatureEnvy when dealing with data in a method

I'm often encountering methods where the handling of data is necessary in order to achieve certain process, in general something like: def process_something(data_from_external_service) request_params = { param1:…
Alexander Fradiani
  • 1,001
  • 3
  • 13
  • 33
2
votes
2 answers

Reek error RepeatedConditional

I have below error: tests @action.placed.!=(true) at least 3 times (RepeatedConditional) Generated from below code: def left super unless @action.placed != true end def right super unless @action.placed != true …
Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168
2
votes
4 answers

If we cache params into a local var in an action, will it help or its the same?

So we run a code quality tool called reek once in a while as part of our project. The tool basically looks for code smells and reports them. Here, we observed that we get "Duplication" smell every time we try to access a key in params more than once…
Chirantan
  • 15,304
  • 8
  • 49
  • 75
1
vote
1 answer

Feature Envy when Mixing in Modules

I'm currently writing a very simple start to a test tool. The idea is that you can have classes that include my "Testable" module. For example: class Veilus include Testable end site = Veilus.new The Testable module has the following: module…
Jeff Nyman
  • 870
  • 2
  • 12
  • 31
1
vote
1 answer

reek complaints for DuplicateMethodCall format.json

I have this code reek complains for DuplicateMethodCall (calls format.json twice) if object_error.blank? format.json { render json: order } else format.json { render json: object_error, status: :unprocessable_entity } end What is the best way…
Chris Ian
  • 771
  • 1
  • 7
  • 19
1
2