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

feat(rome_formatter): Align IR element #2995

Merged
merged 2 commits into from
Aug 4, 2022
Merged

feat(rome_formatter): Align IR element #2995

merged 2 commits into from
Aug 4, 2022

Conversation

MichaReiser
Copy link
Contributor

@MichaReiser MichaReiser commented Aug 3, 2022

This PR adds an alignment FormatElement that allows explicitly aligning content by a specific amount of spaces rather than using indent that uses the configured indent string.

Aligning by an explicit number of spaces is e.g. needed when formatting conditional expressions where the content should be aligned to "? " and : .

Prettier compatibility

Prettier's align IR supports not only positive numbers but also

  • negative numbers (for dedenting)
  • NEGATIVE_INFINITE: TO dedent to root
  • strings: To use a specific indent string sequence other than spaces

I'll add the functionality once needed (NEGATIVE_INFINITE will be needed for template literals)

Tests

I added a new doc test that demonstrates the new IR element.

This PR adds an alignment `FormatElement` that allows explicitly aligning content by a specific amount of spaces rather than using `indent` that uses the configured indent string.

Aligning by an explicit number of spaces is e.g. needed when formatting conditional expressions where the content should be aligned to `"? "` and `: `.

## Tests

I added a new doc test that demonstrates the new IR element.
@MichaReiser MichaReiser added the A-Formatter Area: formatter label Aug 3, 2022
@MichaReiser MichaReiser requested a review from leops August 3, 2022 13:17
@MichaReiser MichaReiser requested a review from ematipico as a code owner August 3, 2022 13:17
@MichaReiser MichaReiser self-assigned this Aug 3, 2022
@MichaReiser MichaReiser temporarily deployed to aws August 3, 2022 13:17 Inactive
@MichaReiser
Copy link
Contributor Author

!bench_formatter

@github-actions
Copy link

github-actions bot commented Aug 3, 2022

@cloudflare-workers-and-pages
Copy link

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

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: a154bc3
Status: ✅  Deploy successful!
Preview URL: https://ae359394.tools-8rn.pages.dev
Branch Preview URL: https://feat-align-ir.tools-8rn.pages.dev

View logs

@github-actions
Copy link

github-actions bot commented Aug 3, 2022

Formatter Benchmark Results

group                                    main                                   pr
-----                                    ----                                   --
formatter/checker.ts                     1.01    382.0±3.69ms     6.8 MB/sec    1.00    377.6±2.00ms     6.9 MB/sec
formatter/compiler.js                    1.00    233.2±1.03ms     4.5 MB/sec    1.00    232.4±1.06ms     4.5 MB/sec
formatter/d3.min.js                      1.00    189.0±2.08ms  1420.4 KB/sec    1.00    188.2±1.32ms  1425.9 KB/sec
formatter/dojo.js                        1.00     12.6±0.05ms     5.4 MB/sec    1.00     12.6±0.10ms     5.5 MB/sec
formatter/ios.d.ts                       1.08    261.7±2.27ms     7.1 MB/sec    1.00    242.4±0.82ms     7.7 MB/sec
formatter/jquery.min.js                  1.00     50.0±0.50ms  1692.7 KB/sec    1.00     49.9±0.92ms  1694.8 KB/sec
formatter/math.js                        1.00    376.4±1.43ms  1761.7 KB/sec    1.02    383.4±3.71ms  1729.5 KB/sec
formatter/parser.ts                      1.00      8.4±0.04ms     5.8 MB/sec    1.00      8.4±0.01ms     5.8 MB/sec
formatter/pixi.min.js                    1.00    204.8±2.30ms     2.1 MB/sec    1.02    209.0±1.04ms     2.1 MB/sec
formatter/react-dom.production.min.js    1.00     61.7±0.67ms  1911.0 KB/sec    1.00     61.6±0.44ms  1912.2 KB/sec
formatter/react.production.min.js        1.01      3.1±0.01ms     2.0 MB/sec    1.00      3.0±0.01ms     2.0 MB/sec
formatter/router.ts                      1.01      6.5±0.04ms     9.5 MB/sec    1.00      6.4±0.01ms     9.6 MB/sec
formatter/tex-chtml-full.js              1.00    488.1±1.75ms  1911.6 KB/sec    1.01    492.1±2.19ms  1896.1 KB/sec
formatter/three.min.js                   1.00    237.9±1.05ms     2.5 MB/sec    1.05    250.7±2.45ms     2.3 MB/sec
formatter/typescript.js                  1.00   1572.6±9.17ms     6.0 MB/sec    1.00  1574.6±10.53ms     6.0 MB/sec
formatter/vue.global.prod.js             1.00     82.1±0.99ms  1503.5 KB/sec    1.00     81.8±1.36ms  1507.6 KB/sec

enum Indent {
/// Indent by the specified count of indention levels
Simple(u16),
/// Indent `indent` indention levels and add `align` spaces.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent indent indention

LOL! Any chance we can rephrase it a bit? Like:

Indents the given indent, by the specified indentation levels. It then adds the spaces specified by align

@MichaReiser MichaReiser temporarily deployed to aws August 4, 2022 06:18 Inactive
@MichaReiser MichaReiser temporarily deployed to aws August 4, 2022 06:34 Inactive
@MichaReiser MichaReiser merged commit 00c1dfd into main Aug 4, 2022
@MichaReiser MichaReiser deleted the feat/align-ir branch August 4, 2022 09:06
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浏览器服务,不要输入任何密码和下载