Skip to content

Commit

Permalink
refactor(prettier): Update tasks/prettier to correctly handle snapsho…
Browse files Browse the repository at this point in the history
…ts (#8337)

I refactored the code in `tasks/prettier_conformance` primarily to make
the output more readable when using `--filter`.

But I also discovered that our previous implementation did not correctly
handle Prettier's behavior of adding a blank line at the EOF.

In addition, I resolved a problem where test specs that used patterns
like `runFormatTest(_, parsers)` were unable to locate the correct
snapshot output.

As a result, compatibility has also improved slightly. 😉

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
leaysgur and autofix-ci[bot] authored Jan 8, 2025
1 parent 6220e05 commit 8e3eed7
Show file tree
Hide file tree
Showing 10 changed files with 425 additions and 437 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/oxc_prettier/src/format/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ impl<'a> Format<'a> for Program<'a> {

if let Some(body_doc) = block::print_block_body(p, &self.body, Some(&self.directives)) {
parts.push(body_doc);
// XXX: Prettier seems to add this, but test results don't match
// parts.extend(hardline!());
parts.extend(hardline!());
}

array!(p, parts)
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_prettier/src/format/print/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn print_block<'a>(
array!(p, parts)
}

/// For `Program` only
pub fn print_block_body<'a>(
p: &mut Prettier<'a>,
stmts: &[Statement<'a>],
Expand Down
1 change: 1 addition & 0 deletions tasks/prettier_conformance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ oxc_prettier = { workspace = true }
oxc_span = { workspace = true }
oxc_tasks_common = { workspace = true }

cow-utils = { workspace = true }
pico-args = { workspace = true }
rustc-hash = { workspace = true }
walkdir = { workspace = true }
9 changes: 2 additions & 7 deletions tasks/prettier_conformance/snapshots/prettier.js.snap.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
js compatibility: 246/641 (38.38%)
js compatibility: 249/641 (38.85%)

# Failed

Expand Down Expand Up @@ -220,9 +220,6 @@ js compatibility: 246/641 (38.38%)
* js/empty-paren-comment/class.js
* js/empty-paren-comment/empty_paren_comment.js

### js/end-of-line
* js/end-of-line/example.js

### js/export
* js/export/blank-line-between-specifiers.js
* js/export/same-local-and-exported.js
Expand Down Expand Up @@ -566,10 +563,8 @@ js compatibility: 246/641 (38.38%)
* jsx/jsx/quotes.js
* jsx/jsx/regex.js
* jsx/jsx/return-statement.js
* jsx/jsx/self-closing.js
* jsx/jsx/spacing.js
* jsx/jsx/template-literal-in-attr.js
* jsx/jsx/ternary.js

### jsx/last-line
* jsx/last-line/last_line.js
Expand Down Expand Up @@ -603,4 +598,4 @@ js compatibility: 246/641 (38.38%)
* jsx/stateless-arrow-fn/test.js

### jsx/text-wrap
* jsx/text-wrap/test.js
* jsx/text-wrap/test.js
9 changes: 2 additions & 7 deletions tasks/prettier_conformance/snapshots/prettier.ts.snap.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ts compatibility: 190/568 (33.45%)
ts compatibility: 193/568 (33.98%)

# Failed

Expand Down Expand Up @@ -54,10 +54,8 @@ ts compatibility: 190/568 (33.45%)
* jsx/jsx/quotes.js
* jsx/jsx/regex.js
* jsx/jsx/return-statement.js
* jsx/jsx/self-closing.js
* jsx/jsx/spacing.js
* jsx/jsx/template-literal-in-attr.js
* jsx/jsx/ternary.js

### jsx/last-line
* jsx/last-line/last_line.js
Expand Down Expand Up @@ -230,9 +228,6 @@ ts compatibility: 190/568 (33.45%)
* typescript/conformance/classes/mixinClassesMembers.ts
* typescript/conformance/classes/nestedClassDeclaration.ts

### typescript/conformance/classes/classDeclarations/classAbstractKeyword
* typescript/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractWithInterface.ts

### typescript/conformance/classes/classDeclarations/classHeritageSpecification
* typescript/conformance/classes/classDeclarations/classHeritageSpecification/classExtendsItselfIndirectly.ts

Expand Down Expand Up @@ -654,4 +649,4 @@ ts compatibility: 190/568 (33.45%)
* typescript/update-expression/update-expressions.ts

### typescript/webhost
* typescript/webhost/webtsc.ts
* typescript/webhost/webtsc.ts
Loading

0 comments on commit 8e3eed7

Please sign in to comment.