From c50567f2644fc6954f1b48078c64ae36d030ccb0 Mon Sep 17 00:00:00 2001 From: Kieran Ryan Date: Sat, 4 Jan 2025 19:46:55 +0000 Subject: [PATCH] debt: Migrate Python formatter from `black` to `ruff` - Faster tooling - Better handling with linting rule conflicts - Enables extending to hundreds of linting rules - Aligns with pytest-bdd (https://github.com/pytest-dev/pytest-bdd/pull/758) --- .pre-commit-config.yaml | 7 +++---- python/gherkin/ast_node.py | 1 - python/gherkin/dialect.py | 1 - python/gherkin/token_matcher_markdown.py | 3 --- python/pyproject.toml | 12 ++++++------ 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 34a8cdf4b7..f8558ee02b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,10 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: - # Using this mirror lets us use mypyc-compiled black, which is about 2x faster - - repo: https://github.com/psf/black-pre-commit-mirror - rev: c53240a7f974b3707e13eac6710542cc96a2d61a # frozen: 24.10.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: 89c421dff2e1026ba12cdb9ebd731f4a83aa8021 # frozen: v0.8.6 hooks: - - id: black + - id: ruff-format files: "^python/" - repo: https://github.com/asottile/pyupgrade rev: 19364aa1b2ac289ce75e6bbe93994f7b4b9425f6 # frozen: v3.19.0 diff --git a/python/gherkin/ast_node.py b/python/gherkin/ast_node.py index d345838baf..f586bf77a5 100644 --- a/python/gherkin/ast_node.py +++ b/python/gherkin/ast_node.py @@ -9,7 +9,6 @@ class AstNode: - def __init__(self, rule_type: str) -> None: self.rule_type = rule_type self._sub_items: defaultdict[str, list[object]] = defaultdict(list) diff --git a/python/gherkin/dialect.py b/python/gherkin/dialect.py index 3178cc94b5..3cfc9b4f70 100644 --- a/python/gherkin/dialect.py +++ b/python/gherkin/dialect.py @@ -33,7 +33,6 @@ class Dialect: - @classmethod def for_name(cls, name: str) -> Self | None: return cls(DIALECTS[name]) if name in DIALECTS else None diff --git a/python/gherkin/token_matcher_markdown.py b/python/gherkin/token_matcher_markdown.py index ca9eb890c2..7e991746d8 100644 --- a/python/gherkin/token_matcher_markdown.py +++ b/python/gherkin/token_matcher_markdown.py @@ -12,7 +12,6 @@ class GherkinInMarkdownTokenMatcher(TokenMatcher): - def __init__(self, dialect_name: str = "en") -> None: super().__init__(dialect_name) @@ -21,7 +20,6 @@ def reset(self) -> None: self.matched_feature_line = False def match_FeatureLine(self, token: Token) -> bool: - if self.matched_feature_line: self._set_token_matched(token, None) @@ -122,7 +120,6 @@ def match_Comment(self, token: Token) -> bool: return self._set_token_matched(token, None, False) def match_Empty(self, token: Token) -> bool: - result = False if token.line.is_empty(): result = True diff --git a/python/pyproject.toml b/python/pyproject.toml index 7a8a29b0d2..e8ef1eb8e1 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -44,12 +44,12 @@ gherkin = ["*.json"] disallow_untyped_defs = true packages = ["gherkin"] -[tool.black] -target-version = ["py39", "py310", "py311", "py312", "py313"] +[tool.ruff] +target-version = "py39" [tool.flake8] -# E1: indentation: already covered by `black` -# E2: whitespace: already covered by `black` -# E3: blank line: already covered by `black` -# E501: line length: already covered by `black` +# E1: indentation: already covered by `ruff` +# E2: whitespace: already covered by `ruff` +# E3: blank line: already covered by `ruff` +# E501: line length: already covered by `ruff` extend-ignore = "E1,E2,E3,E501"