Skip to content

Commit daead30

Browse files
committed
fix(tasks/prettier_conformance): Skip tests which cannot parse (#15025)
If the parser reports a syntax error, simply skip the test. `oxfmt` already reports error for this case. By this change, tests containing unsupported syntax such as stage 2, 3 will be automatically ignored. I'll add notes in the line comments to explain what they were like.
1 parent 5de99c2 commit daead30

File tree

4 files changed

+27
-38
lines changed

4 files changed

+27
-38
lines changed

tasks/prettier_conformance/snapshots/prettier.js.snap.md

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
js compatibility: 656/749 (87.58%)
1+
js compatibility: 673/749 (89.85%)
22

33
# Failed
44

@@ -17,27 +17,11 @@ js compatibility: 656/749 (87.58%)
1717
| js/comments/if.js | 💥💥 | 74.83% |
1818
| js/comments/return-statement.js | 💥💥 | 98.28% |
1919
| js/comments/tagged-template-literal.js | 💥💥 | 92.86% |
20-
| js/comments/html-like/comment.js | 💥 | 0.00% |
2120
| js/comments/tagged-template-literal/11662.js | 💥 | 80.00% |
2221
| js/conditional/comments.js | 💥✨ | 23.69% |
2322
| js/conditional/new-ternary-examples.js | 💥✨ | 20.14% |
2423
| js/conditional/new-ternary-spec.js | 💥✨ | 24.35% |
2524
| js/conditional/postfix-ternary-regressions.js | 💥✨ | 20.77% |
26-
| js/discard-binding/array-pattern.js | 💥 | 0.00% |
27-
| js/discard-binding/basic.js | 💥 | 0.00% |
28-
| js/discard-binding/discard-binding-arrow-params.js | 💥 | 0.00% |
29-
| js/discard-binding/discard-binding-assignment.js | 💥 | 0.00% |
30-
| js/discard-binding/discard-binding-async-arrow-params.js | 💥 | 0.00% |
31-
| js/discard-binding/discard-binding-bindings.js | 💥 | 0.00% |
32-
| js/discard-binding/discard-binding-for-await-using-binding.js | 💥 | 0.00% |
33-
| js/discard-binding/discard-binding-for-bindings.js | 💥 | 0.00% |
34-
| js/discard-binding/discard-binding-for-lhs.js | 💥 | 0.00% |
35-
| js/discard-binding/discard-binding-for-using-binding.js | 💥 | 0.00% |
36-
| js/discard-binding/function-parameter.js | 💥 | 0.00% |
37-
| js/discard-binding/object-pattern.js | 💥 | 0.00% |
38-
| js/discard-binding/unary-expression-void.js | 💥 | 0.00% |
39-
| js/discard-binding/using-variable-declarator.js | 💥 | 0.00% |
40-
| js/discard-binding/using.js | 💥 | 0.00% |
4125
| js/explicit-resource-management/for-await-using-of-comments.js | 💥 | 0.00% |
4226
| js/explicit-resource-management/valid-await-using-comments.js | 💥 | 66.67% |
4327
| js/for/9812-unstable.js | 💥 | 45.45% |
@@ -90,7 +74,6 @@ js compatibility: 656/749 (87.58%)
9074
| js/test-declarations/angularjs_inject.js | 💥💥 | 91.53% |
9175
| js/test-declarations/test_declarations.js | 💥💥 | 95.88% |
9276
| js/trailing-comma/dynamic-import.js | 💥💥💥 | 0.00% |
93-
| jsx/expression-with-types/expression.js | 💥💥💥💥 | 0.00% |
9477
| jsx/fbt/test.js | 💥 | 84.06% |
9578
| jsx/jsx/quotes.js | 💥💥💥💥 | 79.41% |
9679
| jsx/jsx/regex.js | 💥💥💥💥 | 75.00% |

tasks/prettier_conformance/snapshots/prettier.ts.snap.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
ts compatibility: 532/598 (88.96%)
1+
ts compatibility: 537/598 (89.80%)
22

33
# Failed
44

55
| Spec path | Failed or Passed | Match ratio |
66
| :-------- | :--------------: | :---------: |
7-
| jsx/expression-with-types/expression.js | 💥💥💥💥 | 0.00% |
87
| jsx/fbt/test.js | 💥 | 84.06% |
98
| jsx/jsx/quotes.js | 💥💥💥💥 | 79.41% |
109
| jsx/jsx/regex.js | 💥💥💥💥 | 75.00% |
@@ -36,9 +35,7 @@ ts compatibility: 532/598 (88.96%)
3635
| typescript/conditional-types/nested-in-condition.ts | 💥✨ | 15.79% |
3736
| typescript/conditional-types/new-ternary-spec.ts | 💥✨ | 10.67% |
3837
| typescript/conditional-types/parentheses.ts | 💥✨ | 15.22% |
39-
| typescript/conformance/types/functions/functionOverloadErrorsSyntax.ts | 💥 | 0.00% |
4038
| typescript/decorators-ts/angular.ts | 💥 | 87.50% |
41-
| typescript/definite/without-annotation.ts | 💥 | 91.67% |
4239
| typescript/import-require/comments.ts | 💥 | 33.33% |
4340
| typescript/import-type/long-module-name/long-module-name2.ts | 💥 | 25.00% |
4441
| typescript/import-type/long-module-name/long-module-name4.ts | 💥 | 89.29% |
@@ -61,8 +58,6 @@ ts compatibility: 532/598 (88.96%)
6158
| typescript/prettier-ignore/mapped-types.ts | 💥 | 96.61% |
6259
| typescript/property-signature/consistent-with-flow/comments.ts | 💥 | 80.00% |
6360
| typescript/property-signature/consistent-with-flow/union.ts | 💥 | 85.71% |
64-
| typescript/type-arguments-bit-shift-left-like/3.ts | 💥 | 0.00% |
65-
| typescript/type-arguments-bit-shift-left-like/5.tsx | 💥 | 0.00% |
6661
| typescript/type-params/18041.ts | 💥 | 43.75% |
6762
| typescript/type-params/constraints-and-default-2.ts | 💥 | 97.60% |
6863
| typescript/type-params/constraints-and-default.ts | 💥 | 87.32% |

tasks/prettier_conformance/src/ignore_list.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ pub const IGNORE_TESTS: &[&str] = &[
7676
// non-standard syntax
7777
"js/deferred-import-evaluation",
7878
"js/bind-expressions",
79-
// Unsupported stage3 features
80-
"tuple-and-record.js",
81-
"js/async-do-expressions",
8279
// Babel plugins (mostly experimental syntaxes)
8380
"js/babel-plugins",
8481
"js/destructuring-private-fields",

tasks/prettier_conformance/src/lib.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use similar::TextDiff;
1515
use walkdir::WalkDir;
1616

1717
use oxc_allocator::Allocator;
18-
use oxc_formatter::{FormatOptions, Formatter, get_parse_options};
18+
use oxc_formatter::{FormatOptions, Formatter, enable_jsx_source_type, get_parse_options};
1919
use oxc_parser::Parser;
2020
use oxc_span::SourceType;
2121

@@ -240,12 +240,18 @@ impl TestRunner {
240240
)
241241
.unwrap();
242242

243+
let Some(actual) =
244+
Self::run_oxc_formatter(path, &source_text, format_options.clone())
245+
else {
246+
// Skip the test if parsing failed
247+
if self.options.debug {
248+
println!(" => Skipped (parsing failed)");
249+
}
250+
continue;
251+
};
252+
243253
let actual = Self::replace_escape_and_eol(
244-
&Self::run_oxc_formatter(
245-
&source_text,
246-
SourceType::from_path(path).unwrap(),
247-
format_options.clone(),
248-
),
254+
&actual,
249255
expected.contains("LF>") || expected.contains("<CR"),
250256
);
251257

@@ -414,15 +420,23 @@ impl TestRunner {
414420
}
415421

416422
fn run_oxc_formatter(
423+
path: &Path,
417424
source_text: &str,
418-
source_type: SourceType,
419-
formatter_options: FormatOptions,
420-
) -> String {
425+
format_options: FormatOptions,
426+
) -> Option<String> {
421427
let allocator = Allocator::default();
422-
let source_type = source_type.with_jsx(source_type.is_javascript());
428+
429+
let source_type = SourceType::from_path(path).unwrap();
430+
let source_type = enable_jsx_source_type(source_type);
431+
423432
let ret = Parser::new(&allocator, source_text, source_type)
424433
.with_options(get_parse_options())
425434
.parse();
426-
Formatter::new(&allocator, formatter_options).build(&ret.program)
435+
if !ret.errors.is_empty() {
436+
return None;
437+
}
438+
439+
let formatted = Formatter::new(&allocator, format_options).build(&ret.program);
440+
Some(formatted)
427441
}
428442
}

0 commit comments

Comments
 (0)