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

Trailing comma rule results in },]) contortion #133

Closed
searls opened this issue Sep 3, 2019 · 4 comments
Closed

Trailing comma rule results in },]) contortion #133

searls opened this issue Sep 3, 2019 · 4 comments
Labels
rule change 👩‍⚖️ Suggest a style guide rule change

Comments

@searls
Copy link
Contributor

searls commented Sep 3, 2019

Standard keeps slamming the final , into this and I hate it:

    Item.find_by_sql([sql, {
      user_id: user.id,
      answer: answer,
    },]).uniq

There's no way anyone thinks },]) is preferable in this case, right?

@searls searls added the rule change 👩‍⚖️ Suggest a style guide rule change label Sep 3, 2019
@pcriv
Copy link
Contributor

pcriv commented Sep 3, 2019

Yup, I don't like it either 😬
Would the solution be only adding the comma to the last element of a hash?

@searls
Copy link
Contributor Author

searls commented Sep 3, 2019

Yes, one would think

@GeoffAbtion
Copy link

},]) is undesirable but I think it is a symptom of another problem, you're trying to wrap a hash in a strange way. Of course that is going to look wrong.

These all look reasonable:

Item.find_by_sql(
  [
    sql,
    {
      user_id: user.id,
      answer: answer,
    },
  ]
).uniq
Item.find_by_sql([
  sql,
  {
    user_id: user.id,
    answer: answer,
  },
]).uniq
Item.find_by_sql([
  sql,
  {user_id: user.id, answer: answer},
]).uniq
Item.find_by_sql([sql, {user_id: user.id, answer: answer}]).uniq
  1. is probably what I'd want to see.

@jmkoni
Copy link
Contributor

jmkoni commented Jan 7, 2021

Pretty sure we fixed this in a7156b1

@jmkoni jmkoni closed this as completed Jan 7, 2021
casperisfine pushed a commit to casperisfine/standard that referenced this issue Aug 31, 2022
These cops used to be configured with `EnforcedStyleForMultiline: consistent_comma`
but it was changed in standardrb@a7156b1
because it can cause some weird contortions, see: standardrb#133

I totally agree that this cop resulting in such horrible contorsion
is broken, but I don't understand why that would justify to switch
to a different style rather than to just disable the cop.

Trailing comma in multiline hashes & co have the major advantage of
reducing diff noise when adding or removing an element.
casperisfine pushed a commit to casperisfine/standard that referenced this issue Aug 31, 2022
These cops used to be configured with `EnforcedStyleForMultiline: consistent_comma`
but it was changed in standardrb@a7156b1
because it can cause some weird contortions, see: standardrb#133

I totally agree that this cop resulting in such horrible contorsion
is broken, but I don't understand why that would justify to switch
to a different style rather than to just disable the cop.

Trailing comma in multiline hashes & co have the major advantage of
reducing diff noise when adding or removing an element.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule change 👩‍⚖️ Suggest a style guide rule change
Projects
None yet
Development

No branches or pull requests

4 participants