Skip to content

[Clippy] Fix various clippy warnings #50

@sorafujitani

Description

@sorafujitani

Summary

Address multiple clippy warnings to improve code quality and idiomatic Rust usage.

Warnings to Fix

1. unused_self warnings

File: ext/rfmt/src/parser/prism_adapter.rs:17, 80

fn parse_json(&self, json: &str) -> ...  // &self unused
fn convert_comment(&self, comment: &PrismComment) -> ...  // &self unused

Fix: Convert to associated functions:

fn parse_json(json: &str) -> ...
fn convert_comment(comment: &PrismComment) -> ...

2. match_same_arms warning

File: ext/rfmt/src/parser/prism_adapter.rs:82-91

"line" => CommentType::Line,
"block" => CommentType::Block,
_ => CommentType::Line,  // Same as "line" arm

Fix: Combine arms:

"block" => CommentType::Block,
_ => CommentType::Line,

3. doc_markdown warnings

Files: ext/rfmt/src/error/mod.rs:32, ext/rfmt/src/parser/prism_adapter.rs:16,29,79

/// Convert RfmtError to Magnus Error for Ruby interop

Fix: Add backticks around type names:

/// Convert `RfmtError` to Magnus `Error` for Ruby interop

4. struct_excessive_bools warning

File: ext/rfmt/src/ast/mod.rs:423

pub struct FormattingInfo {
    pub needs_blank_line_before: bool,
    pub needs_blank_line_after: bool,
    pub preserve_newlines: bool,
    pub multiline: bool,
}

Fix (optional): Use bitflags:

use bitflags::bitflags;

bitflags! {
    pub struct FormattingFlags: u8 {
        const NEEDS_BLANK_LINE_BEFORE = 0b0001;
        const NEEDS_BLANK_LINE_AFTER = 0b0010;
        const PRESERVE_NEWLINES = 0b0100;
        const MULTILINE = 0b1000;
    }
}

Files to Modify

  • ext/rfmt/src/parser/prism_adapter.rs
  • ext/rfmt/src/error/mod.rs
  • ext/rfmt/src/ast/mod.rs (optional bitflags change)

Acceptance Criteria

  • cargo clippy reports no warnings
  • All existing tests pass
  • No functional changes to behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions