Skip to content

[pycodestyle] Implement blank-line-at-end-of-file (W391) - #10243

Merged
charliermarsh merged 14 commits into
astral-sh:mainfrom
augustelalande:too_many_newlines
Mar 12, 2024
Merged

[pycodestyle] Implement blank-line-at-end-of-file (W391)#10243
charliermarsh merged 14 commits into
astral-sh:mainfrom
augustelalande:too_many_newlines

Conversation

@augustelalande

Copy link
Copy Markdown
Contributor

Summary

Implements the blank line at end of file rule (W391) from pycodestyle. Renamed to TooManyNewlinesAtEndOfFile for clarity.

Test Plan

New fixtures have been added

Part of #2402

@augustelalande augustelalande changed the title Too many newlines [pycodestyle] Implement " Mar 6, 2024
@augustelalande augustelalande changed the title [pycodestyle] Implement " [pycodestyle] Implement "blank line at end of file" (W391) Mar 6, 2024
@augustelalande augustelalande changed the title [pycodestyle] Implement "blank line at end of file" (W391) [pycodestyle] Implement blank-line-at-end-of-file (W391) Mar 6, 2024
@augustelalande augustelalande changed the title [pycodestyle] Implement blank-line-at-end-of-file (W391) [pycodestyle] Implement blank-line-at-end-of-file (W391) Mar 6, 2024
@codspeed-hq

codspeed-hq Bot commented Mar 6, 2024

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #10243 will not alter performance

Comparing augustelalande:too_many_newlines (2d4e2fe) with main (c746912)

Summary

✅ 30 untouched benchmarks

@github-actions

github-actions Bot commented Mar 6, 2024

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+27 -0 violations, +0 -0 fixes in 5 projects; 38 projects unchanged)

commaai/openpilot (+10 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ common/transformations/camera.py:163:1: W391 [*] Extra newline at end of file
+ selfdrive/car/card.py:142:1: W391 [*] Extra newline at end of file
+ selfdrive/car/subaru/carstate.py:229:1: W391 [*] Extra newline at end of file
+ selfdrive/debug/internal/fuzz_fw_fingerprint.py:51:1: W391 [*] Too many newlines at end of file
+ selfdrive/debug/test_fw_query_on_routes.py:187:1: W391 [*] Extra newline at end of file
+ selfdrive/thermald/fan_controller.py:38:1: W391 [*] Extra newline at end of file
+ system/loggerd/tests/test_loggerd.py:285:1: W391 [*] Extra newline at end of file
+ tools/zookeeper/disable.py:8:1: W391 [*] Extra newline at end of file
+ tools/zookeeper/enable_and_wait.py:31:1: W391 [*] Extra newline at end of file
+ tools/zookeeper/ignition.py:10:1: W391 [*] Extra newline at end of file

docker/docker-py (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ docker/utils/__init__.py:13:1: W391 [*] Extra newline at end of file

fronzbot/blinkpy (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ blinksync/forms.py:122:1: W391 [*] Extra newline at end of file

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

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ examples/example_bulkwriter.py:418:1: W391 [*] Extra newline at end of file
+ examples/milvus_client/rbac.py:104:1: W391 [*] Extra newline at end of file
+ examples/user.py:93:1: W391 [*] Extra newline at end of file

mlflow/mlflow (+12 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ docs/source/llms/llm-evaluate/notebooks/question-answering-evaluation.ipynb:cell 28:1:1: W391 [*] Extra newline at end of file
+ docs/source/llms/llm-evaluate/notebooks/rag-evaluation-llama2.ipynb:cell 22:1:1: W391 [*] Extra newline at end of file
+ docs/source/llms/llm-evaluate/notebooks/rag-evaluation.ipynb:cell 19:1:1: W391 [*] Extra newline at end of file
+ docs/source/llms/rag/notebooks/retriever-evaluation-tutorial.ipynb:cell 48:1:1: W391 [*] Extra newline at end of file
+ docs/source/traditional-ml/hyperparameter-tuning-with-child-runs/notebooks/parent-child-runs.ipynb:cell 15:1:1: W391 [*] Extra newline at end of file
+ docs/source/traditional-ml/serving-multiple-models-with-pyfunc/notebooks/MME_Tutorial.ipynb:cell 25:1:1: W391 [*] Extra newline at end of file
+ examples/evaluation/qa-evaluation.ipynb:cell 29:1:1: W391 [*] Extra newline at end of file
+ examples/evaluation/rag-evaluation.ipynb:cell 16:1:1: W391 [*] Extra newline at end of file
+ examples/h2o/random_forest.ipynb:cell 6:1:1: W391 [*] Extra newline at end of file
+ examples/llms/RAG/retriever-evaluation-tutorial.ipynb:cell 48:1:1: W391 [*] Extra newline at end of file
+ examples/rapids/mlflow_project/notebooks/rapids_mlflow.ipynb:cell 14:1:1: W391 [*] Extra newline at end of file
+ examples/sklearn_elasticnet_wine/train.ipynb:cell 6:1:1: W391 [*] Extra newline at end of file

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
W391 27 27 0 0 0

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser MichaReiser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution.

We should convert this to a token based rule OR avoid using a regex to fix the performance regression.

@charliermarsh
charliermarsh self-requested a review March 12, 2024 01:20
@charliermarsh charliermarsh self-assigned this Mar 12, 2024
@charliermarsh charliermarsh added rule Implementing or modifying a lint rule preview Related to preview mode features labels Mar 12, 2024
/// W391
pub(crate) fn too_many_newlines_at_end_of_file(
diagnostics: &mut Vec<Diagnostic>,
lxr: &[LexResult],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I removed the Locator. I don't think we need to guard on empty files here -- that's just for the "no trailing newline" check, since empty files would be a false positive.

@charliermarsh
charliermarsh merged commit b117f33 into astral-sh:main Mar 12, 2024
@augustelalande
augustelalande deleted the too_many_newlines branch March 12, 2024 02:45
@Avasam

Avasam commented Apr 30, 2024

Copy link
Copy Markdown
Contributor

One more step towards #9057 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants