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

Bug: breaking assignment to class

Open helixbass opened this issue 6 years ago • 2 comments

This

exports.ExportNamedDeclaration = class ExportNamedDeclaration extends ExportDeclaration
  ...

is formatting like

exports
  .ExportNamedDeclaration = class ExportNamedDeclaration extends ExportDeclaration
  ...

so the class body doesn't parse as indented

helixbass avatar Mar 24 '19 15:03 helixbass

#55 fixed this specific case but there are other examples that would still break eg

exports().ExportNamedDeclaration = ...

This seems like part of a more general problem where nothing in a control line can do a simple indented break because then the indented body won't parse as indented

helixbass avatar Mar 24 '19 15:03 helixbass

I'm thinking that a short-term "solution" would be to disable the indentChain option for now (or advertise as USE AT YOUR OWN RISK), since all I can think of that would cause this is a member expression LHS of an assignment

Basically I think the question for whether an indented body could ever be not actually indented due to something like this can be broken into:

  1. Are there any cases where an element of the "control line" (non-indented line that precedes the indented body) could itself break in a way that's not "self-indent-closing"?

Hopefully this is already covered (eg if a for source or guard breaks, it gets parenthesized), and if there are any more cases that aren't covered then presumably they can be covered in a similar way (make sure it gets parenthesized if it needs to be) since for these we know that it's part of a structure that has an indented body

  1. The trickier cases (like this issue) are when there's something else preceding the "control line" on the same line/expression that could itself break in a non-self-indent-closing way (and it would presumably be hard to robustly guard against all arbitrarily nested variants of these from the perspective of the control structure or the enclosing expressions)

So the question is, what types of expressions are there that could have its first part break in a non-self-indent-closing way while not affecting the indent level of the control structure

Assignment (like in this issue) is one thing where the LHS can break separately (at least if the RHS is inlined like here for class). So what types of assignment LHS could non-self-indent-closing break?

I can only see non-computed member expressions

And not sure what if any other types of enclosing expressions could break that way? Eg this indents the whole control structure:

a +
  class B
    c: ->

helixbass avatar Apr 03 '19 13:04 helixbass