ruff/crates/ruff_linter/src
Igor Drokin 673167a565
[`flake8-bugbear`] Include certain guaranteed-mutable expressions: tuples, generators, and assignment expressions (`B006`) (#20024)
## Summary
Resolves #20004

The implementation now supports guaranteed-mutable expressions in the
following cases:
- Tuple literals with mutable elements (supporting deep nesting)
- Generator expressions
- Named expressions (walrus operator) containing mutable components

Preserves original formatting for assignment value:

```python
# Test case
def f5(x=([1, ])):
    print(x)
```
```python
# Fix before
def f5(x=(None)):
    if x is None:
        x = [1]
    print(x)
```
```python
# Fix after 
def f5(x=None):
    if x is None:
        x = ([1, ])
    print(x)
```
The expansion of detected expressions and the new fixes gated behind
previews.

## Test Plan
- Added B006_9.py with a bunch of test cases
- Generated snapshots

---------

Co-authored-by: Igor Drokin <drokinii1017@gmail.com>
Co-authored-by: dylwil3 <dylwil3@gmail.com>
2025-10-03 09:29:36 -05:00
..
checkers [`ruff`] Extend FA102 with listed PEP 585-compatible APIs (#20659) 2025-10-03 09:45:32 -04:00
comments Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
cst Update Rust toolchain to 1.89 (#19807) 2025-08-07 18:21:50 +02:00
docstrings Update Rust toolchain to 1.89 (#19807) 2025-08-07 18:21:50 +02:00
fix Update Rust crate anyhow to v1.0.100 (#20499) 2025-09-22 09:51:52 +02:00
importer [ruff] Remove `Locator` from `Importer` 2025-09-17 13:59:28 -04:00
linter [`pylint`] Detect more exotic NaN literals in `PLW0177` (#18630) 2025-06-19 11:05:06 +00:00
message Display diffs for `ruff format --check` and add support for different output formats (#20443) 2025-09-30 12:00:51 -04:00
registry Remove `Message::to_rule` (#18447) 2025-06-05 12:48:29 -04:00
rules [`flake8-bugbear`] Include certain guaranteed-mutable expressions: tuples, generators, and assignment expressions (`B006`) (#20024) 2025-10-03 09:29:36 -05:00
settings Display diffs for `ruff format --check` and add support for different output formats (#20443) 2025-09-30 12:00:51 -04:00
snapshots [syntax-errors] Detect `yield from` inside async function (#20051) 2025-09-03 10:13:05 -04:00
codes.rs [`flake8-async`] Implement `blocking-path-method` (`ASYNC240`) (#20264) 2025-09-23 08:30:47 -04:00
directives.rs Track t-strings and f-strings for token-based rules and suppression comments (#20357) 2025-09-12 13:00:12 -05:00
doc_lines.rs Update Rust toolchain to 1.89 (#19807) 2025-08-07 18:21:50 +02:00
fs.rs Move GitLab output rendering to `ruff_db` (#20117) 2025-08-28 08:56:33 -04:00
lib.rs Combine `OldDiagnostic` and `Diagnostic` (#19053) 2025-07-03 13:01:09 -04:00
line_width.rs Switch to Rust 2024 edition (#18129) 2025-05-16 13:25:28 +02:00
linter.rs [ruff] Treat panics as fatal diagnostics, sort panics last (#20258) 2025-09-16 11:33:37 -07:00
locator.rs Update Rust toolchain to 1.89 (#19807) 2025-08-07 18:21:50 +02:00
logging.rs Display diffs for `ruff format --check` and add support for different output formats (#20443) 2025-09-30 12:00:51 -04:00
noqa.rs Remove Diagnostic::expect_range and all consumers (#20322) 2025-09-10 17:19:20 -07:00
package.rs Detect empty implicit namespace packages (#14236) 2024-11-09 22:03:34 -05:00
packaging.rs Nested namespace packages support (#10541) 2024-03-24 22:53:32 -04:00
preview.rs [`flake8-bugbear`] Include certain guaranteed-mutable expressions: tuples, generators, and assignment expressions (`B006`) (#20024) 2025-10-03 09:29:36 -05:00
pyproject_toml.rs Rename `Diagnostic::syntax_error` methods, separate `Ord` implementation (#19179) 2025-07-08 09:54:19 -04:00
registry.rs Apply fix availability and applicability when adding to `DiagnosticGuard` and remove `NoqaCode::rule` (#18834) 2025-06-24 10:08:36 -04:00
renamer.rs Add a `ScopeKind` for the `__class__` cell (#20048) 2025-08-26 09:49:08 -04:00
rule_redirects.rs [`flake8-bandit`] Move `unsafe-markup-use` from `RUF035` to `S704` (#15957) 2025-03-13 15:37:37 +01:00
rule_selector.rs Ignore deprecated rules unless selected by exact code (#20167) 2025-09-10 09:00:27 -04:00
source_kind.rs Update MSRV to 1.85 and toolchain to 1.87 (#18126) 2025-05-16 09:19:55 +02:00
test.rs Remove `TextEmitter` (#20595) 2025-09-29 08:46:25 -04:00
text_helpers.rs Handle non-printable characters in diff view (#11687) 2024-06-08 06:22:03 +00:00
upstream_categories.rs Fix pylint upstream categories not showing in docs (#10441) 2024-03-18 01:27:39 +00:00
violation.rs Rename `Diagnostic::syntax_error` methods, separate `Ord` implementation (#19179) 2025-07-08 09:54:19 -04:00