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

Releax the Rubocop::Cop::TrivialAccessors #211

Closed
famished-tiger opened this issue May 28, 2013 · 1 comment
Closed

Releax the Rubocop::Cop::TrivialAccessors #211

famished-tiger opened this issue May 28, 2013 · 1 comment

Comments

@famished-tiger
Copy link

This cop is a bit too strict.
Consider the following class:

class Foo
  attr_reader(:bar)
  def initialize(something)
    @bar = something
...

The cop complains about the initialization of the attribute bar: "Use attr_writer to define trivial writer methods."
The issue is that I want bar to have a public read-only accessor and no writer (this attribute is initialized once only in the constructor).
Following the advice from the cop, will oblige:
-Create a writer it should be kept private method.
-That simple writer will only be used in the constructor. Thus a writer method for one single calling method!...
This will add burden to the class.
In fact, the cop should be excluded for any attribute initialized in the constructor and that attribute is nowhere else updated. Easy to say, but I realize that's a challenging check to implement.

@bbatsov
Copy link
Collaborator

bbatsov commented May 28, 2013

That's actually a bug. I'll have it fixed tomorrow. This cop should simply ignore the initialize method.

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

2 participants