Skip to content

Commit

Permalink
Switch to "ruff" linter, enable many of its rules
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Sep 10, 2023
1 parent 8c064b0 commit b810a87
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ jobs:
- name: Install dependencies
run: |
hatch run style:pip freeze
hatch run types:pip freeze
- name: Check style
if: always()
run: |
hatch run style:fix
- name: Check formatting
if: always()
run: |
hatch run style:format
git diff --exit-code
- name: Install dependencies
run: |
hatch run types:pip freeze
git diff --color --exit-code
- name: Check types
if: always()
run: |
hatch run types:check
5 changes: 4 additions & 1 deletion mkdocs_section_index/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import collections
import logging
from typing import TYPE_CHECKING

from jinja2 import Environment
from mkdocs.plugins import BasePlugin
from mkdocs.structure.nav import Navigation, Section
from mkdocs.structure.pages import Page

from . import SectionPage, rewrites

if TYPE_CHECKING:
from jinja2 import Environment

__all__ = ["SectionIndexPlugin"]

log = logging.getLogger(f"mkdocs.plugins.{__name__}")
Expand Down
30 changes: 20 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ include = ["/mkdocs_section_index", "/tests"]

[tool.hatch.envs.default.scripts]
all = [
"hatch run style:format",
"hatch run style:fix",
"hatch run types:check",
"hatch run test:test",
]
Expand Down Expand Up @@ -85,15 +85,16 @@ check = [
[tool.hatch.envs.style]
skip-install = true
dependencies = [
"pyupgrade",
"autoflake",
"ruff",
"isort",
"black",
]
[tool.hatch.envs.style.scripts]
fix = [
"ruff check --fix mkdocs_section_index tests",
"format",
]
format = [
"find mkdocs_section_index tests -name '*.py' | xargs pyupgrade --exit-zero-even-if-changed --py37-plus",
"autoflake -r mkdocs_section_index tests",
"isort -q mkdocs_section_index tests",
"black -q mkdocs_section_index tests",
]
Expand All @@ -112,11 +113,20 @@ line-length = 100
profile = "black"
line_length = 100

[tool.autoflake]
in-place = true
remove-all-unused-imports = true
remove-unused-variables = true
expand-star-imports = true
[tool.ruff]
select = [
"F", "W", "E", "UP", "YTT", "C4", "FA", "PIE", "T20", "RSE", "TCH", "DTZ",
"B002", "B003", "B005", "B007", "B009", "B012", "B013", "B014", "B015", "B018", "B020", "B021", "B023", "B026", "B033", "B034", "B905",
"COM818",
"PERF101",
"PGH002", "PGH004", "PGH005",
"PLE", "PLW0120", "PLW0127",
"RUF001", "RUF007", "RUF010", "RUF100", "RUF200",
"SIM101", "SIM107", "SIM201", "SIM202", "SIM208", "SIM210", "SIM211", "SIM300", "SIM401", "SIM910",
]
ignore = ["E501", "E731"]
[tool.ruff.flake8-comprehensions]
allow-dict-calls-with-keyword-arguments = true

[tool.mypy]
ignore_missing_imports = true
Expand Down
3 changes: 0 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import functools
import http.server
import logging
import sys
import threading

import pytest
Expand All @@ -20,8 +19,6 @@ def cap_log():

@pytest.fixture(scope="session")
def http_server(tmp_path_factory):
if sys.version_info < (3, 7):
pytest.skip("limitation of http.server", allow_module_level=True)
directory = tmp_path_factory.mktemp("http_server")
httpd = http.server.HTTPServer(
("localhost", 0),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_nav_repr(golden, tmpdir):

@contextlib.contextmanager
def template_test(directory):
config = dict()
config = {}
files = FakeFiles(config)
env = Environment(loader=FileSystemLoader(directory))
env.filters["url"] = lambda s: s
Expand Down

0 comments on commit b810a87

Please sign in to comment.