ruff/crates/ruff_python_formatter/src
Dhruv Manilawala 3e00ddce38
Preserve trailing semicolon for Notebooks (#8590)
## Summary

This PR updates the formatter to preserve trailing semicolon for Jupyter
Notebooks.

The motivation behind the change is that semicolons in notebooks are
typically used to hide the output, for example when plotting. This is
highlighted in the linked issue.

The conditions required as to when the trailing semicolon should be
preserved are:
1. It should be a top-level statement which is last in the module.
2. For statement, it can be either assignment, annotated assignment, or
augmented assignment. Here, the target should only be a single
identifier i.e., multiple assignments or tuple unpacking isn't
considered.
3. For expression, it can be any.

## Test Plan

Add a new integration test in `ruff_cli`. The test notebook basically
acts as a document as to which trailing semicolons are to be preserved.

fixes: #8254
2023-11-10 21:53:35 +05:30
..
comments Preserve trailing semicolon for Notebooks (#8590) 2023-11-10 21:53:35 +05:30
expression Preserve trailing semicolon for Notebooks (#8590) 2023-11-10 21:53:35 +05:30
module Attach dangling comments to the comprehension instead of the if or iter nodes (#7693) 2023-09-29 10:45:01 +01:00
other Fix multiline lambda expression statement formating (#8466) 2023-11-05 09:35:23 -05:00
pattern New Singleton enum for PatternMatchSingleton node (#8063) 2023-10-30 05:48:53 +00:00
snapshots Remove exception-handler lexing from unused-bound-exception fix (#5851) 2023-07-18 18:27:46 +00:00
statement Preserve trailing semicolon for Notebooks (#8590) 2023-11-10 21:53:35 +05:30
type_param Don't move type param opening parenthesis comment (#8163) 2023-10-24 12:02:27 +00:00
builders.rs Add [format|lint].exclude options (#8000) 2023-10-18 01:15:25 +00:00
cli.rs Add test and basic implementation for formatter preview mode (#8044) 2023-10-26 15:33:26 +00:00
context.rs Preserve trailing semicolon for Notebooks (#8590) 2023-11-10 21:53:35 +05:30
generated.rs Split Constant to individual literal nodes (#8064) 2023-10-30 12:13:23 +05:30
lib.rs Use source type to determine parser mode for formatting (#8205) 2023-10-25 19:20:02 +05:30
main.rs Formatter and parser refactoring (#7569) 2023-09-26 15:29:43 +02:00
options.rs Refine warning about incompatible isort settings (#8192) 2023-10-25 08:41:17 +01:00
prelude.rs Accept any Into<AnyNodeRef> as Comments arguments (#5205) 2023-06-20 16:49:21 +00:00
verbatim.rs Preserve trailing semicolons when using fmt: off (#8275) 2023-10-30 00:22:34 +00:00