Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent reporting for FeatureEnvy #1337

Closed
klobuczek opened this issue Jun 11, 2018 · 9 comments
Closed

Inconsistent reporting for FeatureEnvy #1337

klobuczek opened this issue Jun 11, 2018 · 9 comments
Assignees
Labels

Comments

@klobuczek
Copy link

The following code

class << self
  def normalize_path(scope, path)
    path_desc = new(scope)
    path_desc.increment(path.shift) while path_desc.next? && path.present?
    path_desc if path.empty?
  end
end

raises JsonapiExt::Scoping::Include::PathDescriptor#normalize_path refers to 'path' more than self (maybe move it to another class?)

however, if I rewrite it to:

def self.normalize_path(scope, path)
  path_desc = new(scope)
  path_desc.increment(path.shift) while path_desc.next? && path.present?
  path_desc if path.empty?
end

it does not.

@mvz mvz changed the title Inconsistent issue reporting. Class methods not detected for all cases Jun 12, 2018
@mvz mvz added the defect label Jun 12, 2018
@mvz mvz changed the title Class methods not detected for all cases Inconsistent reporting for FeatureEnvy Jun 12, 2018
@mvz mvz self-assigned this Jun 12, 2018
@mvz
Copy link
Collaborator

mvz commented Jun 13, 2018

I've looked into this and it's super easy to make this consistent. The change doesn't even break any of our tests, which shows that we completely missed this 😆.

@pardaloupa
Copy link

pardaloupa commented Jul 12, 2018

This problem seems to still occur when dealing with private_class_method used within a module.

module Admins
  class << self
    private
      attr_reader: users
  end

  module_function
  ...
  
  def show_active_users
   ...
   active = active_users
   ...
  end

  private_class_method
    
  def users
    @users ||=[]
  end
  
  def active_users
    active =
      users
        .select { |user| user.deleted? == false }
    active.map { |user| user.visible = true
   
    Workspace.fetch_users(active) unless active.empty?
  end
end

refers to 'user' more than self (maybe move it to another class?)

Goes away if I use self.

@mvz
Copy link
Collaborator

mvz commented Jul 12, 2018

@pardaloupa AIUI, private_class_method doesn't work without arguments.

@pardaloupa
Copy link

pardaloupa commented Jul 12, 2018

Wow, I never realized that... Ruby never complained.

Is this is how you are supposed to use it?

module Admins
  class << self
    private
      attr_reader: users
  end

  module_function
  ...
  
  def show_active_users
   ...
   active = active_users
   ...
  end
    
  def users
    @users ||=[]
  end
  
  def active_users
    active =
      users
        .select { |user| user.deleted? == false }
    active.map { |user| user.visible = true
   
    Workspace.fetch_users(active) unless active.empty?
  end
  private_class_method :active_users
end

If that is right, reek still complains 😞

Edit: all the examples I have seen seem to be using self then passing it over to private_class_method. Maybe is actually required?

@pardaloupa
Copy link

I am really confused on how to use module_function with private class methods.

This comment clears things up by using extending self / private combo instead of module_function and private_class_method but goes against the ruby style guideline... Not sure if it is a reek problem now... Any suggestions would be highly appreciated.

@mvz
Copy link
Collaborator

mvz commented Jul 12, 2018

If that is right, reek still complains

Ok, now that is a valid bug 😆.

@pardaloupa
Copy link

pardaloupa commented Jul 12, 2018

Great thanks for confirming it @mvz then I guess I will keep using module_function and private_class_method and the reek issues will vanish once a bug fix is pushed. Let me know if you need me to open a new issue as this is hard to track 👍

Edit: Same issue occurs with module_function methods

@mvz
Copy link
Collaborator

mvz commented Jul 13, 2018

@pardaloupa yes if you could open a new issue with your example code that would be great!

@pardaloupa
Copy link

@mvz done #1397 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants