Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt ruff for linting #2090

Open
simonw opened this issue Jun 29, 2023 · 2 comments
Open

Adopt ruff for linting #2090

simonw opened this issue Jun 29, 2023 · 2 comments

Comments

@simonw
Copy link
Owner

simonw commented Jun 29, 2023

https://beta.ruff.rs/docs/

@simonw simonw added the ci label Jun 29, 2023
@simonw
Copy link
Owner Author

simonw commented Jun 29, 2023

I tried it just now and got some interesting results.

I dropped in a ruff.toml file:

line-length = 160

Because the default line length limit of 88 was causing a lot of noisy errors.

Then run:

pip install ruff
ruff check .

Plenty of warnings about unused imports - running ruff check . --fix fixed those automatically, but I think I still need to manually review them as some might be imports which are deliberate and should be in __all__ to ensure they are visible from that module as well.

Some lines in tests are longer than even 160 chars, e.g.:

expected_tds = [
[
'<td class="col-data"><a class="blob-download" href="/fixtures.blob?sql=select+*+from+binary_data&amp;_blob_column=data&amp;_blob_hash=f3088978da8f9aea479ffc7f631370b968d2e855eeb172bea7f6c7a04262bb6d">&lt;Binary:\xa07\xa0bytes&gt;</a></td>'
],
[
'<td class="col-data"><a class="blob-download" href="/fixtures.blob?sql=select+*+from+binary_data&amp;_blob_column=data&amp;_blob_hash=b835b0483cedb86130b9a2c280880bf5fadc5318ddf8c18d0df5204d40df1724">&lt;Binary:\xa07\xa0bytes&gt;</a></td>'
],
['<td class="col-data">\xa0</td>'],
]

These can have # noqa: E501 added to the end of those lines to skip the check for them.

That got it down to:

% ruff check . 
datasette/views/table.py:23:5: F811 Redefinition of unused `format_bytes` from line 19
run_tests.py:2:5: E401 Multiple imports on one line
tests/test_api.py:591:40: F811 Redefinition of unused `app_client_no_files` from line 7
tests/test_api.py:629:35: F811 Redefinition of unused `app_client_no_files` from line 7
tests/test_api.py:635:54: F811 Redefinition of unused `app_client_with_dot` from line 8
tests/test_api.py:661:25: F811 Redefinition of unused `app_client_shorter_time_limit` from line 9
tests/test_api.py:759:25: F811 Redefinition of unused `app_client_two_attached_databases_one_immutable` from line 10
tests/test_api.py:892:28: F811 Redefinition of unused `app_client_larger_cache_size` from line 11
tests/test_api.py:928:5: F811 Redefinition of unused `app_client_with_cors` from line 12
tests/test_api.py:929:5: F811 Redefinition of unused `app_client_two_attached_databases_one_immutable` from line 10
tests/test_api.py:969:38: F811 Redefinition of unused `app_client_two_attached_databases` from line 13
tests/test_api.py:976:39: F811 Redefinition of unused `app_client_conflicting_database_names` from line 14
tests/test_api.py:987:38: F811 Redefinition of unused `app_client_immutable_and_inspect_file` from line 15
tests/test_api.py:1002:24: F811 Redefinition of unused `app_client` from line 6
tests/test_csv.py:67:33: F811 Redefinition of unused `app_client_with_cors` from line 6
tests/test_csv.py:157:21: F811 Redefinition of unused `app_client_csv_max_mb_one` from line 5
tests/test_csv.py:198:20: F811 Redefinition of unused `app_client_with_trace` from line 7
tests/test_csv.py:209:53: F811 Redefinition of unused `app_client_with_trace` from line 7
tests/test_csv.py:215:53: F811 Redefinition of unused `app_client_with_trace` from line 7
tests/test_filters.py:102:11: F811 Redefinition of unused `test_through_filters_from_request` from line 81
tests/test_html.py:19:19: F811 Redefinition of unused `app_client_two_attached_databases` from line 7
tests/test_html.py:175:25: F811 Redefinition of unused `app_client_shorter_time_limit` from line 6
tests/test_html.py:469:51: F811 Redefinition of unused `app_client` from line 4
tests/test_html.py:797:26: F811 Redefinition of unused `app_client_base_url_prefix` from line 5
tests/test_html.py:840:44: F811 Redefinition of unused `app_client_base_url_prefix` from line 5
tests/test_html.py:850:51: F811 Redefinition of unused `app_client_base_url_prefix` from line 5
tests/test_pagination.py:50:43: F821 Undefined name `parse_next`
tests/test_pagination.py:82:7: F811 Redefinition of unused `KeysetPaginator` from line 36
tests/test_plugins.py:115:15: E741 Ambiguous variable name: `l`
tests/test_plugins.py:482:161: E501 Line too long (170 > 160 characters)
tests/test_plugins.py:543:29: E741 Ambiguous variable name: `l`
tests/test_plugins.py:563:161: E501 Line too long (170 > 160 characters)
tests/test_plugins.py:940:62: E741 Ambiguous variable name: `l`
tests/test_table_api.py:739:5: F811 Redefinition of unused `app_client_returned_rows_matches_page_size` from line 6
tests/test_table_api.py:1066:45: F811 Redefinition of unused `app_client_with_trace` from line 5
tests/test_table_html.py:484:29: E741 Ambiguous variable name: `l`
tests/test_table_html.py:524:29: E741 Ambiguous variable name: `l`
tests/test_table_html.py:675:161: E501 Line too long (165 > 160 characters)
tests/test_table_html.py:897:161: E501 Line too long (164 > 160 characters)
tests/test_table_html.py:902:161: E501 Line too long (164 > 160 characters)
tests/test_utils.py:141:161: E501 Line too long (176 > 160 characters)
Found 41 errors.

Those "Redefinition of unused app_client_two_attached_databases" lines are caused because of the fixtures pattern I'm using here:

from .fixtures import ( # noqa
app_client,
app_client_base_url_prefix,
app_client_shorter_time_limit,
app_client_two_attached_databases,
make_app_client,
METADATA,
)
from .utils import assert_footer_links, inner_html
import json
import pathlib
import pytest
import re
import urllib.parse
def test_homepage(app_client_two_attached_databases):
response = app_client_two_attached_databases.get("/")

I could fix that by getting rid of fixtures.py and moving those into conftest.py.

@simonw
Copy link
Owner Author

simonw commented Jun 29, 2023

Decided to fix just those "Ambiguous variable name" ones:

ruff check . | grep E741

Then iterated through and fixed them all.

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

No branches or pull requests

1 participant