Skip to content

Commit fba6627

Browse files
committed
Sort formatter diagnostics in snapshots
1 parent a530449 commit fba6627

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

crates/ruff_python_formatter/tests/fixtures.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,16 @@ fn ensure_unchanged_ast(
477477
formatted_unsupported_syntax_errors
478478
.retain(|fingerprint, _| !unformatted_unsupported_syntax_errors.contains_key(fingerprint));
479479

480+
// Sort the errors by location to ensure the snapshot output is stable.
481+
let mut formatted_unsupported_syntax_errors = formatted_unsupported_syntax_errors
482+
.into_values()
483+
.collect::<Vec<_>>();
484+
formatted_unsupported_syntax_errors
485+
.sort_by_key(|error| (error.range().start(), error.range().end()));
486+
480487
let file = SourceFileBuilder::new(input_path.file_name().unwrap(), formatted_code).finish();
481488
let diagnostics = formatted_unsupported_syntax_errors
482-
.values()
489+
.iter()
483490
.map(|error| {
484491
let mut diag = Diagnostic::new(DiagnosticId::InvalidSyntax, Severity::Error, error);
485492
let span = Span::from(file.clone()).with_range(error.range());

crates/ruff_python_formatter/tests/snapshots/format@expression__nested_string_quote_style.py.snap

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -392,26 +392,26 @@ t"{('implicit concatenation', ["'single'", '"double"'])}"
392392

393393
### Unsupported Syntax Errors
394394
error[invalid-syntax]: Cannot reuse outer quote character in f-strings on Python 3.11 (syntax was added in Python 3.12)
395-
--> nested_string_quote_style.py:30:24
395+
--> nested_string_quote_style.py:28:24
396396
|
397+
26 | f"'single' quotes and {'nested string'}"
398+
27 | t"'single' quotes and {'nested string'}"
397399
28 | f'"double" quotes and {'nested string with "double" quotes'}' # syntax error pre-3.12
400+
| ^
398401
29 | t'"double" quotes and {'nested string with "double" quotes'}'
399402
30 | f"'single' quotes and {"nested string with 'single' quotes"}'" # syntax error pre-3.12
400-
| ^
401-
31 | t"'single' quotes and {"nested string with 'single' quotes"}'"
402-
32 | f'"double" quotes and {"nested string with 'single' quotes"}' # syntax error pre-3.12
403403
|
404404
warning: Only accept new syntax errors if they are also present in the input. The formatter should not introduce syntax errors.
405405

406406
error[invalid-syntax]: Cannot reuse outer quote character in f-strings on Python 3.11 (syntax was added in Python 3.12)
407-
--> nested_string_quote_style.py:28:24
407+
--> nested_string_quote_style.py:30:24
408408
|
409-
26 | f"'single' quotes and {'nested string'}"
410-
27 | t"'single' quotes and {'nested string'}"
411409
28 | f'"double" quotes and {'nested string with "double" quotes'}' # syntax error pre-3.12
412-
| ^
413410
29 | t'"double" quotes and {'nested string with "double" quotes'}'
414411
30 | f"'single' quotes and {"nested string with 'single' quotes"}'" # syntax error pre-3.12
412+
| ^
413+
31 | t"'single' quotes and {"nested string with 'single' quotes"}'"
414+
32 | f'"double" quotes and {"nested string with 'single' quotes"}' # syntax error pre-3.12
415415
|
416416
warning: Only accept new syntax errors if they are also present in the input. The formatter should not introduce syntax errors.
417417

@@ -519,25 +519,25 @@ t"{('implicit concatenation', ["'single'", '"double"'])}"
519519

520520
### Unsupported Syntax Errors
521521
error[invalid-syntax]: Cannot reuse outer quote character in f-strings on Python 3.11 (syntax was added in Python 3.12)
522-
--> nested_string_quote_style.py:30:24
522+
--> nested_string_quote_style.py:28:24
523523
|
524+
26 | f"'single' quotes and {'nested string'}"
525+
27 | t"'single' quotes and {'nested string'}"
524526
28 | f'"double" quotes and {'nested string with "double" quotes'}' # syntax error pre-3.12
527+
| ^
525528
29 | t'"double" quotes and {'nested string with "double" quotes'}'
526529
30 | f"'single' quotes and {"nested string with 'single' quotes"}'" # syntax error pre-3.12
527-
| ^
528-
31 | t"'single' quotes and {"nested string with 'single' quotes"}'"
529-
32 | f'"double" quotes and {"nested string with 'single' quotes"}' # syntax error pre-3.12
530530
|
531531
warning: Only accept new syntax errors if they are also present in the input. The formatter should not introduce syntax errors.
532532

533533
error[invalid-syntax]: Cannot reuse outer quote character in f-strings on Python 3.11 (syntax was added in Python 3.12)
534-
--> nested_string_quote_style.py:28:24
534+
--> nested_string_quote_style.py:30:24
535535
|
536-
26 | f"'single' quotes and {'nested string'}"
537-
27 | t"'single' quotes and {'nested string'}"
538536
28 | f'"double" quotes and {'nested string with "double" quotes'}' # syntax error pre-3.12
539-
| ^
540537
29 | t'"double" quotes and {'nested string with "double" quotes'}'
541538
30 | f"'single' quotes and {"nested string with 'single' quotes"}'" # syntax error pre-3.12
539+
| ^
540+
31 | t"'single' quotes and {"nested string with 'single' quotes"}'"
541+
32 | f'"double" quotes and {"nested string with 'single' quotes"}' # syntax error pre-3.12
542542
|
543543
warning: Only accept new syntax errors if they are also present in the input. The formatter should not introduce syntax errors.

0 commit comments

Comments
 (0)