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 8731626 commit dbf35ee
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
10 changes: 7 additions & 3 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
- name: Check types
if: always()
run: |
hatch run types:check
2 changes: 1 addition & 1 deletion mkdocs_gen_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import logging

from .editor import FilesEditor
from .nav import Nav # noqa
from .nav import Nav # noqa: F401 - re-export

__version__ = "0.5.0"

Expand Down
4 changes: 2 additions & 2 deletions mkdocs_gen_files/config_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def run_validation(self, value):
raise ValidationError(f"Expected a list of items, but a {type(value)} was given.")

result = []
for item in value:
for _ in value:
self.option_type.pre_validation(self._config, self._key_name)
for item in value:
result.append(self.option_type.validate(item))
for item in value:
for _ in value:
self.option_type.post_validation(self._config, self._key_name)
return result

Expand Down
18 changes: 14 additions & 4 deletions mkdocs_gen_files/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,34 @@
import runpy
import tempfile
import urllib.parse
from typing import Callable

from mkdocs.config import Config
from mkdocs.plugins import BasePlugin
from mkdocs.structure.files import Files
from mkdocs.structure.pages import Page

try:
from mkdocs.exceptions import PluginError
except ImportError:
PluginError = SystemExit # type: ignore

from typing import TYPE_CHECKING, TypeVar

from .config_items import ListOfFiles
from .editor import FilesEditor

if TYPE_CHECKING:
from mkdocs.config import Config
from mkdocs.structure.files import Files
from mkdocs.structure.pages import Page

T = TypeVar("T")

try:
from mkdocs.plugins import event_priority
except ImportError:
event_priority = lambda priority: lambda f: f # No-op fallback

def event_priority(priority: float) -> Callable[[T], T]:
return lambda f: f # No-op fallback


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 @@ -54,7 +54,7 @@ include = ["/mkdocs_gen_files", "/tests"]

[tool.hatch.envs.default.scripts]
all = [
"hatch run style:format",
"hatch run style:fix",
"hatch run types:check",
"hatch run test:test",
]
Expand All @@ -81,15 +81,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_gen_files tests",
"format",
]
format = [
"find mkdocs_gen_files tests -name '*.py' | xargs pyupgrade --exit-zero-even-if-changed --py37-plus",
"autoflake -r mkdocs_gen_files tests",
"isort -q mkdocs_gen_files tests",
"black -q mkdocs_gen_files 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

0 comments on commit dbf35ee

Please sign in to comment.