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

[Fix #7976] Add ignore options for Layout/EmptyLinesAroundAttributeAccessor #7982

Conversation

koic
Copy link
Member

@koic koic commented May 16, 2020

Fixes #7976 and #7981

This PR adds IgnoreAliasSyntax and IgnoredMethods options for Layout/EmptyLinesAroundAttributeAccessor .

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

And users can specify ignored methods using IgnoredMethods. 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.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the add_ignore_options_for_empty_lines_around_attribute_accessor branch 3 times, most recently from d7eeef6 to 35c311d Compare May 16, 2020 03:45
@koic koic force-pushed the add_ignore_options_for_empty_lines_around_attribute_accessor branch from 35c311d to c8cc5b9 Compare May 16, 2020 03:59
@@ -468,6 +468,13 @@ Layout/EmptyLinesAroundAttributeAccessor:
StyleGuide: '#empty-lines-around-attribute-accessor'
Enabled: pending
VersionAdded: '0.83'
VersionChanged: '1.0'
IgnoreAliasSyntax: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather use Allow and Allowed here.

@@ -4,6 +4,8 @@ module RuboCop
module Cop
module Layout
# Checks for a newline after attribute accessor.
# `alias` syntax and `alias_method`, `public`, `protected`, and `private` methods are ignored by default.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also be more specific in the initial sentence - it's an attribute accessor or a group of them.

@bbatsov
Copy link
Collaborator

bbatsov commented May 17, 2020

Good work! Probably at some point we should have something more generic for other macros that are typically grouped together.

@koic koic force-pushed the add_ignore_options_for_empty_lines_around_attribute_accessor branch from c8cc5b9 to 872af14 Compare May 17, 2020 06:38
@koic
Copy link
Member Author

koic commented May 17, 2020

Yeah, I update this PR.

@@ -468,6 +468,13 @@ Layout/EmptyLinesAroundAttributeAccessor:
StyleGuide: '#empty-lines-around-attribute-accessor'
Enabled: pending
VersionAdded: '0.83'
VersionChanged: '1.0'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also change this to 0.84.

Copy link
Member Author

@koic koic May 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I updated it!

…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.
@koic koic force-pushed the add_ignore_options_for_empty_lines_around_attribute_accessor branch from 872af14 to aad52dd Compare May 17, 2020 08:01
@bbatsov bbatsov merged commit fdbbda2 into rubocop:master May 17, 2020
@koic koic deleted the add_ignore_options_for_empty_lines_around_attribute_accessor branch May 17, 2020 08:29
@ashmaroli
Copy link

Thank you for the quick turnaround @koic and @bbatsov :)

koic added a commit to koic/rubocop that referenced this pull request May 17, 2020
@koic koic mentioned this pull request May 17, 2020
8 tasks
bbatsov pushed a commit that referenced this pull request May 17, 2020
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

Successfully merging this pull request may close these issues.

Allow Layout/EmptyLineAroundAttributeAccessor cop to ignore immediate keyword declarations
3 participants