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

feat(rome_js_formatter): jestEach template literals #3308 #3582

Merged
merged 1 commit into from
Nov 14, 2022

Conversation

denbezrukov
Copy link
Contributor

Summary

Close #3308

Test Plan

cargo test -p rome_js_formatter

@netlify
Copy link

netlify bot commented Nov 8, 2022

Deploy Preview for docs-rometools canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 30cb7b9
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/6371f1f6b3a56c0008050e3b

@denbezrukov denbezrukov force-pushed the jest-each branch 2 times, most recently from 0dbece5 to 119ea23 Compare November 8, 2022 08:23
text.push_str(&padding);
}

text.push(' ');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wondering if we could use space instead of ' '

Copy link
Contributor

Choose a reason for hiding this comment

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

space won't work because our printer de-duplicates spaces (space(), space() gets printed as a single space).

You can try to use align instead but I think using ' ' is fine.

Copy link
Contributor

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Awesome work. I have some small nit comments.

One thing we need to look into is guarding against skipped token trivia on elements that you remove. Because that would result in the skipped token trivia being emitted before the template.

I recommend testing for skipped token trivia in the is_test_each_pattern and bail out if it has any.

The alternative is to use the FormatError::PoorLayout and catch the template formatting error to fall back to the default formatting. I think explicitly testing is nicer and the overhead should be reasonable (considering the complexity of doing the formatting).

crates/rome_js_formatter/src/utils/test_each_pattern.rs Outdated Show resolved Hide resolved
crates/rome_js_formatter/src/utils/test_each_pattern.rs Outdated Show resolved Hide resolved
crates/rome_js_formatter/src/utils/test_each_pattern.rs Outdated Show resolved Hide resolved
crates/rome_js_formatter/src/utils/test_each_pattern.rs Outdated Show resolved Hide resolved
crates/rome_js_formatter/src/utils/test_each_pattern.rs Outdated Show resolved Hide resolved
crates/rome_js_formatter/src/utils/test_each_pattern.rs Outdated Show resolved Hide resolved
crates/rome_js_formatter/src/utils/test_each_pattern.rs Outdated Show resolved Hide resolved
crates/rome_js_formatter/src/utils/test_each_pattern.rs Outdated Show resolved Hide resolved
crates/rome_js_formatter/src/utils/test_each_pattern.rs Outdated Show resolved Hide resolved
text.push_str(&padding);
}

text.push(' ');
Copy link
Contributor

Choose a reason for hiding this comment

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

space won't work because our printer de-duplicates spaces (space(), space() gets printed as a single space).

You can try to use align instead but I think using ' ' is fine.

@denbezrukov denbezrukov force-pushed the jest-each branch 3 times, most recently from 4b329e9 to 9bab47f Compare November 9, 2022 08:14
@denbezrukov
Copy link
Contributor Author

Awesome work. I have some small nit comments.

One thing we need to look into is guarding against skipped token trivia on elements that you remove. Because that would result in the skipped token trivia being emitted before the template.

I recommend testing for skipped token trivia in the is_test_each_pattern and bail out if it has any.

The alternative is to use the FormatError::PoorLayout and catch the template formatting error to fall back to the default formatting. I think explicitly testing is nicer and the overhead should be reasonable (considering the complexity of doing the formatting).

Thank you for your review!

I added is_test_each_pattern_elements function, where we test that each node we remove does not contain any trivia.

Copy link
Contributor

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Awesome work!

I'll merge it after we pushed the 10.0.1 patch release.

