+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_formatter): Dedent IR #3007

Merged
merged 2 commits into from
Aug 6, 2022
Merged

Conversation

MichaReiser
Copy link
Contributor

Summary

This PR adds a new IR that allows to reduce the indention for some content nested inside of an align or indent.

The behaviour of the element depends on whether the closest ancestor is an align or indent

  • align: Removes the align spaces
  • indent: Reduces the indention level by one EXCEPT if the level is 0, in which case this is a no-op

This is necessary for the formatting of nested conditional expressions where the consequent gets wrapped in an align but any nested consequent should be indented by one level (and not an indent). That's why the formatter uses dedent(indent(...)) to undo the align but enforce an indent.

Test Plan

I added a new builder test showing the behaviour of the dedent element.

This PR adds a new IR that allows to reduce the indention for some content nested inside of an `align` or `indent`.

The behaviour of the element depends on whether the closest ancestor is an `align` or `indent`

* `align`: Removes the `align` spaces
* `indent`: Reduces the indention level by one *EXCEPT* if the level is 0, in which case this is a no-op

This is necessary for the formatting of nested conditional expressions where the `consequent` gets wrapped in an `align` but any nested consequent should be indented by one level (and not an indent). That's why the formatter uses `deden(indent(...))` to undo the `align` but enforce an `indent`.
@MichaReiser MichaReiser added the A-Formatter Area: formatter label Aug 4, 2022
@MichaReiser MichaReiser added this to the 0.9.0 milestone Aug 4, 2022
@MichaReiser MichaReiser requested a review from leops August 4, 2022 16:15
@MichaReiser MichaReiser requested a review from ematipico as a code owner August 4, 2022 16:15
@MichaReiser MichaReiser temporarily deployed to aws August 4, 2022 16:15 Inactive
@github-actions
Copy link

github-actions bot commented Aug 4, 2022

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Aug 4, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4c9e9b5
Status: ✅  Deploy successful!
Preview URL: https://515ada42.tools-8rn.pages.dev
Branch Preview URL: https://feat-dedent-format-element.tools-8rn.pages.dev

View logs

@MichaReiser MichaReiser temporarily deployed to aws August 6, 2022 12:05 Inactive
@MichaReiser MichaReiser merged commit 4afdfbb into main Aug 6, 2022
@MichaReiser MichaReiser deleted the feat/dedent-format-element branch August 6, 2022 12:12
IWANABETHATGUY pushed a commit to IWANABETHATGUY/tools that referenced this pull request Aug 10, 2022
IWANABETHATGUY pushed a commit to IWANABETHATGUY/tools that referenced this pull request Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载