Skip to content

formatter: Support ignore comment on same line #16915

@david-crespo

Description

@david-crespo

This may be non-standard because the Prettier ignore docs don't mention it, but Prettier supports putting the // prettier-ignore comment on the same line as the code you want ignored (example). Oxfmt supports this on the line before (#14808), but not on the same line. I think it would be perfectly reasonable to close this as a wontfix — just wanted to flag it in case full compatibility is the goal. This is the source of like 95% of the diff vs. Prettier when I tried oxfmt just now on the oxidecomputer/console codebase.

/// Checks if the node has a suppression comment (prettier-ignore).
pub fn is_suppressed(&self, start: u32) -> bool {
self.comments_before(start).iter().any(|comment| self.is_suppression_comment(comment))
}
pub fn is_suppression_comment(&self, comment: &Comment) -> bool {
// TODO: Consider using `oxfmt-ignore` instead of `prettier-ignore`
self.source_text.text_for(&comment.content_span()).trim() == "prettier-ignore"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-formatterArea - FormatterC-docsCategory - Documentation. Related to user-facing or internal documentationE-Help WantedExperience level - For the experienced collaborators

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions