Skip to content

Commit d6f90dd

Browse files
committed
chore(formatter): add --print-width support for the formatter example (#16379)
Add `--print-width` support for the example and change the default to 80 for common cases
1 parent e056f1e commit d6f90dd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

crates/oxc_formatter/examples/formatter.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
use std::{fs, path::Path};
1515

1616
use oxc_allocator::Allocator;
17-
use oxc_formatter::{BracketSameLine, FormatOptions, Formatter, Semicolons, get_parse_options};
17+
use oxc_formatter::{
18+
BracketSameLine, FormatOptions, Formatter, LineWidth, Semicolons, get_parse_options,
19+
};
1820
use oxc_parser::Parser;
1921
use oxc_span::SourceType;
2022
use pico_args::Arguments;
@@ -24,6 +26,7 @@ fn main() -> Result<(), String> {
2426
let mut args = Arguments::from_env();
2527
let no_semi = args.contains("--no-semi");
2628
let show_ir = args.contains("--ir");
29+
let print_width = args.opt_value_from_str::<&'static str, u16>("--print-width").unwrap_or(None);
2730
let name = args.free_from_str().unwrap_or_else(|_| "test.js".to_string());
2831

2932
// Read source file
@@ -46,9 +49,14 @@ fn main() -> Result<(), String> {
4649

4750
// Format the parsed code
4851
let semicolons = if no_semi { Semicolons::AsNeeded } else { Semicolons::Always };
52+
let line_width = match print_width {
53+
Some(width) => LineWidth::try_from(width).unwrap(),
54+
None => LineWidth::try_from(80).unwrap(),
55+
};
4956
let options = FormatOptions {
5057
bracket_same_line: BracketSameLine::from(true),
5158
semicolons,
59+
line_width,
5260
..Default::default()
5361
};
5462

0 commit comments

Comments
 (0)