@@ -7,6 +7,7 @@ use crate::{
77 prelude:: { if_group_breaks, token} ,
88 printer:: PrinterOptions ,
99 } ,
10+ ir_transform:: options:: SortImportsOptions ,
1011 write,
1112} ;
1213
@@ -71,9 +72,8 @@ pub struct FormatOptions {
7172 /// Enable formatting for embedded languages (e.g., CSS, SQL, GraphQL) within template literals. Defaults to "auto".
7273 pub embedded_language_formatting : EmbeddedLanguageFormatting ,
7374
74- // TODO: `FormatOptions`? Split out as `TransformOptions`?
7575 /// Sort import statements. By default disabled.
76- pub experimental_sort_imports : Option < SortImports > ,
76+ pub experimental_sort_imports : Option < SortImportsOptions > ,
7777}
7878
7979impl FormatOptions {
@@ -978,93 +978,3 @@ impl fmt::Display for EmbeddedLanguageFormatting {
978978 f. write_str ( s)
979979 }
980980}
981-
982- // ---
983-
984- #[ derive( Clone , Debug , Eq , PartialEq ) ]
985- pub struct SortImports {
986- /// Partition imports by newlines.
987- /// Default is `false`.
988- pub partition_by_newline : bool ,
989- /// Partition imports by comments.
990- /// Default is `false`.
991- pub partition_by_comment : bool ,
992- /// Sort side effects imports.
993- /// Default is `false`.
994- pub sort_side_effects : bool ,
995- /// Sort order (asc or desc).
996- /// Default is ascending (asc).
997- pub order : SortOrder ,
998- /// Ignore case when sorting.
999- /// Default is `true`.
1000- pub ignore_case : bool ,
1001- /// Whether to insert blank lines between different import groups.
1002- /// - `true`: Insert one blank line between groups (default)
1003- /// - `false`: No blank lines between groups
1004- ///
1005- /// NOTE: Cannot be used together with `partition_by_newline: true`.
1006- pub newlines_between : bool ,
1007- /// Prefixes for internal imports.
1008- /// If `None`, uses the default internal patterns.
1009- pub internal_pattern : Option < Vec < String > > ,
1010- /// Groups configuration for organizing imports.
1011- /// Each inner `Vec` represents a group, and multiple group names in the same `Vec` are treated as one.
1012- /// If `None`, uses the default groups.
1013- pub groups : Option < Vec < Vec < String > > > ,
1014- }
1015-
1016- impl Default for SortImports {
1017- fn default ( ) -> Self {
1018- Self {
1019- partition_by_newline : false ,
1020- partition_by_comment : false ,
1021- sort_side_effects : false ,
1022- order : SortOrder :: default ( ) ,
1023- ignore_case : true ,
1024- newlines_between : true ,
1025- internal_pattern : None ,
1026- groups : None ,
1027- }
1028- }
1029- }
1030-
1031- #[ derive( Clone , Copy , Debug , Default , Eq , Hash , PartialEq ) ]
1032- pub enum SortOrder {
1033- /// Sort in ascending order (A-Z).
1034- #[ default]
1035- Asc ,
1036- /// Sort in descending order (Z-A).
1037- Desc ,
1038- }
1039-
1040- impl SortOrder {
1041- pub const fn is_asc ( self ) -> bool {
1042- matches ! ( self , Self :: Asc )
1043- }
1044-
1045- pub const fn is_desc ( self ) -> bool {
1046- matches ! ( self , Self :: Desc )
1047- }
1048- }
1049-
1050- impl FromStr for SortOrder {
1051- type Err = & ' static str ;
1052-
1053- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
1054- match s {
1055- "asc" => Ok ( Self :: Asc ) ,
1056- "desc" => Ok ( Self :: Desc ) ,
1057- _ => Err ( "Value not supported for SortOrder. Supported values are 'asc' and 'desc'." ) ,
1058- }
1059- }
1060- }
1061-
1062- impl fmt:: Display for SortOrder {
1063- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1064- let s = match self {
1065- SortOrder :: Asc => "ASC" ,
1066- SortOrder :: Desc => "DESC" ,
1067- } ;
1068- f. write_str ( s)
1069- }
1070- }
0 commit comments