refactor(formatter): rename write folder to print#17919
refactor(formatter): rename write folder to print#17919graphite-app[bot] merged 1 commit intomainfrom
write folder to print#17919Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
6427b48 to
fcadc6a
Compare
7af3a33 to
9f8ec5e
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
write folder to print
64d7145 to
667659a
Compare
Merge activity
|
This is what I have been wanting to change for a long time, since I worked on the formatter.
The reason is:
The formatter has a macro called `write`, which is used throughout the entire formatting process. Additionally, the formatter has a `write` folder that includes all formatting logic for the AST nodes, so we have two different things called `write`.
That confuses us when you have to import that `write` macro and also need to import other functions from other AST node formatting files
```rs
use crate::{
write, // This is a macro
write::{ // This is a write folder, we wrote all formatting logic for all AST in it
arrow_function_expression::FormatMaybeCachedFunctionBody, semicolon::OptionalSemicolon,
},
};
```
Not only that!! In VSCode, the `rust-analyzer` can help us automatically import functions from other files.
When you don't import `write` marco yet, your imports is like this
```rs
use crate::{
write::{ // This is a write folder, we wrote all formatting logic for all AST in it
arrow_function_expression::FormatMaybeCachedFunctionBody, semicolon::OptionalSemicolon,
},
};
```
And, when typing `write` somewhere, and `rust-analyzer` triggers to import the `write` macro. That's very cool, but unfortunately, since you already have imported something from the write folder, it would import `self` from the write folder.
So the final imports is:
```rs
use crate::{
write::{ // This is a write folder, we wrote all formatting logic for all AST in it
self, arrow_function_expression::FormatMaybeCachedFunctionBody, semicolon::OptionalSemicolon,
// ^^^^ Oh, no, it is totally different things
},
};
```
To avoid these two bad things, I renamed the `write` folder to `print`, making it cleaner and avoiding struggling with a wave of annoying errors.
The wrong `write` imported is like
<img width="1512" height="913" alt="image" src="https://github.com/user-attachments/assets/f9c8392b-297d-4170-b1d7-54cfe3840ab3" />
460248a to
4d5e530
Compare
667659a to
06288ef
Compare

This is what I have been wanting to change for a long time, since I worked on the formatter.
The reason is:
The formatter has a macro called
write, which is used throughout the entire formatting process. Additionally, the formatter has awritefolder that includes all formatting logic for the AST nodes, so we have two different things calledwrite.That confuses us when you have to import that
writemacro and also need to import other functions from other AST node formatting filesNot only that!! In VSCode, the
rust-analyzercan help us automatically import functions from other files.When you don't import
writemarco yet, your imports is like thisAnd, when typing
writesomewhere, andrust-analyzertriggers to import thewritemacro. That's very cool, but unfortunately, since you already have imported something from the write folder, it would importselffrom the write folder.So the final imports is:
To avoid these two bad things, I renamed the
writefolder toprint, making it cleaner and avoiding struggling with a wave of annoying errors.The wrong

writeimported is like