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

Lint/UselessAccessModifier doesn't recognize conditionally defined methods #3049

Closed
bquorning opened this issue Apr 14, 2016 · 0 comments
Closed

Comments

@bquorning
Copy link
Contributor

When a class or module uses if to conditionally define a private method, the Lint/UselessAccessModifier cop seems to thing that the private access modifier is useless.

Expected behavior

No offenses.

Actual behavior

One offense:

test.rb:8:3: W: Useless private access modifier.
  private
  ^^^^^^^

Steps to reproduce the problem

Run rubocop on this (contrived) test.rb file:

# encoding: utf-8
# frozen_string_literal: true
class Foo
  def initialize
    puts value
  end

  private

  if defined?(Bar)
    def value
      true
    end
  else
    def value
      false
    end
  end
end

RuboCop version

» bin/rubocop -V
0.39.0 (using Parser 2.3.0.7, running on ruby 2.3.0 x86_64-darwin15)
» git log -1 --pretty=format:'%H'
3564db025d475397ab2a0ebb9d584a114421c198
owst added a commit to owst/rubocop that referenced this issue Apr 26, 2016
- Add detection of conditionally defined methods,
- Add detection of dynamically defined methods,
- Ensure singleton class methods are handled correctly,
- DRY up some repetition in specs.
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
- Add detection of conditionally defined methods,
- Add detection of dynamically defined methods,
- Ensure singleton class methods are handled correctly,
- DRY up some repetition in specs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant