Skip to content

Commit 2bf9347

Browse files
authored
chore(rust): Fix needless_doctest_main lint by updating parser_tsx example (#12996)
1 parent 70f742a commit 2bf9347

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ unused_peekable = "warn"
9696
too_long_first_doc_paragraph = "warn"
9797
suspicious_operation_groupings = "warn"
9898
redundant_clone = "warn"
99-
needless_doctest_main = "allow" # FIXME
10099
zero_sized_map_values = "allow" # FIXME https://github.com/rust-lang/rust-clippy/issues/15429
101100
# cargo
102101
cargo = { level = "warn", priority = -1 }

crates/oxc_parser/examples/parser_tsx.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use oxc_parser::{Parser, ParserReturn};
1414
use oxc_span::SourceType;
1515

1616
/// Parse a TypeScript JSX file and validate the results
17-
fn main() {
17+
fn main() -> Result<(), String> {
1818
let source_text = r"
1919
import React from 'react';
2020
@@ -45,8 +45,16 @@ export const Counter: React.FC = () => {
4545
..
4646
} = Parser::new(&allocator, source_text, source_type).parse();
4747

48-
assert!(!panicked);
49-
assert!(errors.is_empty());
48+
if panicked {
49+
return Err("Parser panicked".to_string());
50+
}
51+
52+
if !errors.is_empty() {
53+
return Err(format!("Parsing errors: {}", errors.len()));
54+
}
55+
5056
assert!(!program.body.is_empty());
5157
assert_eq!(program.comments.len(), 1);
58+
59+
Ok(())
5260
}

0 commit comments

Comments
 (0)