Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make chain breaking as similar to original prettier (js) as much as possible #2320

Merged
merged 8 commits into from
Feb 3, 2024
Merged

Conversation

eldair
Copy link
Contributor

@eldair eldair commented Jan 29, 2024

There is a hardcoded line which is the cause of chain breaks even though the expression would fit in one line. This is a quick and easy solution for #1545

I have adjusted test so they all pass but if this is merged than some of those could be removed as redundant.

@eldair
Copy link
Contributor Author

eldair commented Jan 29, 2024

I have updated the pull request to include a new option where user can define their own max calls in a chain before break occurs. The default option is left as is (I think the number 3 is based on similar option in main prettier repo) so it would not affect current codebases.

@eldair eldair changed the title Removed chain break with more than 3 expressions Added an option to set desired max calls in a chain before break Jan 29, 2024
Updated description in options file
@czosel
Copy link
Collaborator

czosel commented Jan 30, 2024

Hi @eldair, thanks for contributing! I think adding an option for this doesn't fit to the Prettier option philosophy. Did you already look into how Prettier for JS handles this? It would be awesome if we could solve it the same way.

@eldair
Copy link
Contributor Author

eldair commented Jan 30, 2024

Hi @czosel , I'm sorry, I didn't see that doc about adding options. The next best thing in my opinion is to remove chains limit and to leave them in single line if they can fit (they would still break in case of multiline closures). this would be as close to the js counterpart as possible without adding checks for call complexity which might not even be needed for php.

This is from prettier (js) with my comments

  // We don't want to print in one line if at least one of these conditions occurs:
  //  * the chain has comments, - this is taken care of
  //  * the chain is an expression statement and all the arguments are literal-like ("fluent configuration" pattern), - this one I don't understand (it has no separate check in the code)
  //  * the chain is longer than 2 calls and has non-trivial arguments or more than 2 arguments in any call but the first one, - in php arrow functions don't tend to be complicated and regular multiline functions would already break the chain
  //  * any group but the last one has a hard line, - taken care of
  //  * the last call's arguments have a hard line and other calls have non-trivial arguments. - same as 3.

@eldair
Copy link
Contributor Author

eldair commented Jan 30, 2024

Me again, I have started digging into isSimpleCallArgument of prettier. I will get back if I manage to port it for php to be on par with js version.

@eldair eldair changed the title Added an option to set desired max calls in a chain before break Make chain breaking as similar to original prettier (js) as much as possible Jan 30, 2024
@eldair
Copy link
Contributor Author

eldair commented Jan 31, 2024

@czosel Pull request can be checked now. The code is not perfect and I tried to test as many combination as I could think of but it is much closer to the JS counterpart and I think better than the current implementation.
Let me know if something should be changed/fixed/improved.

@cseufert
Copy link
Collaborator

cseufert commented Feb 2, 2024

Change looks good to me, however, can you reformat with prettier and commit? See CI / Lint action, at least print.mjs needs reformating.

@eldair
Copy link
Contributor Author

eldair commented Feb 2, 2024

@cseufert thanks for checking it out, i've fixed the file

@czosel
Copy link
Collaborator

czosel commented Feb 3, 2024

LGTM, thanks for the awesome contribution @eldair! 🎉

@czosel czosel merged commit 410e292 into prettier:main Feb 3, 2024
11 of 12 checks passed
@czosel
Copy link
Collaborator

czosel commented Feb 3, 2024

Released in v0.22.2 🎉

@eldair
Copy link
Contributor Author

eldair commented Feb 4, 2024

Woohoo 🎉

