Rubocop: Style/TrailingCommaInArguments false positive with interpretation of multi-lined arguments?

Created on 7 Oct 2016  路  2Comments  路  Source: rubocop-hq/rubocop

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?

bug

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.

      # 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

All 2 comments

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 鉂わ笍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

herwinw picture herwinw  路  3Comments

Ana06 picture Ana06  路  3Comments

benoittgt picture benoittgt  路  3Comments

deivid-rodriguez picture deivid-rodriguez  路  3Comments

Aqualon picture Aqualon  路  3Comments