Skip to content

[eradicate] Fix false positive for lines with leading whitespace (ERA001) - #25122

Merged
ntBre merged 3 commits into
mainfrom
brent/era-whitespace
May 13, 2026
Merged

ntBre merged 3 commits into
mainfrom
brent/era-whitespace

Conversation

@ntBre

@ntBre ntBre commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes #25116 by reusing our is_python_whitespace helper for
trimming lines that may contain code. This avoids false positives in
cases where comments are preceded by tabs (or form-feeds). These would
previously fail to trim the whitespace and end up parsing a module
like:

\t# comment here

which is valid Python.

Test plan

New tests based on the report

ntBre added 3 commits May 12, 2026 14:51
…ERA001`)

Summary
--

This PR fixes #25116 by reusing our `is_python_whitespace` helper for
trimming lines that may contain code. This avoids false positives in
cases where comments are preceded by tabs (or form-feeds). These would
previously fail to trim the whitespace and end up parsing a module
like:

```py
\t# comment here
```

which is valid Python.

Test plan
--

New tests based on the report
@astral-sh-bot

astral-sh-bot Bot commented May 12, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+7 -0 violations, +0 -0 fixes in 2 projects; 54 projects unchanged)

langchain-ai/langchain (+3 -0 violations, +0 -0 fixes)

+ libs/langchain/langchain_classic/chains/natbot/crawler.py:173:9: ERA001 Found commented-out code
+ libs/langchain/langchain_classic/chains/natbot/crawler.py:174:9: ERA001 Found commented-out code
+ libs/langchain/langchain_classic/chains/natbot/crawler.py:175:9: ERA001 Found commented-out code

milvus-io/pymilvus (+4 -0 violations, +0 -0 fixes)

+ examples/bulk_import/example_bulkinsert_json.py:94:1: ERA001 Found commented-out code
+ examples/bulk_import/example_bulkinsert_json.py:95:1: ERA001 Found commented-out code
+ examples/orm_deprecated/bulk_import/example_bulkinsert_json.py:126:1: ERA001 Found commented-out code
+ examples/orm_deprecated/bulk_import/example_bulkinsert_json.py:127:1: ERA001 Found commented-out code

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
ERA001 7 7 0 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+7 -0 violations, +0 -0 fixes in 2 projects; 54 projects unchanged)

langchain-ai/langchain (+3 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

+ libs/langchain/langchain_classic/chains/natbot/crawler.py:173:9: ERA001 Found commented-out code
+ libs/langchain/langchain_classic/chains/natbot/crawler.py:174:9: ERA001 Found commented-out code
+ libs/langchain/langchain_classic/chains/natbot/crawler.py:175:9: ERA001 Found commented-out code

milvus-io/pymilvus (+4 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

+ examples/bulk_import/example_bulkinsert_json.py:94:1: ERA001 Found commented-out code
+ examples/bulk_import/example_bulkinsert_json.py:95:1: ERA001 Found commented-out code
+ examples/orm_deprecated/bulk_import/example_bulkinsert_json.py:126:1: ERA001 Found commented-out code
+ examples/orm_deprecated/bulk_import/example_bulkinsert_json.py:127:1: ERA001 Found commented-out code

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
ERA001 7 7 0 0 0

@ntBre

ntBre commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

Hmm, I didn't think about this also trimming tabs after the #, which is what all of the ecosystem results correspond to, for example:

# {"rows": [
# 	  {"str_field": "row-based_0", "float_vector_field": [0.190, 0.046, 0.143, 0.972, 0.592, 0.238, 0.266, 0.995]},
# 	  {"str_field": "row-based_1", "float_vector_field": [0.149, 0.586, 0.012, 0.673, 0.588, 0.917, 0.949, 0.944]},
#     ......
#   ]
# }

but I think that still makes sense and matches the space handling.

@ntBre
ntBre marked this pull request as ready for review May 12, 2026 19:53
@ntBre ntBre added bug Something isn't working rule Implementing or modifying a lint rule labels May 12, 2026
@ntBre
ntBre requested a review from MichaReiser May 12, 2026 19:53
@ntBre
ntBre merged commit 3660a46 into main May 13, 2026
44 checks passed
@ntBre
ntBre deleted the brent/era-whitespace branch May 13, 2026 12:58
thejchap pushed a commit to thejchap/ruff that referenced this pull request May 23, 2026
…ERA001`) (astral-sh#25122)

Summary
--

This PR fixes astral-sh#25116 by reusing our `is_python_whitespace` helper for
trimming lines that may contain code. This avoids false positives in
cases where comments are preceded by tabs (or form-feeds). These would
previously fail to trim the whitespace and end up parsing a module
like:

```py
\t# comment here
```

which is valid Python.

Test plan
--

New tests based on the report
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERA001: False positive for tab indented code

2 participants