-
-
Notifications
You must be signed in to change notification settings - Fork 867
refactor(formatter/sort-imports): Move SortImportsOptions to sort_imports/options.rs
#16374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
graphite-app
merged 1 commit into
main
from
12-02-refactor_formatter_sort-imports_move_sortimportsoptions_to_sort_imports_options.rs
Dec 2, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,4 +21,4 @@ | |
|
|
||
| mod sort_imports; | ||
|
|
||
| pub use sort_imports::SortImportsTransform; | ||
| pub use sort_imports::*; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
crates/oxc_formatter/src/ir_transform/sort_imports/options.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| use std::fmt; | ||
| use std::str::FromStr; | ||
|
|
||
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
| pub struct SortImportsOptions { | ||
| /// Partition imports by newlines. | ||
| /// Default is `false`. | ||
| pub partition_by_newline: bool, | ||
| /// Partition imports by comments. | ||
| /// Default is `false`. | ||
| pub partition_by_comment: bool, | ||
| /// Sort side effects imports. | ||
| /// Default is `false`. | ||
| pub sort_side_effects: bool, | ||
| /// Sort order (asc or desc). | ||
| /// Default is ascending (asc). | ||
| pub order: SortOrder, | ||
| /// Ignore case when sorting. | ||
| /// Default is `true`. | ||
| pub ignore_case: bool, | ||
| /// Whether to insert blank lines between different import groups. | ||
| /// - `true`: Insert one blank line between groups (default) | ||
| /// - `false`: No blank lines between groups | ||
| /// | ||
| /// NOTE: Cannot be used together with `partition_by_newline: true`. | ||
| pub newlines_between: bool, | ||
| /// Prefixes for internal imports. | ||
| /// If `None`, uses the default internal patterns. | ||
| pub internal_pattern: Option<Vec<String>>, | ||
| /// Groups configuration for organizing imports. | ||
| /// Each inner `Vec` represents a group, and multiple group names in the same `Vec` are treated as one. | ||
| /// If `None`, uses the default groups. | ||
| pub groups: Option<Vec<Vec<String>>>, | ||
| } | ||
|
|
||
| impl Default for SortImportsOptions { | ||
| fn default() -> Self { | ||
| Self { | ||
| partition_by_newline: false, | ||
| partition_by_comment: false, | ||
| sort_side_effects: false, | ||
| order: SortOrder::default(), | ||
| ignore_case: true, | ||
| newlines_between: true, | ||
| internal_pattern: None, | ||
| groups: None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)] | ||
| pub enum SortOrder { | ||
| /// Sort in ascending order (A-Z). | ||
| #[default] | ||
| Asc, | ||
| /// Sort in descending order (Z-A). | ||
| Desc, | ||
| } | ||
|
|
||
| impl SortOrder { | ||
| pub const fn is_asc(self) -> bool { | ||
| matches!(self, Self::Asc) | ||
| } | ||
|
|
||
| pub const fn is_desc(self) -> bool { | ||
| matches!(self, Self::Desc) | ||
| } | ||
| } | ||
|
|
||
| impl FromStr for SortOrder { | ||
| type Err = &'static str; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| match s { | ||
| "asc" => Ok(Self::Asc), | ||
| "desc" => Ok(Self::Desc), | ||
| _ => Err("Value not supported for SortOrder. Supported values are 'asc' and 'desc'."), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for SortOrder { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| let s = match self { | ||
| SortOrder::Asc => "ASC", | ||
| SortOrder::Desc => "DESC", | ||
| }; | ||
| f.write_str(s) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.