beautifier / js-beautify

Beautifier for javascript
https://beautifier.io
MIT License
8.55k stars 1.37k forks source link

Add option to make chained methods move to one line #757

Open erezfz opened 9 years ago

erezfz commented 9 years ago

Hello, in the online editor at http://jsbeautifier.org/, using chrome latest version (44.0.2403.155 m) setting option - "Break lines on chained methods" =false , is not functioning. Beautify breaks method channing.

Settings: "Break lines on chained methods" =false "wrap lines near 40 characters"

sample code:

if (oParameters.State !== ui().s2p().mm().supplinvoice().manage().util().Constants().blabla()) {
return false;
  }
 }

result after beautification:

if (oParameters.State !== ui().s2p().mm()
    .supplinvoice().manage().util().Constants()
    .blabla()) {
    return false;
}
}

Expected result after beautification:

if (oParameters.State !== ui().s2p().mm().supplinvoice().manage().util().Constants().blabla()) {
    return false;
}
}

is it a source-problem in the online-editor or the jsbeautify code?

erezfz commented 9 years ago

I've found that its not related to the editor; the "break_chained_methods" is not functioning

bitwiseman commented 8 years ago

Please look at the output here: https://github.com/mpelikan/js-beautify/blob/master/test/template/node-javascript.mustache#L580

break_chained_methods is used to force newlines between chained methods, not to prevent line breaks between chained method. Sorry, this correct behavior.

bitwiseman commented 8 years ago

Please comment if you'd like this reopened.

erezfz commented 7 years ago

Returning to the headline of the issue- can you add option to disable/ enable breaklines on chained methods?

bitwiseman commented 7 years ago

We've added to the list of requested enhancements. There are a number higher priority issues that we'll be working on first. Would you be will contribute this addition to the project?

erezfz commented 7 years ago

yes

bitwiseman commented 7 years ago

Great! See https://github.com/beautify-web/js-beautify/blob/master/CONTRIBUTING.md.