tisnamuliarta referenced this pull request in tisnamuliarta/laravel-shadcn Mar 11, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@prettier/plugin-php](https://togithub.com/prettier/prettier-php) |
[`^0.18.9` ->
`^0.22.0`](https://renovatebot.com/diffs/npm/@prettier%2fplugin-php/0.18.9/0.22.2)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@prettier%2fplugin-php/0.22.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@prettier%2fplugin-php/0.22.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@prettier%2fplugin-php/0.18.9/0.22.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@prettier%2fplugin-php/0.18.9/0.22.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>prettier/prettier-php (@&#8203;prettier/plugin-php)</summary>

###
[`v0.22.2`](https://togithub.com/prettier/plugin-php/releases/tag/v0.22.2)

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.22.1...v0.22.2)

#### What's Changed

- Make chain breaking as similar to original prettier (js) as much as
possible by [@&#8203;eldair](https://togithub.com/eldair) in
[https://github.com/prettier/plugin-php/pull/2320](https://togithub.com/prettier/plugin-php/pull/2320)
- fix: 🐛 singleQuote option does not work on format API by
[@&#8203;shufo](https://togithub.com/shufo) in
[https://github.com/prettier/plugin-php/pull/2303](https://togithub.com/prettier/plugin-php/pull/2303)
- chore: upgrade dependencies by
[@&#8203;czosel](https://togithub.com/czosel) in
[https://github.com/prettier/plugin-php/pull/2321](https://togithub.com/prettier/plugin-php/pull/2321)

#### New Contributors

- [@&#8203;eldair](https://togithub.com/eldair) made their first
contribution in
[https://github.com/prettier/plugin-php/pull/2320](https://togithub.com/prettier/plugin-php/pull/2320)

**Full Changelog**:
prettier/plugin-php@v0.22.1...v0.22.2

###
[`v0.22.1`](https://togithub.com/prettier/plugin-php/releases/tag/v0.22.1)

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.22.0...v0.22.1)

- fix the entry
([#&#8203;2290](https://togithub.com/prettier/prettier-php/issues/2290),
thanks [@&#8203;fisker](https://togithub.com/fisker))

###
[`v0.22.0`](https://togithub.com/prettier/plugin-php/releases/tag/v0.22.0)

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.21.0...v0.22.0)

- feat: make format compatible with "PER Coding Style 2.0"
([#&#8203;2269](https://togithub.com/prettier/prettier-php/issues/2269),
thanks [@&#8203;ferchoz](https://togithub.com/ferchoz))
- fix: make `/standalone` entry work with `require()`
([#&#8203;2247](https://togithub.com/prettier/prettier-php/issues/2247),
thanks [@&#8203;shufo](https://togithub.com/shufo))
- chore: upgrade deps
([#&#8203;2289](https://togithub.com/prettier/prettier-php/issues/2289))

###
[`v0.21.0`](https://togithub.com/prettier/plugin-php/releases/tag/v0.21.0):
0.21.0

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.20.1...v0.21.0)

- fix(match): Indent match conditions
([#&#8203;2258](https://togithub.com/prettier/prettier-php/issues/2258),
thanks [@&#8203;claytonrcarter](https://togithub.com/claytonrcarter)!)
- chore!: upgrade dependencies
([#&#8203;2262](https://togithub.com/prettier/prettier-php/issues/2262))

#### Breaking changes

This release drops support for node v14.

###
[`v0.20.1`](https://togithub.com/prettier/plugin-php/releases/tag/v0.20.1)

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.20.0...v0.20.1)

**This package is now pure ESM.**

- vscode documentation update
([#&#8203;2194](https://togithub.com/prettier/prettier-php/issues/2194),
thanks [@&#8203;WazzaJB](https://togithub.com/WazzaJB)!)
- Use `AstPath` getters
([#&#8203;2214](https://togithub.com/prettier/prettier-php/issues/2214),
thanks [@&#8203;fisker](https://togithub.com/fisker)!)
- Migrate to ESM
([#&#8203;2213](https://togithub.com/prettier/prettier-php/issues/2213),
thanks [@&#8203;fisker](https://togithub.com/fisker)!)

###
[`v0.20.0`](https://togithub.com/prettier/plugin-php/releases/tag/v0.20.0)

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.19.7...v0.20.0)

Many thanks to [@&#8203;fisker](https://togithub.com/fisker) for many
contributions!

- feat: upgrade to prettier 3
([#&#8203;2200](https://togithub.com/prettier/prettier-php/issues/2200))
- Simplify `print()`
([#&#8203;2212](https://togithub.com/prettier/prettier-php/issues/2212))
- Convert tests to ES Modules
([#&#8203;2210](https://togithub.com/prettier/prettier-php/issues/2210))
- Fix standalone test
([#&#8203;2211](https://togithub.com/prettier/prettier-php/issues/2211))
- Update .gitattributes
([#&#8203;2209](https://togithub.com/prettier/prettier-php/issues/2209))

### Breaking Change

This adds support for Prettier v3. It also drops compatibility with
Prettier v1 and v2.

###
[`v0.19.7`](https://togithub.com/prettier/plugin-php/releases/tag/v0.19.7):
0.19.7

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.19.6...v0.19.7)

- fix(match): Support empty lines and comments in match expressions
([#&#8203;1956](https://togithub.com/prettier/prettier-php/issues/1956),
[#&#8203;2201](https://togithub.com/prettier/prettier-php/issues/2201) -
thanks [@&#8203;claytonrcarter](https://togithub.com/claytonrcarter)!)

###
[`v0.19.6`](https://togithub.com/prettier/plugin-php/releases/tag/v0.19.6):
0.19.6

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.19.5...v0.19.6)

- Add support for final class const
([#&#8203;2186](https://togithub.com/prettier/prettier-php/issues/2186),
thanks [@&#8203;cseufert](https://togithub.com/cseufert)!)
- chore: upgrade dependencies
([#&#8203;2193](https://togithub.com/prettier/prettier-php/issues/2193))

###
[`v0.19.5`](https://togithub.com/prettier/plugin-php/releases/tag/v0.19.5):
0.19.5

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.19.4...v0.19.5)

- fix: add option for PHP 8.2
([#&#8203;2179](https://togithub.com/prettier/prettier-php/issues/2179))
*Note*: This allows setting `phpVersion` to `8.2` - Support for PHP 8.2
is still incomplete, though!

###
[`v0.19.4`](https://togithub.com/prettier/plugin-php/releases/tag/v0.19.4):
0.19.4

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.19.3...v0.19.4)

This release includes several internal cleanups and updates, thanks to
contributions by [@&#8203;fisker](https://togithub.com/fisker)!

- improve doc print and update prettier dependency
([#&#8203;1922](https://togithub.com/prettier/prettier-php/issues/1922))
- use `clean.ignoredProperties`
([#&#8203;2158](https://togithub.com/prettier/prettier-php/issues/2158))
- Remove handling `\r`
([#&#8203;2157](https://togithub.com/prettier/prettier-php/issues/2157))
-   dependency updates

###
[`v0.19.3`](https://togithub.com/prettier/plugin-php/releases/tag/v0.19.3):
0.19.3

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.19.2...v0.19.3)

- feat: add support for readonly classes \[PHP 8.2]
([#&#8203;2131](https://togithub.com/prettier/prettier-php/issues/2131),
thanks [@&#8203;genintho](https://togithub.com/genintho)!)
- chore: upgrade dependencies
([#&#8203;2134](https://togithub.com/prettier/prettier-php/issues/2134))

###
[`v0.19.2`](https://togithub.com/prettier/plugin-php/releases/tag/v0.19.2):
0.19.2

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.19.1...v0.19.2)

#### Deprecations

The `psr2` setting for the `braceStyle` option has been renamed to
`per-cs` to be more in line with future PER releases (see
[https://github.com/prettier/plugin-php/issues/2060](https://togithub.com/prettier/plugin-php/issues/2060)
for details). `psr2` will continue to work for now, but will be removed
in a future release.

#### Bugfixes

- Support expressions in new statement
([#&#8203;2086](https://togithub.com/prettier/prettier-php/issues/2086),
thanks [@&#8203;cseufert](https://togithub.com/cseufert)!)
- Fix for function curly brace with attrs
([#&#8203;2089](https://togithub.com/prettier/prettier-php/issues/2089),
thanks [@&#8203;cseufert](https://togithub.com/cseufert)!)
- Deprecated PSR-2 braceStyle and use PER-CS instead
([#&#8203;2070](https://togithub.com/prettier/prettier-php/issues/2070),
thanks [@&#8203;cseufert](https://togithub.com/cseufert)!)

###
[`v0.19.1`](https://togithub.com/prettier/plugin-php/releases/tag/v0.19.1):
0.19.1

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.19.0...v0.19.1)

- fix for inline closure
([#&#8203;2062](https://togithub.com/prettier/prettier-php/issues/2062),
thanks [@&#8203;cseufert](https://togithub.com/cseufert)!)
- chore: upgrade dependencies
([#&#8203;2068](https://togithub.com/prettier/prettier-php/issues/2068))

###
[`v0.19.0`](https://togithub.com/prettier/plugin-php/releases/tag/v0.19.0):
0.19.0

[Compare
Source](https://togithub.com/prettier/prettier-php/compare/v0.18.9...v0.19.0)

- fix: formatting of long cases in match statement
([#&#8203;2054](https://togithub.com/prettier/prettier-php/issues/2054))
- chore: upgrade dependencies
([#&#8203;2059](https://togithub.com/prettier/prettier-php/issues/2059))

Breaking Change:

-   Dropped support for Node v12.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/tisnamuliarta/laravel-shadcn).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMzAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIzMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants