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

Several auto-correction/offense disparities in Style/TrivialAccessors #1580

Closed
lumeet opened this issue Jan 18, 2015 · 3 comments
Closed

Several auto-correction/offense disparities in Style/TrivialAccessors #1580

lumeet opened this issue Jan 18, 2015 · 3 comments
Labels

Comments

@lumeet
Copy link
Contributor

lumeet commented Jan 18, 2015

I've found all of the following usages in a form or another in real code.

# encoding: utf-8
# test_trivial_methods.rb
# Auto-correction failing in this class.
class MyTrivialMethods
  def one_value
    @another_value
  end

  def good?
    @good
  end

  def value(value)
    @value = value
  end

  def store_my_block(&block)
    @block = block
  end
end

Then...

$ bin/rubocop --auto-correct -f s test_trivial_methods.rb
== test_trivial_methods.rb ==
C:  5:  3: [Corrected] Use attr_reader to define trivial reader methods.
C:  9:  3: [Corrected] Use attr_reader to define trivial reader methods.
C: 13:  3: [Corrected] Use attr_writer to define trivial writer methods.
C: 17:  3: [Corrected] Use attr_writer to define trivial writer methods.

1 file inspected, 4 offenses detected, 4 offenses corrected

...but nothing is actually changed. What do you think should be the correct behavior here? Spontaneously, I find at least methods 2-4 useful in some contexts, and while number 1 doesn't feel like a good idea, there might be reasons to do that, too.

@glittershark
Copy link

👍

@jonas054
Copy link
Collaborator

@lumeet You can allow all those methods with the following configuration:

Style/TrivialAccessors:
  ExactNameMatch: true
  AllowDSLWriters: true

The fact that [Corrected] is printed when nothing was changed is a bug, though.

@jonas054 jonas054 added the bug label Jan 21, 2015
@lumeet
Copy link
Contributor Author

lumeet commented Jan 22, 2015

Thanks, @jonas054. I'm still forgetting all the configs. Anyway, I can try to fix the bug a bit later unless someone else is quick to do it before me.

bbatsov added a commit that referenced this issue Jan 31, 2015
[Fix #1580] Use fail instead of return in TrivialAccessors#autocorrect
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

3 participants