Visitar URL original
Fix `--add-noqa` whitespace on blank lines by Bortlesboat · Pull Request #23839 · astral-sh/ruff · GitHub
Skip to content

Fix --add-noqa whitespace on blank lines - #23839

Closed
Bortlesboat wants to merge 1 commit into
astral-sh:mainfrom
Bortlesboat:fix/add-noqa-blank-line-whitespace
Closed

Bortlesboat wants to merge 1 commit into
astral-sh:mainfrom
Bortlesboat:fix/add-noqa-blank-line-whitespace

Conversation

@Bortlesboat

Copy link
Copy Markdown
Contributor

Summary

Fixes #23751

When --add-noqa adds a noqa directive to a blank line (e.g., for D100 diagnostics that target TextRange::ZERO), it previously inserted leading whitespace ( # noqa: D100). This change skips the two leading spaces when the line has no content, producing # noqa: D100 instead.

Test plan

  • Added unit test blank_line_no_leading_whitespace that verifies a diagnostic on a blank line produces # noqa: F841\n without leading spaces.
  • All existing noqa tests continue to pass (89 tests).

When `--add-noqa` adds a directive to a blank line (e.g., for D100
diagnostics at TextRange::ZERO), it previously inserted leading
whitespace ("  # noqa: ..."). Now it omits the leading spaces for
blank lines, producing "# noqa: ..." instead.

Fixes #23751
@astral-sh-bot
astral-sh-bot Bot requested a review from amyreese March 9, 2026 17:19
@MichaReiser

Copy link
Copy Markdown
Member

Thank you. Unfortunately, there's already a PR for this, see #23773

@MichaReiser MichaReiser closed this Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--add-noqa for diagnostics on blank lines results in bad whitespace

3 participants