Weird Indentation with chained calls
See original GitHub issuePrettier 1.15.3 Playground link
--parser babylon
Input:
$.ajax({
url: 'https://random.com'
}).done(function (data) {
console.log('Done');
}).fail(function () {
console.log('Error');
});
Output:
$.ajax({
url: "https://random.com"
})
.done(function(data) {
console.log("Done");
})
.fail(function() {
console.log("Error");
});
Expected behavior:
$.ajax({
url: 'https://random.com'
}).done(function (data) {
console.log('Done');
}).fail(function () {
console.log('Error');
});
If I remove the fail from the chained call list then prettier will format it like this -
Prettier 1.15.3 Playground link
--parser babylon
Input:
$.ajax({
url: 'https://random.com'
}).done(function (data) {
console.log('Done');
});
Output:
$.ajax({
url: "https://random.com"
}).done(function(data) {
console.log("Done");
});
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:13 (6 by maintainers)
Top Results From Across the Web
in chained calls causes strange formatting and indentation #230
seems to break the chain somehow. Parts of the chain may be merged onto the same line, while other parts are indented too...
Read more >Auto-indent lines feature wrongly indents multiline chained ...
PY-33832 Incorrect indentation when chaining method calls within parentheses ... PyCharm seems to make some weird decisions, ruining the visual structure:
Read more >c# - Indent chained method calls so they all start at the same ...
Consider the following code formatting, taken from this answer. var query = grades.GroupBy(student => student.Name) .Select(group => new ...
Read more >bug#32496: 27.0.50; Strange indentation when ruby-align-chained ...
From: Bozhidar Batsov. Subject: bug#32496: 27.0.50; Strange indentation when ruby-align-chained-calls is t. Date: Wed, 01 Sep 2021 13:02:56 +0300.
Read more >Indent Chained Methods - Unibeautify
Indent chained method calls. Configuration option for beautifiers JS-Beautify, ESLint and languages EJS, JSX, JavaScript.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@bodrick Because with 2+ chains you’re most likely to want something similar to:
which is subjectively better than:
We had to choose an heuristic and that was it.
As for the OP, I personally prefer the Prettier formatting than the your expected.
agree to disagree, but for me double indentation is better than inconsistent indentation.
ie you have double indentation for all of the other functions…