Comment on lines 189 to 193
if leading_trivia.pieces().next().is_some() {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the test asserting if it has any skipped token trivia?

That's probably going to work but using leading_trivia.has_skipped() is more explicit and easier to understand to readers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@MichaReiser
Copy link
Contributor

!bench_formatter

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Formatter Benchmark Results

group                                    main                                   pr
-----                                    ----                                   --
formatter/checker.ts                     1.02    415.6±3.01ms     6.3 MB/sec    1.00    406.9±2.49ms     6.4 MB/sec
formatter/compiler.js                    1.01    219.5±1.62ms     4.8 MB/sec    1.00    218.1±1.14ms     4.8 MB/sec
formatter/d3.min.js                      1.01    172.6±2.05ms  1554.8 KB/sec    1.00    170.8±1.69ms  1571.3 KB/sec
formatter/dojo.js                        1.00     11.3±0.06ms     6.1 MB/sec    1.00     11.3±0.05ms     6.1 MB/sec
formatter/ios.d.ts                       1.02    244.7±3.31ms     7.6 MB/sec    1.00    240.3±2.73ms     7.8 MB/sec
formatter/jquery.min.js                  1.01     46.1±0.51ms  1834.8 KB/sec    1.00     45.8±0.24ms  1848.3 KB/sec
formatter/math.js                        1.01    339.5±1.93ms  1953.0 KB/sec    1.00    336.0±2.08ms  1973.7 KB/sec
formatter/parser.ts                      1.01      7.7±0.09ms     6.3 MB/sec    1.00      7.6±0.04ms     6.4 MB/sec
formatter/pixi.min.js                    1.00    184.4±1.10ms     2.4 MB/sec    1.00    184.0±1.74ms     2.4 MB/sec
formatter/react-dom.production.min.js    1.01     54.8±0.97ms     2.1 MB/sec    1.00     54.2±0.58ms     2.1 MB/sec
formatter/react.production.min.js        1.00      2.7±0.01ms     2.3 MB/sec    1.00      2.6±0.01ms     2.3 MB/sec
formatter/router.ts                      1.00      6.3±0.03ms     9.6 MB/sec    1.00      6.3±0.04ms     9.6 MB/sec
formatter/tex-chtml-full.js              1.01    435.8±2.63ms     2.1 MB/sec    1.00    430.3±1.65ms     2.1 MB/sec
formatter/three.min.js                   1.01    219.0±1.27ms     2.7 MB/sec    1.00    217.8±1.26ms     2.7 MB/sec
formatter/typescript.js                  1.02   1501.2±6.17ms     6.3 MB/sec    1.00   1469.3±4.27ms     6.5 MB/sec
formatter/vue.global.prod.js             1.00     71.4±0.76ms  1728.1 KB/sec    1.00     71.1±0.74ms  1735.7 KB/sec

@leops leops added this to the 11.0.0 milestone Nov 9, 2022
@MichaReiser MichaReiser requested a review from a team November 14, 2022 07:22
@MichaReiser MichaReiser merged commit 745bdaa into rome:main Nov 14, 2022
jeysal added a commit to jeysal/rometools that referenced this pull request Nov 14, 2022
* upstream/main: (45 commits)
  website(docs): set `color-scheme` on the root element (rome#3721)
  feat(rome_analyze): add a warning for unused suppression comments (rome#3718)
  feat(rome_js_analyze): Implement prefer-numeric-literals lint (rome#3558)
  feat(rome_js_formatter): jestEach template literals rome#3308 (rome#3582)
  doc(website): Add context about Romes philosophy (rome#3714)
  fix(rome_js_formatter): Single-line comment below a JSX prop triggers… (rome#3641)
  test(rome_js_formatter): update prettier tests (rome#3684)
  fix(rome_js_parser): improve await handling in non-async context (rome#3573)
  fix(rome_js_parser): improve yield parsing in non generator function (rome#3622)
  More playground polish
  Fix backgrounds
  Fix height
  Align docs.rome.tools with rome.tools
  Reenable compression
  Add missing width
  website(docs): More playground IDE features (rome#3711)
  fix(rome_js_formatter): new expression attribute (rome#3686)
  docs(website): added checkbox to toggle linter in playground (rome#3699)
  website(docs): More website tweaks (rome#3707)
  website(docs): Add default layout property (rome#3705)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📎 Formatter: Format jestEach template literals
3 participants