Skip to content

Break on multiple chained calls #1565

@SimenB

Description

@SimenB

I've mentioned this possibility in a few different issue (#1099, #1282, #1401), but I thought a separate issue might be appropriate. 😄

I'd like for prettier to break on multiple chained calls. I prefer a higher printWidth than 80 in most cases (such as strings, log statements, class declarations etc), but increasing it leads prettier to one-line a lot of chained expressions that were multi-lined.
Eslint has a rule for this called newline-per-chained-call. It defaults to 3 chained calls should break, which sounds like a sane starting point. This rule is unfixable, unfortunately, but Prettier could fix it! 😀

Even for the default width of 80 some things are inlined which IMO are more readable expanded.

I don't think there's any doubt which of these two are the easiest to read (especially considering the git diff scenario from eslint's docs): https://prettier.github.io/prettier/#%7B%22content%22%3A%22d3%5Cn%20%20.select(%5C%22body%5C%22)%5Cn%20%20.selectAll(%5C%22p%5C%22)%5Cn%20%20.data(%5B1%2C%202%5D)%5Cn%20%20.enter()%5Cn%20%20.style(%5C%22color%5C%22%2C%20%5C%22white%5C%22)%3B%5Cn%5Cnd3%5Cn%20%20.select(%5C%22body%5C%22)%5Cn%20%20.selectAll(%5C%22p%5C%22)%5Cn%20%20.data(%5B1%2C%202%2C%203%5D)%5Cn%20%20.enter()%5Cn%20%20.style(%5C%22color%5C%22%2C%20%5C%22white%5C%22)%3B%5Cn%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3A%22none%22%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Afalse%2C%22parser%22%3A%22babylon%22%2C%22semi%22%3Atrue%2C%22useTabs%22%3Afalse%2C%22doc%22%3Afalse%7D%7D

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:member chainslocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!status:needs discussionIssues needing discussion and a decision to be made before action can be taken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions