You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rubocop allows single line method definitions to use empty parentheses.
Eg.
defmethod_1()'foo';enddefmethod_2()='bar'
Though this behaviour has been part of Rubocop for many years, as far as I can see it is contrary to the style guide which expressly instructs against using parentheses in a method definition when there are no parameters:
Method Definition Parentheses
Use def with parentheses when there are parameters. Omit the parentheses when the method doesn’t accept any parameters.
I have been unable to find an exception to this rule for single line methods anywhere in the guide (though I might be missing it).
Solution
Style/DefWithParentheses flags offences for single line method definitions with parentheses which do not accept parameters
Alternatives
I have been unable to discover the rationale behind originally allowing empty parentheses in this commit. If it is behaviour we want to retain, perhaps there should be a mention of it in the style guide (assuming there isn't one already which I have been unable to find).
The text was updated successfully, but these errors were encountered:
def foo() do_something end will continue to allow because def foo do_something end is a syntax error.
On the other hand, be aware that the endless method definition's parentheses can be omitted. I've opened #10421.
koic
added a commit
to koic/rubocop
that referenced
this issue
Feb 20, 2022
…method definition
Fixesrubocop#10421.
This PR makes `Style/DefWithParentheses` aware of endless method definition.
`def foo() do_something end` will continue to allow because `def foo do_something end`
is a syntax error.
On the other hand, be aware that the endless method definition's parentheses can be omitted.
…definition
Fixes#10421.
This PR makes `Style/DefWithParentheses` aware of endless method definition.
`def foo() do_something end` will continue to allow because `def foo do_something end`
is a syntax error.
On the other hand, be aware that the endless method definition's parentheses can be omitted.
Problem
Rubocop allows single line method definitions to use empty parentheses.
Eg.
Though this behaviour has been part of Rubocop for many years, as far as I can see it is contrary to the style guide which expressly instructs against using parentheses in a method definition when there are no parameters:
Link: Method Definition Parentheses
I have been unable to find an exception to this rule for single line methods anywhere in the guide (though I might be missing it).
Solution
Style/DefWithParentheses
flags offences for single line method definitions with parentheses which do not accept parametersAlternatives
I have been unable to discover the rationale behind originally allowing empty parentheses in this commit. If it is behaviour we want to retain, perhaps there should be a mention of it in the style guide (assuming there isn't one already which I have been unable to find).
The text was updated successfully, but these errors were encountered: