Skip to content

Commit

Permalink
Enable all ruff's linting rules
Browse files Browse the repository at this point in the history
I do like to be notified if I leave an unused import in my code, so I
tried adding the F401 rule to my Makefile.

It flagged the unused import of `page` into `wpsite`, which was there to
make the `page` module importable in tests with:

    from .context import page

Unused imports can be silenced by defining `__all__`, so it made sense
to squash that by listing the modules in `__all__`. However, given that
I included the import for testing purposes, why not move the fix to the
test setup?

So I've explicitly imported all tested modules in `tests/context.py`
instead.

I then realised that I was only one step away from enabling all of
ruff's linting rules; ignoring E402 which complains if module-level
imports aren't at the top of the file. That was easily fixed with a
quick:

    ruff check --add-noqa .
  • Loading branch information
gma committed Nov 15, 2023
1 parent 77210ed commit 9c82fa5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ check: lint format types

.PHONY: lint
lint:
ruff check . --select E9,F63,F7,F82 --show-source
ruff check . --show-source

.PHONY: format
format:
Expand Down
6 changes: 5 additions & 1 deletion tests/context.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
__all__ = ['astro', 'page', 'wp']

import os
import sys

project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(0, project_root)

from wpsite import *
from wpsite import astro # noqa: E402
from wpsite import page # noqa: E402
from wpsite import wp # noqa: E402


def rss_doc(xml: str) -> str:
Expand Down
3 changes: 1 addition & 2 deletions wpsite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
"""

from pathlib import Path

from pathlib import Path

from . import astro
from . import page
from . import wp


Expand Down

0 comments on commit 9c82fa5

Please sign in to comment.