Skip to content

refactor(formatter): rename write folder to print#17919

Merged
graphite-app[bot] merged 1 commit intomainfrom
01-12-refactor_formatter_rename_write_folder_to_print
Jan 13, 2026
Merged

refactor(formatter): rename write folder to print#17919
graphite-app[bot] merged 1 commit intomainfrom
01-12-refactor_formatter_rename_write_folder_to_print

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Jan 12, 2026

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

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

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:

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
image

@github-actions github-actions bot added A-formatter Area - Formatter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Jan 12, 2026
Copy link
Member Author

Dunqing commented Jan 12, 2026


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.

@Dunqing Dunqing force-pushed the 01-12-refactor_formatter_move_call-like_expression_formatting_implementation_to_call_like_expression_module branch from 6427b48 to fcadc6a Compare January 12, 2026 08:22
@Dunqing Dunqing force-pushed the 01-12-refactor_formatter_rename_write_folder_to_print branch from 7af3a33 to 9f8ec5e Compare January 12, 2026 08:23
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 12, 2026

Merging this PR will not alter performance

✅ 38 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing 01-12-refactor_formatter_rename_write_folder_to_print (667659a) with 01-12-refactor_formatter_move_call-like_expression_formatting_implementation_to_call_like_expression_module (460248a)

Open in CodSpeed

Footnotes

  1. 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 changed the title refactor(formatter): rename write folder to print refactor(formatter): rename write folder to print Jan 12, 2026
@Dunqing Dunqing force-pushed the 01-12-refactor_formatter_rename_write_folder_to_print branch 2 times, most recently from 64d7145 to 667659a Compare January 13, 2026 08:50
@github-actions github-actions bot added the A-ast-tools Area - AST tools label Jan 13, 2026
@Dunqing Dunqing requested a review from leaysgur January 13, 2026 08:53
@Dunqing Dunqing marked this pull request as ready for review January 13, 2026 08:53
Copy link
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@leaysgur leaysgur added the 0-merge Merge with Graphite Merge Queue label Jan 13, 2026
Copy link
Member

leaysgur commented Jan 13, 2026

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" />
@graphite-app graphite-app bot force-pushed the 01-12-refactor_formatter_move_call-like_expression_formatting_implementation_to_call_like_expression_module branch from 460248a to 4d5e530 Compare January 13, 2026 09:28
@graphite-app graphite-app bot force-pushed the 01-12-refactor_formatter_rename_write_folder_to_print branch from 667659a to 06288ef Compare January 13, 2026 09:29
Base automatically changed from 01-12-refactor_formatter_move_call-like_expression_formatting_implementation_to_call_like_expression_module to main January 13, 2026 09:34
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 13, 2026
@graphite-app graphite-app bot merged commit 06288ef into main Jan 13, 2026
21 checks passed
@graphite-app graphite-app bot deleted the 01-12-refactor_formatter_rename_write_folder_to_print branch January 13, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools A-formatter Area - Formatter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants