-
-
Notifications
You must be signed in to change notification settings - Fork 721
chore(rust): Fix needless_doctest_main lint by updating parser_tsx example #12996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(rust): Fix needless_doctest_main lint by updating parser_tsx example #12996
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
CodSpeed Instrumentation Performance ReportMerging #12996 will not alter performanceComparing Summary
|
needless_doctest_main = "allow" @oxc-project/oxc/files/Cargo.toml and fix the offender.…s requested Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the needless_doctest_main clippy lint by updating the parser_tsx.rs example to return a Result type instead of (), which is the expected pattern for doctests included in library documentation.
- Changed
fn main()tofn main() -> Result<(), String>in the parser_tsx example - Removed the
needless_doctest_main = "allow"lint suppression from Cargo.toml - Improved error handling by replacing assertions with proper Result-based error handling
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/oxc_parser/examples/parser_tsx.rs | Updated main function signature and error handling to return Result type |
| Cargo.toml | Removed needless_doctest_main lint suppression |
Summary
Fixes the
needless_doctest_mainclippy lint by updating theparser_tsx.rsexample to match the expected pattern for doctests included in library documentation.Root Cause
The
needless_doctest_mainlint was triggered becauseparser_tsx.rsis included as a doctest in the library documentation via:Clippy expects doctests with
fn main()to return aResulttype to handle potential errors, not(). Theparser.rsexample didn't trigger this warning because it already returnedResult<(), String>.Changes Made
Removed lint suppression: Deleted
needless_doctest_main = "allow" # FIXMEfromCargo.tomlUpdated function signature: Changed
fn main()tofn main() -> Result<(), String>inparser_tsx.rsImproved error handling: Added proper error handling to utilize the Result type:
Enhanced output: Added informative console output showing parse results
Added lint attribute: Added
#![expect(clippy::print_stdout)]to allow console output in examplesVerification
needless_doctest_mainwarnings when running clippycargo run -p oxc_parser --example parser_tsxjust readycompletes successfullyparser.rsThe solution is minimal and surgical, only modifying 2 files with the smallest possible changes to resolve the lint issue while improving the example's robustness.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.