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

Allow Layout/EmptyLineAroundAttributeAccessor cop to ignore immediate keyword declarations #7976

Closed
ashmaroli opened this issue May 15, 2020 · 0 comments · Fixed by #7982
Closed
Assignees

Comments

@ashmaroli
Copy link

Is your feature request related to a problem? Please describe.

Say, I have the following class;

class Foo
  attr_reader :alpha, :beta
  private :beta

  attr_accessor :gamma
  alias_method :delta=, :gamma=
end

Layout/EmptyLineAroundAttributeAccessor cop recommends that my class be refactored into:

class Foo
  attr_reader :alpha, :beta

  private :beta

  attr_accessor :gamma

  alias_method :delta=, :gamma=
end

which IMHO has poorer readability compared to the original.

Describe the solution you'd like

A config option to allow having keywords such as private, protected, public, alias, alias_method, etc to immediately follow the attr*.
(N.B.: I don't want to enforce this, just have such occurrences ignored by the cop)

Describe alternatives you've considered

Exclude the file for the cop in .rubocop.yml

@koic koic self-assigned this May 15, 2020
koic added a commit to koic/rubocop that referenced this issue May 17, 2020
…ributeAccessor`

Fixes rubocop#7976 and rubocop#7981

This PR adds `AllowAliasSyntax` and `AllowedMethods` options.
for `Layout/EmptyLinesAroundAttributeAccessor` cop.

Users can configure a behavior for `alias` syntax using
`IgnoreAliasSyntax` option. Ignored by default (true).

And users can specify ignored methods using `AllowedMethods`.
By default, set `alias_method`, `public`, `protected`, and
`private` provided by Ruby.

`cattr_accessor`, `attribute`, other methods provided by Rails (and other gems)
can be set by user applications or RuboCop Rails gem.
bbatsov pushed a commit that referenced this issue May 17, 2020
…ccessor`

Fixes #7976 and #7981

This PR adds `AllowAliasSyntax` and `AllowedMethods` options.
for `Layout/EmptyLinesAroundAttributeAccessor` cop.

Users can configure a behavior for `alias` syntax using
`IgnoreAliasSyntax` option. Ignored by default (true).

And users can specify ignored methods using `AllowedMethods`.
By default, set `alias_method`, `public`, `protected`, and
`private` provided by Ruby.

`cattr_accessor`, `attribute`, other methods provided by Rails (and other gems)
can be set by user applications or RuboCop Rails gem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants