Skip to content

Instantly share code, notes, and snippets.

@garybernhardt
Last active August 17, 2019 08:20
Show Gist options
  • Save garybernhardt/55254ce390b87b2121cee69f1c2f61f6 to your computer and use it in GitHub Desktop.
Save garybernhardt/55254ce390b87b2121cee69f1c2f61f6 to your computer and use it in GitHub Desktop.
function f() {
switch (x) {
case "1":
<div>foo</div>
case "2":
return <div>
<div>
foo
</div>
<div>foo</div>
</div>
case "3":
return <div>
<div>foo</div>
<div />
</div>
case "4":
return <div>
foo
</div>
}
}
@mikker
Copy link

mikker commented Aug 16, 2019

Prettier formats like so (after fixing typo)

function f() {
  switch (x) {
    case "1":
      <div>foo</div>;
    case "2":
      return (
        <div>
          <div>foo</div>
          <div>foo</div>
        </div>
      );
    case "3":
      return (
        <div>
          <div>foo</div>
          <div />
        </div>
      );
    case "4":
      return <div>foo</div>;
  }
}

@eprev
Copy link

eprev commented Aug 17, 2019

This is what Yats does (when you add the parentheses), it seems Yats uses standard xml.vim to indent JSX, thus it works fine when JSX begins with a new line.

function f() {
  switch (x) {
    case "1":
      <div>foo</div>
    case "2":
      return (
        <div>
          <div>
              foo
          </div>
          <div>foo</div>                                                                                                                                      
        </div>
    )
    case "3":
      return (
        <div>
          <div>foo</div>
          <div/>
        </div>
    )
    case "4":
      return (
        <div>
            foo
        </div>
    )
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment