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

Replace flake8 with ruff linter #590

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .flake8

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
restore-keys: "precommit-${{ runner.os }}-${{ steps.poetry_setup.outputs-python-version}}-"

- name: Run pre-commit hooks
run: SKIP=black,isort,flake8,pyright pre-commit run --all-files
run: SKIP=black,isort,ruff,pyright pre-commit run --all-files

- name: Run black formatter check
run: black --check --diff .
Expand All @@ -50,8 +50,8 @@ jobs:
- name: Run pyright type checker
run: pyright .

- name: Run flake8 linter
run: flake8 .
- name: Run ruff linter
run: ruff check --show-source .

# Steps below are here to generate and upload an artifact from
# this workflow so that we can have the data about author and some
Expand Down
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ repos:

- repo: local
hooks:
- id: flake8
name: Flake8
description: Run flake8 checks on the code
entry: poetry run flake8
- id: ruff
name: Ruff
description: Run ruff checks on the code
entry: poetry run ruff check --force-exclude
language: system
types: [python]
require_serial: true
args: [--fix, --exit-non-zero-on-fix]

- repo: local
hooks:
Expand Down
2 changes: 1 addition & 1 deletion mcstatus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mcstatus.server import BedrockServer, JavaServer, MCServer # noqa: F401
from mcstatus.server import BedrockServer, JavaServer, MCServer
ItsDrike marked this conversation as resolved.
Show resolved Hide resolved

__all__ = [
"MCServer",
Expand Down
2 changes: 1 addition & 1 deletion mcstatus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def deprecated(


def deprecated(
obj: Any = None, # noqa: ANN401
obj: Any = None,
ItsDrike marked this conversation as resolved.
Show resolved Hide resolved
*,
replacement: str | None = None,
version: str | None = None,
Expand Down
179 changes: 27 additions & 152 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 39 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,10 @@ pytest-rerunfailures = "^11.1.2"
coverage = "^7.2.6"

[tool.poetry.group.lint.dependencies]
ruff = "^0.0.278"
PerchunPak marked this conversation as resolved.
Show resolved Hide resolved
black = "^23.3.0"
coverage = "^7.2.6"
flake8 = "^6.0.0"
flake8-annotations = "^3.0.1"
flake8-bugbear = "^23.5.9"
flake8-tidy-imports = "^4.8.0"
flake8-pep585 = {version = "^0.1.7", python = ">=3.9"}
flake8-new-union-types = "^0.4.1"
flake8-future-annotations = "^1.1.0"
PerchunPak marked this conversation as resolved.
Show resolved Hide resolved
isort = "^5.12.0"
PerchunPak marked this conversation as resolved.
Show resolved Hide resolved
pep8-naming = "^0.13.3"
pyright = "^1.1.309"
typing-extensions = "^4.6.1"

Expand Down Expand Up @@ -99,6 +92,44 @@ bump = true
enable = true
style = "pep440"

[tool.ruff]
target-version = "py38"
line-length = 127

select = [
"F", # Pyflakes
"W", # Pycodestyle (warnigns)
"E", # Pycodestyle (errors)
"N", # pep8-naming
"ANN", # flake8-annotations
"B", # flake8-bugbear
"FA", # flake8-future-annotations
"TID", # flake8-tidy-imports
"UP007", # flake8-new-union-types equivalent rule
"RUF", # ruff's custom rules
]

ignore = [
PerchunPak marked this conversation as resolved.
Show resolved Hide resolved
"ANN002", # Missing type annotation for *args
"ANN003", # Missing type annotation for **kwargs
"ANN101", # Missing type annotation for self in method
"ANN102", # Missing type annotation for cls in classmethod
"ANN204", # Missing return type annotation for special method
"B904", # Exception raised within try-except should use raise ... from exc
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
]

[tool.ruff.extend-per-file-ignores]
"test_*.py" = [
"ANN", # flake8-annotations
]
"docs/examples/code/**" = [
"FA", # flake8-future-annotations
]

PerchunPak marked this conversation as resolved.
Show resolved Hide resolved
[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.black]
line-length = 127

Expand Down
4 changes: 2 additions & 2 deletions tests/motd/test_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def test_correct_output(self, result: Callable[["str | dict", bool], str], sourc
"<span style='color:rgb(170, 0, 0);text-shadow:0 0 1px rgb(42, 0, 0)'>8</span>"
"<span style='color:rgb(170, 0, 170);text-shadow:0 0 1px rgb(42, 0, 42)'>9</span>"
"<span style='color:rgb(255, 170, 0);text-shadow:0 0 1px rgb"
+ str((64, 42, 0) if bedrock else (42, 42, 0)) # noqa: W503
+ "'>10</span>" # noqa: W503
+ str((64, 42, 0) if bedrock else (42, 42, 0))
+ "'>10</span>"
ItsDrike marked this conversation as resolved.
Show resolved Hide resolved
"<span style='color:rgb(170, 170, 170);text-shadow:0 0 1px rgb(42, 42, 42)'>11</span>"
"<span style='color:rgb(85, 85, 85);text-shadow:0 0 1px rgb(21, 21, 21)'>12</span>"
"<span style='color:rgb(85, 85, 255);text-shadow:0 0 1px rgb(21, 21, 63)'>13</span>"
Expand Down
2 changes: 1 addition & 1 deletion tests/status_response/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BaseStatusResponseTest(abc.ABC):
# if we don't specify item in raw answer, target field will be None
# first element is a list with fields to remove, and attribute that
# must be None. a dict is a raw answer to pass into `build` method
OPTIONAL_FIELDS: tuple[list[tuple[str, str]], dict[str, Any]] | None = None # noqa: ANN401
OPTIONAL_FIELDS: tuple[list[tuple[str, str]], dict[str, Any]] | None = None
PerchunPak marked this conversation as resolved.
Show resolved Hide resolved

def _validate(self) -> None:
"""Perform checks to validate the class."""
Expand Down