felipeochoa / rjsx-mode

A JSX major mode for Emacs
https://github.com/felipeochoa/rjsx-mode
MIT License
641 stars 32 forks source link

Indentation is unexpected without parenthesis #93

Open axelson opened 5 years ago

axelson commented 5 years ago

I expect different indentation for the following code:

Actual:

  render () {
    var a = (
      <div>
        abc
      </div>
    )
    var b = <div>
              abc
            </div>
  }

Expected:

  render () {
    var a = (
      <div>
        abc
      </div>
    )
    var b = <div>
      abc
    </div>
  }

Basically I expect similar indentation with and without the parentheses. Is this something that is accomplishable in rjsx-mode?

Please check if the bug still exists when using js2-jsx-mode (if applicable). If so, it is most likely an upstream bug and should be reported there.

js2-jsx-mode seems to have broken indentation in this scenario as well but in a different way

felipeochoa commented 5 years ago

Nope, that's not possible currently, but PRs welcome

axelson commented 5 years ago

Do you have any pointers on implementing this type of indentation?

felipeochoa commented 5 years ago

You may be able to get it done simply by editing `rjsx--indent-line-to-offset'

The indentation code works by tracking a parent JSX element, relative to which we indent children. This all happens here.

vaer-k commented 5 years ago

This becomes pretty unpleasant when formatting stateless components with arrow functions:

const Stuff = ({ value, children }) =>
  <form>
    {children} 
    <input
      type="text"
      value={value}/>
  </form>

becomes

const Stuff = ({ value, children }) =>
      <form>
      {children} 
      <input
type="text"
value={value}/>
  </form>
knobo commented 5 years ago

But "this" what @vaer-k is refering to is a bug in js2 (I think) /mooz/js2-mode/issues/526