Skip to content

feat(formatter): normalize line break for directive#17303

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-23-feat_formatter_normalize_line_break_for_directive
Dec 24, 2025
Merged

feat(formatter): normalize line break for directive#17303
graphite-app[bot] merged 1 commit intomainfrom
12-23-feat_formatter_normalize_line_break_for_directive

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Dec 23, 2025

Fixes panic caused by

/// Debug assert that the given text contains no `\r` line terminator characters.
//
// `#[inline(always)]` because this is a no-op in release mode
#[inline(always)]
#[expect(clippy::inline_always)]
#[track_caller]
fn debug_assert_no_cr_line_break(text: &str) {
debug_assert!(
!text.contains('\r'),
"The content `{text}` contains an unsupported `\\r` line terminator character but text must only use line feeds `\\n` as line separator. Use `\\n` instead of `\\r` and `\\r\\n` to insert a line break in strings."
);
}

in #17261

Copilot AI review requested due to automatic review settings December 23, 2025 08:43
@github-actions github-actions bot added A-formatter Area - Formatter C-enhancement Category - New feature or request labels Dec 23, 2025
Copy link
Member Author

Dunqing commented Dec 23, 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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

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 adds line break normalization for directive strings in the formatter. The main changes normalize carriage return characters (\r) to newlines (\n) in directive strings while preserving the directive's quote style and escape sequences.

Key changes:

  • Fixes typo in comment: "diretcives" → "directives"
  • Removes #[expect(unused)] attribute from normalize_newlines function (now being used)
  • Updates normalize_directive to call normalize_newlines on directive content and handle both borrowed and owned results

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/oxc_formatter/src/formatter/format_element/mod.rs Removes unused warning attribute since normalize_newlines is now actively used
crates/oxc_formatter/src/utils/string.rs Fixes typo and adds newline normalization logic to normalize_directive method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 23, 2025

CodSpeed Performance Report

Merging #17303 will not alter performance

Comparing 12-23-feat_formatter_normalize_line_break_for_directive (bbb5a43) with main (c813582)1

Summary

✅ 38 untouched
⏩ 7 skipped2

Footnotes

  1. No successful run was found on main (c6690d1) during the generation of this report, so c813582 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Dunqing Dunqing force-pushed the 12-23-feat_formatter_normalize_line_break_for_directive branch from 4f1fcf9 to bbb5a43 Compare December 23, 2025 14:16
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 24, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Dec 24, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 12-23-feat_formatter_normalize_line_break_for_directive branch from bbb5a43 to b00da37 Compare December 24, 2025 01:05
@graphite-app graphite-app bot merged commit b00da37 into main Dec 24, 2025
20 checks passed
@graphite-app graphite-app bot deleted the 12-23-feat_formatter_normalize_line_break_for_directive branch December 24, 2025 01:11
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-formatter Area - Formatter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants