These are chat archives for beautify-web/js-beautify

16th
Nov 2015
Liam Newman
@bitwiseman
Nov 16 2015 20:41
@Noitidart - the code for the webpage (index.html) shows how to load the beautifier in a browser. No browserify needed.
@terakilobyte - interesting.
This input will produce the formatting you're looking for.
} else {
  $.ajax({
    url: 'http://en.wikipedia.org/w/api.php',
    dataType: 'jsonp',
    data: {
      action: 'opensearch',
      format: 'json',
      search: encodeURI(e.target.value)
    }
  }).done((data) => {
    this.setState({
      searchResults: data[1]
    });
  });
}
Liam Newman
@bitwiseman
Nov 16 2015 20:47
I feel like this has been filed as an issue already, but I might be wrong.
Overall, I understand why you'd like it do behave otherwise, but imagine an input that looks like this:
a.b.c.d.e()
If the user (or line wrapping) add a newline like this:
// as expected ".d" is indented to indicate it continues the statement started on the previous line
a.b.c
  .d.e()
Now if we change the text slightly you'll begin to see the problem:
Liam Newman
@bitwiseman
Nov 16 2015 20:52
$.ajax()
  .done()
".done()" continues the statement so it needs to be indented.
That pushes the parameter(s) of ajax() out one more indent.
$.ajax(
    param
  )
  .done()
The beautifier does it's best to collapse extra indents. Which is why you don't see:
Liam Newman
@bitwiseman
Nov 16 2015 21:00
// contents of "(" should indent, contents of "{" should indent.
// that would put "url:" at 6 spaces instead of 4, but the beautifier eliminates the extra indent
$.ajax({
      url: '...'
    })
  .done()

// But if your method signature were more complex, you'd see that indent
$.ajax({
      url: '...'
    },
    a)
  .done()