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

Single line function fix #309

Closed
kardasis opened this issue Jul 3, 2021 · 7 comments · Fixed by rubocop/rubocop#9926
Closed

Single line function fix #309

kardasis opened this issue Jul 3, 2021 · 7 comments · Fixed by rubocop/rubocop#9926

Comments

@kardasis
Copy link

kardasis commented Jul 3, 2021

I have a file called singlelinefunction.rb with the following contents

def a() return ('hi' == 'hello') end
def b() end

When I run bundle exec standardrb singlelinefunction.rb --fix, the resulting file is

def a (
  
  "hi" == "hello")
end

def b
end

Which is obviously incorrect.

When I remove the second function definition, so the contents of the file is

def a() return ('hi' == 'hello') end

Then the output is

def a
  ("hi" == "hello")
end

Which seems like bad style but at least is correct ruby code.

@kardasis
Copy link
Author

kardasis commented Jul 3, 2021

Also worth noting that if the second function has a non-empty body, i.e. def b 'yo' end, then the result is the same as when there's no function there at all. So it appears that the empty function body is at least partly responsible here.
Also, if the second function has an empty body but is not single-line:

def b()  
end

then it's fine too.

@searls
Copy link
Contributor

searls commented Jul 6, 2021

@kardasis Looks like @koic fixed this in the latest Rubocop release, so a fix should land in the next version we cut of Standard

@koic
Copy link
Contributor

koic commented Jul 6, 2021

@searls I'm sorry I haven't been able to share. This issue has not been resolved yet. I will let you know when it is resolved.

@kardasis
Copy link
Author

@koic So this was not addressed in rubocop yet? Should I make an issue over there?

@koic
Copy link
Contributor

koic commented Jul 12, 2021

@kardasis I opened rubocop/rubocop#9926 to resolve this issue. Thank you.

koic added a commit to koic/rubocop that referenced this issue Jul 12, 2021
Fixes standardrb/standard#309.

This PR fixes an incorrect auto-correct for `Style/SingleLineMethods`
when method body is enclosed in parentheses.
@koic
Copy link
Contributor

koic commented Jul 23, 2021

@searls This issue has been resolved with the release of RuboCop 1.18.4.
https://github.com/rubocop/rubocop/releases/tag/v1.18.4

@searls
Copy link
Contributor

searls commented Jul 28, 2021

Thanks @koic, @camilopayan released this update last night!

@searls searls closed this as completed Jul 28, 2021
thearjunmdas pushed a commit to thearjunmdas/rubocop that referenced this issue Aug 20, 2021
Fixes standardrb/standard#309.

This PR fixes an incorrect auto-correct for `Style/SingleLineMethods`
when method body is enclosed in parentheses.
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 a pull request may close this issue.

3 participants