ruff/crates/ruff_python_formatter/src/statement
Dhruv Manilawala f3dac27e9a
Fix f-string formatting in assignment statement (#14454)
## Summary

fixes: #13813

This PR fixes a bug in the formatting assignment statement when the
value is an f-string.

This is resolved by using custom best fit layouts if the f-string is (a)
not already a flat f-string (thus, cannot be multiline) and (b) is not a
multiline string (thus, cannot be flattened). So, it is used in cases
like the following:
```py
aaaaaaaaaaaaaaaaaa = f"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
    expression}moreeeeeeeeeeeeeeeee"
```
Which is (a) `FStringLayout::Multiline` and (b) not a multiline.

There are various other examples in the PR diff along with additional
explanation and context as code comments.

## Test Plan

Add multiple test cases for various scenarios.
2024-11-26 15:07:18 +05:30
..
clause.rs Upgrade to Rust 1.80 (#12586) 2024-07-30 19:18:08 +00:00
mod.rs Preserve trailing statement semicolons when using `fmt: skip` (#8273) 2023-10-30 00:07:14 +00:00
stmt_ann_assign.rs Ruff 2024.2 style (#9639) 2024-02-29 09:30:54 +01:00
stmt_assert.rs Join implicit concatenated strings when they fit on a line (#13663) 2024-10-24 11:52:22 +02:00
stmt_assign.rs Fix f-string formatting in assignment statement (#14454) 2024-11-26 15:07:18 +05:30
stmt_aug_assign.rs Ruff 2024.2 style (#9639) 2024-02-29 09:30:54 +01:00
stmt_break.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_class_def.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_continue.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_delete.rs Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
stmt_expr.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_for.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_function_def.rs Fix parentheses around return type annotations (#13381) 2024-09-20 09:23:53 +02:00
stmt_global.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_if.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_import.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_import_from.rs Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
stmt_ipy_escape_command.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_match.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_nonlocal.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_pass.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_raise.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_return.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_try.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_type_alias.rs Ruff 2024.2 style (#9639) 2024-02-29 09:30:54 +01:00
stmt_while.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_with.rs Fix formatting of single with-item with trailing comment (#14005) 2024-11-01 09:08:06 +01:00
suite.rs Join implicit concatenated strings when they fit on a line (#13663) 2024-10-24 11:52:22 +02:00