File tree 2 files changed +12
-11
lines changed
crates/ruff_python_formatter
2 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -474,18 +474,19 @@ fn normalize_comment<'a>(
474
474
if content. starts_with ( '\u{A0}' ) {
475
475
let trimmed = content. trim_start_matches ( '\u{A0}' ) ;
476
476
477
- // Black adds a space before the non-breaking space if part of a type pragma.
478
477
if trimmed. trim_start ( ) . starts_with ( "type:" ) {
479
- return Ok ( Cow :: Owned ( std:: format!( "# \u{A0} {trimmed}" ) ) ) ;
480
- }
481
-
482
- // Black replaces the non-breaking space with a space if followed by a space.
483
- if trimmed. starts_with ( ' ' ) {
484
- return Ok ( Cow :: Owned ( std:: format!( "# {trimmed}" ) ) ) ;
478
+ // Black adds a space before the non-breaking space if part of a type pragma.
479
+ Ok ( Cow :: Owned ( std:: format!( "# {content}" ) ) )
480
+ } else if trimmed. starts_with ( ' ' ) {
481
+ // Black replaces the non-breaking space with a space if followed by a space.
482
+ Ok ( Cow :: Owned ( std:: format!( "# {trimmed}" ) ) )
483
+ } else {
484
+ // Otherwise we replace the first non-breaking space with a regular space.
485
+ Ok ( Cow :: Owned ( std:: format!( "# {}" , & content[ "\u{A0} " . len( ) ..] ) ) )
485
486
}
487
+ } else {
488
+ Ok ( Cow :: Owned ( std:: format!( "# {}" , content. trim_start( ) ) ) )
486
489
}
487
-
488
- Ok ( Cow :: Owned ( std:: format!( "# {}" , content. trim_start( ) ) ) )
489
490
}
490
491
491
492
/// A helper for stripping '#' from comments.
Original file line number Diff line number Diff line change @@ -65,11 +65,11 @@ i = "" # type: Add space before leading NBSP followed by spaces
65
65
i = "" # type: A space is added
66
66
i = "" # type: Add space before leading NBSP followed by a space
67
67
i = "" # type: Add space before leading NBSP
68
- i = "" # type: Add space before two leading NBSP
68
+ i = "" # type: Add space before two leading NBSP
69
69
70
70
71
71
# A noqa as ` #\u {A0 }\u {A0 }noqa ` becomes ` # \u {A0 }noqa `
72
- i = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # noqa
72
+ i = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # noqa
73
73
` ` `
74
74
75
75
You can’t perform that action at this time.
0 commit comments