This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 657
Named imports formatting #2441
Labels
Comments
45 tasks
I translate the use rome_formatter::{
format_element::ConditionalGroupContent, hard_line_break, indent, soft_block_indent,
soft_line_break_or_space, space_token, LineWidth,
};
fn main() {
use rome_formatter::{
format_elements, group_elements, soft_line_break, token, FormatOptions, Formatted,
};
let elements = group_elements(format_elements![
token("{"),
soft_block_indent(format_elements![
soft_line_break_or_space(),
token("somethingSuperLongsomethingSuperLong2"),
// space_token(),
ConditionalGroupContent::new(
token(","),
rome_formatter::format_element::GroupPrintMode::Multiline
)
]),
token("}"),
space_token(),
token("from"),
space_token(),
token("\"somethingSuperLongsomethingSuperLongsomethingSuperLong\""),
token(";"),
]);
// List [
// SyntaxTokenSlice("import"),
// Space,
// SyntaxTokenSlice("ww"),
// SyntaxTokenSlice(","),
// Space,
// Group(
// List [
// SyntaxTokenSlice("{"),
// Indent(
// List [
// Line(SoftOrSpace),
// SyntaxTokenSlice("somethingSuperLongsomethingSuperLong2"),
// ConditionalGroupContent {
// content: StaticToken(","),
// mode: Multiline,
// },
// ],
// ),
// Line(SoftOrSpace),
// SyntaxTokenSlice("}"),
// ],
// ),
// Space,
// SyntaxTokenSlice("from"),
// Space,
// DynamicToken("\"somethingSuperLongsomethingSuperLongsomethingSuperLong\""),
// StaticToken(";"),
// SyntaxTokenSlice(""),
// Line(Hard),
// ]
let elements = format_elements![
token("import"),
space_token(),
token("ww"),
token(","),
space_token(),
elements,
// hard_line_break()
];
println!(
"{}",
Formatted::new(elements, FormatOptions::default())
.print()
.as_code()
);
// assert_eq!(
// "a,b",
// Formatted::new(elements, FormatOptions::default())
// .print()
// .as_code()
// );
} It prints import ww, {
somethingSuperLongsomethingSuperLong2,
} from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; when I adjust import ww, { somethingSuperLongsomethingSuperLong2} from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; it should be the same as |
#2498 |
ematipico
added
the
I-Normal
Implementation: normal understanding of the tool and awareness
label
May 5, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
Prettier breaks the named imports if the whole
import
statements exceed the line width, Rome only does so if the named imports exceed the line width PlaygroundInput
Prettier
Rome
Expected
Rome's formatting to match Prettier's
The text was updated successfully, but these errors were encountered: