royriojas / esformatter-jsx

esformatter plugin: format jsx files (or js files with Facebook React JSX Syntax)
MIT License
142 stars 25 forks source link

Fails to format props function #94

Closed octohedron closed 7 years ago

octohedron commented 7 years ago

Normal

<DatePicker
    style={ styles.datePickerStyle }
    date={ this.state.date }
    mode='datetime'
    placeholder='Select date and time'
    format='MM/D/YYYY HH:mm'
    confirmBtnText='Confirm'
    cancelBtnText='Cancel'
    showIcon={ false }
    onDateChange={ (date) => {
        this.setState({
          date
        });
      } } />

After applying formatting it becomes

<DatePicker
  style={ styles.datePickerStyle }
  date={ this.state.date }
  mode='datetime'
  placeholder='Select date and time'
  format='MM/D/YYYY HH:mm'
  confirmBtnText='Confirm'
  cancelBtnText='Cancel'
  showIcon={ false }
  onDateChange={ (date) => {
                                                           this.setState({
                                                             date
                                                           });
                                                         } } />

Notice that every time you format, it adds additional indentation to the contents of the onDateChange function

Using esfromtatter-jsx@7.4.0 with sublime-jsfmt

Update: found the problem, it's when using the property shorthand, changing date to date: date fixes the issue, the thing is, this should support it.

royriojas commented 7 years ago

hi @octohedron

I'm having a hard time reproducing this bug. I just copied pasted your code to the small test demo in the repo and I'm not able to reproduce (it formats correctly). Can you also share your config please?