Skip to content

Conversation

@danparizher
Copy link
Contributor

@danparizher danparizher commented Jul 30, 2025

Summary

Fixes #19581

I decided to add in a indent_first_line function into textwrap.rs, as it solely focuses on text manipulation utilities. It follows the same design as indent(), and there may be situations in the future where it can be reused as well.

@ntBre ntBre added bug Something isn't working fixes Related to suggested fixes for violations labels Jul 30, 2025
@ntBre ntBre self-requested a review July 30, 2025 19:58
@github-actions
Copy link
Contributor

github-actions bot commented Jul 30, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this looks good to me! I just had a couple of nits. It might also be nice to throw in the triple-quoted string case as a RUF033 test too, just to double check.

@ntBre
Copy link
Contributor

ntBre commented Aug 12, 2025

Ah the test failures are just a merge conflict with our new diagnostic format. Would you mind rebasing/merging main and then accepting the new snapshots? The new results look correct to me in the CI output.

@ntBre
Copy link
Contributor

ntBre commented Aug 27, 2025

Looks great, thanks! Sorry I forgot to come back to this after the rebase. I just pushed one additional test case like the reported issue and confirmed that everything looks good.

@ntBre ntBre changed the title [RUF] Fix indentation to preserve relative whitespace in multi-line expressions (RUF033) [ruff] Preserve relative whitespace in multi-line expressions (RUF033) Aug 27, 2025
@ntBre ntBre enabled auto-merge (squash) August 27, 2025 19:13
@ntBre ntBre merged commit 89ca493 into astral-sh:main Aug 27, 2025
34 checks passed
@danparizher danparizher deleted the fix-19581 branch August 27, 2025 19:32
carljm added a commit to leandrobbraga/ruff that referenced this pull request Aug 27, 2025
* main:
  [`ruff`] Preserve relative whitespace in multi-line expressions (`RUF033`) (astral-sh#19647)
  [ty] Optimize TDD atom ordering (astral-sh#20098)
  [`airflow`] Extend `AIR311` and `AIR312` rules (astral-sh#20082)
  [ty] Preserve qualifiers when accessing attributes on unions/intersections (astral-sh#20114)
  [ty] Fix the inferred interface of specialized generic protocols (astral-sh#19866)
  [ty] Infer slightly more precise types for comprehensions (astral-sh#20111)
  [ty] Add more tests for protocols (astral-sh#20095)
  [ty] don't eagerly unpack aliases in user-authored unions (astral-sh#20055)
  [`flake8-use-pathlib`] Update links to the table showing the correspondence between `os` and `pathlib` (astral-sh#20103)
  [`flake8-use-pathlib`] Make `PTH100` fix unsafe because it can change behavior (astral-sh#20100)
  [`flake8-use-pathlib`] Delete unused `Rule::OsSymlink` enabled check (astral-sh#20099)
  [ty] Add search paths info to unresolved import diagnostics (astral-sh#20040)
  [`flake8-logging-format`] Add auto-fix for f-string logging calls (`G004`) (astral-sh#19303)
  Add a `ScopeKind` for the `__class__` cell (astral-sh#20048)
  Fix incorrect D413 links in docstrings convention FAQ (astral-sh#20089)
  [ty] Refactor inlay hints structure to use separate parts (astral-sh#20052)
dcreager added a commit that referenced this pull request Aug 28, 2025
* main:
  Fix mdtest ignore python code blocks (#20139)
  [ty] add support for cyclic legacy generic protocols (#20125)
  [ty] add cycle detection for find_legacy_typevars (#20124)
  Use new diff rendering format in tests (#20101)
  [ty] Fix 'too many cycle iterations' for unions of literals (#20137)
  [ty] No boundness analysis for implicit instance attributes (#20128)
  Bump 0.12.11 (#20136)
  [ty] Benchmarks for problematic implicit instance attributes cases (#20133)
  [`pyflakes`] Fix `allowed-unused-imports` matching for top-level modules (`F401`) (#20115)
  Move GitLab output rendering to `ruff_db` (#20117)
  [ty] Evaluate reachability of non-definitely-bound to Ambiguous (#19579)
  [ty] Introduce a representation for the top/bottom materialization of an invariant generic (#20076)
  [`flake8-async`] Implement `blocking-http-call-httpx` (`ASYNC212`) (#20091)
  [ty] print diagnostics with fully qualified name to disambiguate some cases (#19850)
  [`ruff`] Preserve relative whitespace in multi-line expressions (`RUF033`) (#19647)
second-ed pushed a commit to second-ed/ruff that referenced this pull request Sep 9, 2025
…033`) (astral-sh#19647)

## Summary

Fixes astral-sh#19581

I decided to add in a `indent_first_line` function into
[`textwrap.rs`](https://github.com/astral-sh/ruff/blob/main/crates/ruff_python_trivia/src/textwrap.rs),
as it solely focuses on text manipulation utilities. It follows the same
design as `indent()`, and there may be situations in the future where it
can be reused as well.

---------

Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RUF033 fix changes the default expression’s indentation

2 participants