Skip to content

Commit e10d2d7

Browse files
davidBar-Oncalebcartwright
authored andcommitted
Fix issue with extra semicolon when import comment preceeds semicolon
1 parent 4620723 commit e10d2d7

9 files changed

+241
-2
lines changed

Diff for: src/formatting/lists.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -745,11 +745,11 @@ pub(crate) fn extract_post_comment(
745745
post_snippet.trim_matches(white_space)
746746
}
747747
// not comment or over two lines
748-
else if post_snippet.ends_with(',')
748+
else if post_snippet.ends_with(separator)
749749
&& (!post_snippet.trim().starts_with("//") || post_snippet.trim().contains('\n'))
750750
{
751751
post_snippet[..(post_snippet.len() - 1)].trim_matches(white_space)
752-
} else if let Some(sep_pos) = post_snippet.find_uncommented(",") {
752+
} else if let Some(sep_pos) = post_snippet.find_uncommented(separator) {
753753
_post_snippet_without_sep = [
754754
post_snippet[..sep_pos]
755755
.trim_matches(white_space)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// rustfmt-imports_granularity: Crate
2+
3+
// With one comment per item - after the the `;`
4+
use foo1 ; /* 2nd foo1 - comment after ; */
5+
use crate::foo2::bar ; /* 1st foo1::bar - comment after ; */
6+
use crate::foo2::bar ;
7+
8+
// With one comment per item - before the the `;`
9+
use foo3 /* 2nd foo3 - comment before ; */ ;
10+
use crate::foo4::bar /* 1st foo4::bar - comment before ; */ ;
11+
use crate::foo4::bar ;
12+
13+
// With multiline comments or multi comments - after the `;`
14+
use crate::foo5; /* foo5 - Multiline comment before ; line 1
15+
* foo5 - Multiline comment before ; line 2 */
16+
use crate::foo5;
17+
use crate::foo6; // foo6- mixed comments before ; - 1st line comment ;
18+
/* foo6- mixed comments before ; - 2nd block comment */
19+
use crate::foo6;
20+
21+
// With multiline comments or multi comments - before the `;`
22+
use crate::foo7 /* foo7 - Multiline comment before ; line 1
23+
* foo7 - Multiline comment before ; line 2 */ ;
24+
use crate::foo7;
25+
use crate::foo8 // foo8- mixed comments before ; - 1st line comment ;
26+
/* foo8- mixed comments before ; - 2nd block comment */ ;
27+
use crate::foo8;
28+
29+
// With one comment for a module
30+
use crate::foo21::{self} ; /* external comment for foo21 {self} */
31+
use crate::foo21::{foo} ;
32+
use crate::foo21::{bar} ;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// With one comment per item - after the the `;`
2+
use crate::foo1 ;
3+
use crate::foo1 ; /* 2nd foo1 - comment after ; */
4+
use crate::foo2::bar ; /* 1st foo1::bar - comment after ; */
5+
use crate::foo2::bar ;
6+
7+
// With one comment per item - before the the `;`
8+
use crate::foo3 ;
9+
use crate::foo3 /* 2nd foo3 - comment before ; */ ;
10+
use crate::foo4::bar /* 1st foo4::bar - comment before ; */ ;
11+
use crate::foo4::bar ;
12+
13+
// With multiline comments or multi comments - after the `;`
14+
use crate::foo5; /* foo5 - Multiline comment before ; line 1
15+
* foo5 - Multiline comment before ; line 2 */
16+
use crate::foo5;
17+
use crate::foo6; // foo6- mixed comments before ; - 1st line comment ;
18+
/* foo6- mixed comments before ; - 2nd block comment */
19+
use crate::foo6;
20+
21+
// With multiline comments or multi comments - before the `;`
22+
use crate::foo8 // foo8- mixed comments before ; - 1st line comment ;
23+
/* foo8- mixed comments before ; - 2nd block comment */ ;
24+
use crate::foo8;
25+
26+
// With two comments per item
27+
use crate::foo11 ; /* 1st foo11 - comment */
28+
use crate::foo11 ; /* 2nd foo11 - comment */
29+
30+
// With one comment for a module
31+
use crate::foo21::{self} ; /* external comment for foo21 {self} */
32+
use crate::foo21::{foo} ; /* external comment for foo21 {foo} */
33+
use crate::foo21::{bar} ;
34+
35+
// With internal and external comment for a module
36+
use crate::foo22::{self} ; /* external comment for foo22 {self} */
37+
use crate::foo22::{foo /* internal comment for foo22 {foo} */} ;
38+
use crate::foo22::{bar /* internal comment for foo22 {bar} */} ;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// rustfmt-imports_granularity: Item
2+
3+
// With one comment per item - after the the `;`
4+
use crate::foo2::bar ; /* 1st foo1::bar - comment after ; */
5+
use crate::foo2::bar ;
6+
7+
// With one comment per item - before the the `;`
8+
use crate::foo4::bar /* 1st foo4::bar - comment before ; */ ;
9+
use crate::foo4::bar ;
10+
11+
// With multiline comments or multi comments - after the `;`
12+
use crate::foo5; /* foo5 - Multiline comment before ; line 1
13+
* foo5 - Multiline comment before ; line 2 */
14+
use crate::foo6; // foo6- mixed comments before ; - 1st line comment ;
15+
/* foo6- mixed comments before ; - 2nd block comment */
16+
17+
// With multiline comments or multi comments - before the `;`
18+
use crate::foo8 // foo8- mixed comments before ; - 1st line comment ;
19+
/* foo8- mixed comments before ; - 2nd block comment */ ;
20+
21+
// With one comment for a module
22+
use crate::foo21::{self} ; /* external comment for foo21 {self} */
23+
use crate::foo21::{foo} ; /* external comment for foo21 {foo} */
24+
use crate::foo21::{bar} ;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// rustfmt-imports_granularity: Module
2+
3+
// With one comment per item - after the the `;`
4+
use crate::foo1 ;
5+
use crate::foo1 ; /* 2nd foo1 - comment after ; */
6+
use crate::foo2::bar ; /* 1st foo1::bar - comment after ; */
7+
use crate::foo2::bar ;
8+
9+
// With one comment per item - before the the `;`
10+
use crate::foo3 ;
11+
use crate::foo3 /* 2nd foo3 - comment before ; */ ;
12+
use crate::foo4::bar /* 1st foo4::bar - comment before ; */ ;
13+
use crate::foo4::bar ;
14+
15+
// With multiline comments or multi comments - after the `;`
16+
use crate::foo5; /* foo5 - Multiline comment before ; line 1
17+
* foo5 - Multiline comment before ; line 2 */
18+
use crate::foo5;
19+
use crate::foo6; // foo6- mixed comments before ; - 1st line comment ;
20+
/* foo6- mixed comments before ; - 2nd block comment */
21+
use crate::foo6;
22+
23+
// With multiline comments or multi comments - before the `;`
24+
use crate::foo7 /* foo7 - Multiline comment before ; line 1
25+
* foo7 - Multiline comment before ; line 2 */ ;
26+
use crate::foo7;
27+
use crate::foo8 // foo8- mixed comments before ; - 1st line comment ;
28+
/* foo8- mixed comments before ; - 2nd block comment */ ;
29+
use crate::foo8;
30+
31+
// With one comment for a module
32+
use crate::foo21::{self} ; /* external comment for foo21 {self} */
33+
use crate::foo21::{foo} ;
34+
use crate::foo21::{bar} ;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// rustfmt-imports_granularity: Crate
2+
3+
// With one comment per item - after the the `;`
4+
use crate::foo2::bar; /* 1st foo1::bar - comment after ; */
5+
use foo1; /* 2nd foo1 - comment after ; */
6+
7+
// With one comment per item - before the the `;`
8+
use crate::foo4::bar; /* 1st foo4::bar - comment before ; */
9+
use foo3; /* 2nd foo3 - comment before ; */
10+
11+
// With multiline comments or multi comments - after the `;`
12+
use crate::foo5; /* foo5 - Multiline comment before ; line 1
13+
* foo5 - Multiline comment before ; line 2 */
14+
use crate::{foo5, foo6}; // foo6- mixed comments before ; - 1st line comment ;
15+
/* foo6- mixed comments before ; - 2nd block comment */
16+
use crate::foo6;
17+
18+
// With multiline comments or multi comments - before the `;`
19+
use crate::foo8; // foo8- mixed comments before ; - 1st line comment ;
20+
/* foo8- mixed comments before ; - 2nd block comment */
21+
use crate::{foo7, foo8}; /* foo7 - Multiline comment before ; line 1
22+
* foo7 - Multiline comment before ; line 2 */
23+
24+
// With one comment for a module
25+
use crate::foo21::{self, bar, foo}; /* external comment for foo21 {self} */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// With one comment per item - after the the `;`
2+
use crate::foo1;
3+
use crate::foo1; /* 2nd foo1 - comment after ; */
4+
use crate::foo2::bar; /* 1st foo1::bar - comment after ; */
5+
use crate::foo2::bar;
6+
7+
// With one comment per item - before the the `;`
8+
use crate::foo3;
9+
use crate::foo3; /* 2nd foo3 - comment before ; */
10+
use crate::foo4::bar; /* 1st foo4::bar - comment before ; */
11+
use crate::foo4::bar;
12+
13+
// With multiline comments or multi comments - after the `;`
14+
use crate::foo5; /* foo5 - Multiline comment before ; line 1
15+
* foo5 - Multiline comment before ; line 2 */
16+
use crate::foo5;
17+
use crate::foo6; // foo6- mixed comments before ; - 1st line comment ;
18+
/* foo6- mixed comments before ; - 2nd block comment */
19+
use crate::foo6;
20+
21+
// With multiline comments or multi comments - before the `;`
22+
use crate::foo8; // foo8- mixed comments before ; - 1st line comment ;
23+
/* foo8- mixed comments before ; - 2nd block comment */
24+
use crate::foo8;
25+
26+
// With two comments per item
27+
use crate::foo11; /* 1st foo11 - comment */
28+
use crate::foo11; /* 2nd foo11 - comment */
29+
30+
// With one comment for a module
31+
use crate::foo21::bar;
32+
use crate::foo21::foo; /* external comment for foo21 {foo} */
33+
use crate::foo21::{self}; /* external comment for foo21 {self} */
34+
35+
// With internal and external comment for a module
36+
use crate::foo22::{self}; /* external comment for foo22 {self} */
37+
use crate::foo22::{bar /* internal comment for foo22 {bar} */};
38+
use crate::foo22::{foo /* internal comment for foo22 {foo} */};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// rustfmt-imports_granularity: Item
2+
3+
// With one comment per item - after the the `;`
4+
use crate::foo2::bar; /* 1st foo1::bar - comment after ; */
5+
6+
// With one comment per item - before the the `;`
7+
use crate::foo4::bar; /* 1st foo4::bar - comment before ; */
8+
9+
// With multiline comments or multi comments - after the `;`
10+
use crate::foo5; /* foo5 - Multiline comment before ; line 1
11+
* foo5 - Multiline comment before ; line 2 */
12+
use crate::foo6; // foo6- mixed comments before ; - 1st line comment ;
13+
/* foo6- mixed comments before ; - 2nd block comment */
14+
15+
// With multiline comments or multi comments - before the `;`
16+
use crate::foo8;
17+
18+
// With one comment for a module
19+
use crate::foo21::bar;
20+
use crate::foo21::foo; /* external comment for foo21 {foo} */
21+
use crate::foo21::{self}; /* external comment for foo21 {self} */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// rustfmt-imports_granularity: Module
2+
3+
// With one comment per item - after the the `;`
4+
use crate::foo1;
5+
use crate::foo1; /* 2nd foo1 - comment after ; */
6+
use crate::foo2::bar; /* 1st foo1::bar - comment after ; */
7+
8+
// With one comment per item - before the the `;`
9+
use crate::foo3;
10+
use crate::foo3; /* 2nd foo3 - comment before ; */
11+
use crate::foo4::bar; /* 1st foo4::bar - comment before ; */
12+
13+
// With multiline comments or multi comments - after the `;`
14+
use crate::foo5; /* foo5 - Multiline comment before ; line 1
15+
* foo5 - Multiline comment before ; line 2 */
16+
use crate::{foo5, foo6}; // foo6- mixed comments before ; - 1st line comment ;
17+
/* foo6- mixed comments before ; - 2nd block comment */
18+
use crate::foo6;
19+
20+
// With multiline comments or multi comments - before the `;`
21+
use crate::foo8; // foo8- mixed comments before ; - 1st line comment ;
22+
/* foo8- mixed comments before ; - 2nd block comment */
23+
use crate::{foo7, foo8}; /* foo7 - Multiline comment before ; line 1
24+
* foo7 - Multiline comment before ; line 2 */
25+
26+
// With one comment for a module
27+
use crate::foo21::{self, bar, foo}; /* external comment for foo21 {self} */

0 commit comments

Comments
 (0)