If I set this configuration:
Style/TrailingCommaInArguments:
Enabled: true,
EnforcedStyleForMultiline: consistent_comma
Then it enforces this code should have a comma like this:
EmailWorker.perform_async({
subject: "hey there",
email: "[email protected]"
},)
This doesn't seem right to me? It's a nuanced difference, but I don't consider this multi-lined arguments鈥攖he argument actually starts on the same line as the parentheses. The argument itself is multi-lined for readability, but the arguments aren't multi-lined. This is what I think multi-lined arguments look like:
EmailWorker.perform_async(
"foo",
"bar,
)
Or in the context of a hash:
EmailWorker.perform_async(
{
subject: "hey there",
email: "[email protected]"
},
)
Thoughts?
I agree. The purpose of the trailing comma cops is to make it possible to enforce a style that minimizes the diff when another element is added at the end. And the comma in your example is useless for that purpose.
In this code from lib/rubocop/cop/mixin/trailing_comma.rb, we see that the intentions are correct, but the implementation is wrong.
# Returns true if the round/square/curly brackets of the given node are
# on different lines, and each item within is on its own line, and the
# closing bracket is on its own line.
def multiline?(node)
The closing bracket, ) in your case, is _not_ on its own line.
I noted BTW that you also need the following configuration to reproduce the problem:
Style/BracesAroundHashParameters:
EnforcedStyle: braces
@jonas054 鉂わ笍
Most helpful comment
I agree. The purpose of the trailing comma cops is to make it possible to enforce a style that minimizes the diff when another element is added at the end. And the comma in your example is useless for that purpose.
In this code from
lib/rubocop/cop/mixin/trailing_comma.rb, we see that the intentions are correct, but the implementation is wrong.The closing bracket,
)in your case, is _not_ on its own line.I noted BTW that you also need the following configuration to reproduce the problem: