Skip to content

Commit

Permalink
debt: Migrate Python formatter from black to ruff
Browse files Browse the repository at this point in the history
- Faster tooling
- Better handling with linting rule conflicts
- Enables extending to hundreds of linting rules
- Aligns with pytest-bdd (pytest-dev/pytest-bdd#758)
  • Loading branch information
kieran-ryan committed Jan 4, 2025
1 parent 26ba405 commit c50567f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
7 changes: 3 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion python/gherkin/ast_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion python/gherkin/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions python/gherkin/token_matcher_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


class GherkinInMarkdownTokenMatcher(TokenMatcher):

def __init__(self, dialect_name: str = "en") -> None:
super().__init__(dialect_name)

Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit c50567f

Please sign in to comment.