Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 11, 2025

Summary

Fixes the needless_doctest_main clippy lint by updating the parser_tsx.rs example to match the expected pattern for doctests included in library documentation.

Root Cause

The needless_doctest_main lint was triggered because parser_tsx.rs is included as a doctest in the library documentation via:

//! ### Parsing TSX
//! ```rust
#![doc = include_str!("../examples/parser_tsx.rs")]
//! ```

Clippy expects doctests with fn main() to return a Result type to handle potential errors, not (). The parser.rs example didn't trigger this warning because it already returned Result<(), String>.

Changes Made

  1. Removed lint suppression: Deleted needless_doctest_main = "allow" # FIXME from Cargo.toml

  2. Updated function signature: Changed fn main() to fn main() -> Result<(), String> in parser_tsx.rs

  3. Improved error handling: Added proper error handling to utilize the Result type:

    if panicked {
        return Err("Parser panicked".to_string());
    }
    
    if !errors.is_empty() {
        return Err(format!("Parsing errors: {}", errors.len()));
    }
  4. Enhanced output: Added informative console output showing parse results

  5. Added lint attribute: Added #![expect(clippy::print_stdout)] to allow console output in examples

Verification

  • ✅ No needless_doctest_main warnings when running clippy
  • ✅ Example runs successfully: cargo run -p oxc_parser --example parser_tsx
  • ✅ All tests pass: just ready completes successfully
  • ✅ Maintains consistency with other examples like parser.rs

The 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.

@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 11, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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>
@github-actions github-actions bot added the A-parser Area - Parser label Aug 11, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 11, 2025

CodSpeed Instrumentation Performance Report

Merging #12996 will not alter performance

Comparing copilot/fix-13a6ed39-a6e0-4a77-ac4d-5c6a5c331d79 (b0a7132) with main (70f742a)

Summary

✅ 34 untouched benchmarks

Copilot AI changed the title [WIP] Remove needless_doctest_main = "allow" @oxc-project/oxc/files/Cargo.toml and fix the offender. Fix needless_doctest_main lint by updating parser_tsx example Aug 11, 2025
Copilot AI requested a review from Boshen August 11, 2025 15:46
Copilot finished work on behalf of Boshen August 11, 2025 15:46
…s requested

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Copilot AI requested a review from Boshen August 11, 2025 16:18
Copilot finished work on behalf of Boshen August 11, 2025 16:18
@Boshen Boshen changed the title Fix needless_doctest_main lint by updating parser_tsx example chore(rust): Fix needless_doctest_main lint by updating parser_tsx example Aug 11, 2025
@Boshen Boshen marked this pull request as ready for review August 11, 2025 16:45
Copilot AI review requested due to automatic review settings August 11, 2025 16:45
@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label Aug 11, 2025
Copy link
Contributor

Copilot AI left a 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() to fn 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

@Boshen Boshen merged commit 2bf9347 into main Aug 11, 2025
31 of 32 checks passed
@Boshen Boshen deleted the copilot/fix-13a6ed39-a6e0-4a77-ac4d-5c6a5c331d79 branch August 11, 2025 16:50
taearls pushed a commit to taearls/oxc that referenced this pull request Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants