Skip to content

Conversation

MeGaGiGaGon
Copy link
Contributor

Summary

Part of #15584

This PR adds fix safety sections to W291 and W293

The unsafe caveat was added in #10049

// Removing trailing whitespace is not safe inside multiline strings.

Code example demonstrating unsafety:

PS ~\Desktop\New_folder\ruff>Get-Content issue.py
# W291
"""
1
"""

# W293
"""

"""
PS ~\Desktop\New_folder\ruff>Get-Escaped-Content issue.py
# W291\n"""\n1 \n"""\n\n# W293\n"""\n \n"""\r\n
PS ~\Desktop\New_folder\ruff>uvx ruff check issue.py --isolated --select W
issue.py:3:2: W291 Trailing whitespace
  |
1 | # W291
2 | """
3 | 1
  |  ^ W291
4 | """
  |
  = help: Remove trailing whitespace

issue.py:8:1: W293 Blank line contains whitespace
  |
6 | # W293
7 | """
8 |
  | ^ W293
9 | """
  |
  = help: Remove whitespace from blank line

Found 2 errors.
No fixes available (2 hidden fixes can be enabled with the `--unsafe-fixes` option).

Test Plan

N/A, no tests affected.

@MeGaGiGaGon MeGaGiGaGon mentioned this pull request Jun 19, 2025
71 tasks
@MeGaGiGaGon MeGaGiGaGon changed the title [pycodestyle] Add fix safety section to trailing_whitespace.rs [pycodestyle] Add fix safety section to W291 and W293 Jun 19, 2025
Copy link
Collaborator

@dylwil3 dylwil3 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!

@dylwil3 dylwil3 added the documentation Improvements or additions to documentation label Jun 19, 2025
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dylwil3 dylwil3 merged commit 440635c into astral-sh:main Jun 19, 2025
35 checks passed
@MeGaGiGaGon MeGaGiGaGon deleted the fix-safety-section-trailing_whitespace branch June 19, 2025 22:15
dcreager added a commit that referenced this pull request Jun 20, 2025
* main: (21 commits)
  [`flake8-logging`] Avoid false positive for `exc_info=True` outside `logger.exception` (`LOG014`) (#18737)
  [`flake8-pie`] Small docs fix to `PIE794` (#18829)
  [`pylint`] Ignore __init__.py files in (PLC0414) (#18400)
  Avoid generating diagnostics with per-file ignores (#18801)
  [`flake8-simplify`] Fix false negatives for shadowed bindings  (`SIM910`, `SIM911`) (#18794)
  [ty] Fix panics when pulling types for `ClassVar` or `Final` parameterized with >1 argument (#18824)
  [`pylint`] add fix safety section (`PLR1714`) (#18415)
  [Perflint] Small docs improvement to `PERF401` (#18786)
  [`pylint`] Avoid flattening nested `min`/`max` when outer call has single argument (`PLW3301`) (#16885)
  [`ruff`] Added `cls.__dict__.get('__annotations__')` check (`RUF063`) (#18233)
  [ty] Use `HashTable` in `PlaceTable` (#18819)
  docs: Correct collections-named-tuple example to use PascalCase assignment (#16884)
  [ty] ecosystem-analyzer workflow (#18719)
  [ty] Add support for `@staticmethod`s (#18809)
  unnecessary_dict_kwargs doc - a note on type checking benefits (#18666)
  [`flake8-pytest-style`] Mark autofix for `PT001` and `PT023` as unsafe if there's comments in the decorator (#18792)
  [ty] Surface matched overload diagnostic directly (#18452)
  [ty] Report when a dataclass contains more than one `KW_ONLY` field (#18731)
  [`flake8-pie`] Add fix safety section to `PIE794` (#18802)
  [`pycodestyle`] Add fix safety section to `W291` and `W293`  (#18800)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants