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

Handle attr_accessors on the last line in EmptyLinesAroundAttributeAccessor #9185

Merged
merged 1 commit into from
Dec 8, 2020

Conversation

tas50
Copy link
Contributor

@tas50 tas50 commented Dec 7, 2020

I figured I should probably push a fix up after writing so many of my own cops. Let me know if I got the process right. I'd like to contribute more fixes for issues we run into at Chef.

The fix:

In Style/EmptyLinesAroundAttributeAccessor we check the line+1 to see if it's empty. That's fine until the attr_accessor is on the last line and then the next line is nil and blank? fails. When we're checking the next line and it is nil then there is no next line and the attr_accessor is on the last line. We don't need to pad with an empty line so we're good at that point and we can continue on with life.

Fixes #9184

Signed-off-by: Tim Smith tsmith@chef.io

@@ -47,6 +47,10 @@ def do_something
RUBY
end

it 'accepts code that where the attr_accessor is the last line' do
expect_no_offenses("attr_accessor :foo")
Copy link
Member

Choose a reason for hiding this comment

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

CI is failing. Can you update this one?

Suggested change
expect_no_offenses("attr_accessor :foo")
expect_no_offenses('attr_accessor :foo')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦 Too much time in the Chef codebase

…cessor

When we're checking the next line and it's nil then there is no next
line and the attr_accessor is on the last line. We don't need to pad
with an ampty line so we're good at that point and we can continue on
with life.

Signed-off-by: Tim Smith <tsmith@chef.io>
@koic koic merged commit 70ffe1b into rubocop:master Dec 8, 2020
@koic
Copy link
Member

koic commented Dec 8, 2020

Looks good! Thank you!

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.

Layout/EmptyLinesAroundAttributeAccessor fails if the attr_accessor is the last line of the file
2 participants