prettier-plugin-coffeescript icon indicating copy to clipboard operation
prettier-plugin-coffeescript copied to clipboard

Wrong formatting if "or" condition is used in hash object definition

Open eugene-tea opened this issue 6 years ago • 2 comments

This original code

b = null

obj =
  c: 1
  d: b or b: 1
  e: 100

prettier turns to

b = null

obj =
  c: 1
  d: b or
    b: 1

  e: 100

Having a line break breaks CoffeeScript compiler as it is not the same definition anymore

eugene-tea avatar Jan 23 '20 23:01 eugene-tea

Ok this one is also a Coffeescript parser bug (opened https://github.com/jashkenas/coffeescript/issues/5292)

This one would be trickier to guard against in the Prettier plugin (at least in a robust way)

I might be able to implement at least a "stopgap" in the Prettier plugin that avoids this specific case

But I'll also take a look at fixing the parsing issue on the Coffeescript side

Thanks for reporting all of these, it's great to see the Prettier and ESLint plugins being exercised against an actual production hybrid JS/Coffeescript React app :+1:

helixbass avatar Jan 24 '20 23:01 helixbass

@helixbass thank you for looking and spending time. I came with a workaround, of course, something like

b or= b:1

obj =
  c: 1
  d: b
  e: 100

But generally, we did successfully migrate our fairly big project to prettier, after fixing around 3000 lint errors now it seems it's working well. We do have a 50/50 mix of JS and CS and the usage of React in both codebases. I really like having one eslintrc for both JS and CS, moreover, it seems when I override rules for CS some of the general JS rules are inherited (can't say for sure, but it seems so).

eugene-tea avatar Jan 26 '20 23:01 eugene-tea