@@ -15,16 +15,16 @@ pub struct AttributeOrderingConverter {
1515
1616#[ derive( Debug , Clone ) ]
1717struct AttributeOrderingViolation {
18- start_offset : usize , // Offset of '{'
19- end_offset : usize , // Offset of '}' + 1
20- original : String , // Original attrs including braces
18+ start_offset : usize , // Offset of '{'
19+ end_offset : usize , // Offset of '}' + 1
20+ original : String , // Original attrs including braces
2121 error_location : Option < SourceLocation > , // For reporting
2222}
2323
2424impl AttributeOrderingConverter {
2525 pub fn new ( ) -> Result < Self > {
26- let pandoc_output_regex = Regex :: new ( r"^\[\]\{(.+)\}\s*$" )
27- . context ( "Failed to compile pandoc output regex" ) ?;
26+ let pandoc_output_regex =
27+ Regex :: new ( r"^\[\]\{(.+)\}\s*$" ) . context ( "Failed to compile pandoc output regex" ) ?;
2828
2929 Ok ( Self {
3030 pandoc_output_regex,
@@ -48,6 +48,7 @@ impl AttributeOrderingConverter {
4848 false , // not loose mode
4949 & filename,
5050 & mut sink,
51+ true ,
5152 ) ;
5253
5354 let diagnostics = match result {
@@ -101,7 +102,11 @@ impl AttributeOrderingConverter {
101102 let bytes = content. as_bytes ( ) ;
102103
103104 if error_offset >= bytes. len ( ) {
104- return Err ( anyhow ! ( "Error offset {} is beyond content length {}" , error_offset, bytes. len( ) ) ) ;
105+ return Err ( anyhow ! (
106+ "Error offset {} is beyond content length {}" ,
107+ error_offset,
108+ bytes. len( )
109+ ) ) ;
105110 }
106111
107112 // Search backward for '{'
@@ -110,7 +115,10 @@ impl AttributeOrderingConverter {
110115 start -= 1 ;
111116 }
112117 if bytes[ start] != b'{' {
113- return Err ( anyhow ! ( "Could not find opening brace before offset {}" , error_offset) ) ;
118+ return Err ( anyhow ! (
119+ "Could not find opening brace before offset {}" ,
120+ error_offset
121+ ) ) ;
114122 }
115123
116124 // Search forward for '}'
@@ -119,7 +127,10 @@ impl AttributeOrderingConverter {
119127 end += 1 ;
120128 }
121129 if end >= bytes. len ( ) || bytes[ end] != b'}' {
122- return Err ( anyhow ! ( "Could not find closing brace after offset {}" , error_offset) ) ;
130+ return Err ( anyhow ! (
131+ "Could not find closing brace after offset {}" ,
132+ error_offset
133+ ) ) ;
123134 }
124135
125136 Ok ( ( start, end + 1 ) ) // +1 to include the '}'
@@ -142,20 +153,22 @@ impl AttributeOrderingConverter {
142153 . context ( "Failed to spawn pandoc. Is pandoc installed?" ) ?;
143154
144155 if let Some ( mut stdin) = child. stdin . take ( ) {
145- stdin. write_all ( input. as_bytes ( ) )
156+ stdin
157+ . write_all ( input. as_bytes ( ) )
146158 . context ( "Failed to write to pandoc stdin" ) ?;
147159 }
148160
149- let output = child. wait_with_output ( )
161+ let output = child
162+ . wait_with_output ( )
150163 . context ( "Failed to wait for pandoc" ) ?;
151164
152165 if !output. status . success ( ) {
153166 let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
154167 return Err ( anyhow ! ( "Pandoc failed: {}" , stderr) ) ;
155168 }
156169
157- let stdout = String :: from_utf8 ( output . stdout )
158- . context ( "Pandoc output is not valid UTF-8" ) ?;
170+ let stdout =
171+ String :: from_utf8 ( output . stdout ) . context ( "Pandoc output is not valid UTF-8" ) ?;
159172
160173 // Extract normalized attrs from "[]{...}"
161174 if let Some ( caps) = self . pandoc_output_regex . captures ( stdout. trim ( ) ) {
@@ -181,14 +194,14 @@ impl AttributeOrderingConverter {
181194 let mut result = content. to_string ( ) ;
182195
183196 for violation in violations {
184- let normalized = self . normalize_with_pandoc ( & violation. original )
185- . with_context ( || format ! ( "Failed to normalize attributes: {}" , violation. original) ) ?;
197+ let normalized = self
198+ . normalize_with_pandoc ( & violation. original )
199+ . with_context ( || {
200+ format ! ( "Failed to normalize attributes: {}" , violation. original)
201+ } ) ?;
186202
187203 // Replace original with normalized
188- result. replace_range (
189- violation. start_offset ..violation. end_offset ,
190- & normalized
191- ) ;
204+ result. replace_range ( violation. start_offset ..violation. end_offset , & normalized) ;
192205 }
193206
194207 Ok ( result)
@@ -201,7 +214,10 @@ impl AttributeOrderingConverter {
201214
202215 /// Convert byte offset to column number (0-indexed)
203216 fn offset_to_column ( & self , content : & str , offset : usize ) -> usize {
204- let line_start = content[ ..offset] . rfind ( '\n' ) . map ( |pos| pos + 1 ) . unwrap_or ( 0 ) ;
217+ let line_start = content[ ..offset]
218+ . rfind ( '\n' )
219+ . map ( |pos| pos + 1 )
220+ . unwrap_or ( 0 ) ;
205221 offset - line_start
206222 }
207223}
@@ -225,10 +241,7 @@ impl Rule for AttributeOrderingConverter {
225241 file_path : file_path. to_string_lossy ( ) . to_string ( ) ,
226242 has_issue : true ,
227243 issue_count : 1 ,
228- message : Some ( format ! (
229- "Attribute ordering violation: {}" ,
230- v. original
231- ) ) ,
244+ message : Some ( format ! ( "Attribute ordering violation: {}" , v. original) ) ,
232245 location : v. error_location ,
233246 error_code : None ,
234247 error_codes : None ,
0 commit comments