Skip to content

Commit

Permalink
Migrate to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukzak committed Apr 6, 2024
1 parent 72873c9 commit bc08605
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 12 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ jobs:
coverage run -m pytest --verbose
coverage report *.py
- name: Check code style
run: pycodestyle .
- name: Lint check
uses: chartboost/ruff-action@v1

- name: Check python file for typical errors
run: pyflakes .
- name: Format check
uses: chartboost/ruff-action@v1
with:
args: 'format --check'

# type annotation checks
- name: Type checks
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Mac
.DS_Store
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ enough for educational purposes.
## Changelog

- 29.03.2022 - 2
- Add test coverage.
- Add test coverage.
- 29.03.2022 - 1
- Update README. Add formal sections.
- Update README. Add formal sections.
- 29.03.2022 - 0
- Initial
- Initial

## Design notes

Expand Down
2 changes: 1 addition & 1 deletion foo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Foo(object):
class Foo:
def hello(self):
return "hello"

Expand Down
8 changes: 4 additions & 4 deletions foo_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import unittest
from hypothesis import given, strategies

from hypothesis import given, strategies

from foo import Foo


class TestFoo(unittest.TestCase):

def test_hello(self):
self.assertEqual(Foo().hello(), "hello")
assert Foo().hello() == "hello"

@given(strategies.integers(), strategies.integers())
def test_add_commutative(self, a, b):
self.assertEqual(Foo().add(a, b), Foo().add(b, a))
assert Foo().add(a, b) == Foo().add(b, a)
56 changes: 56 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[tool.ruff]
line-length = 120
select = [
# A set of chosen linter rules is specified here.
# See https://beta.ruff.rs/docs/rules/ for more info.
# pyflakes (simple obvious errors)
"F",
# pycodestyle (style linter, pep8, black-compatible)
"E",
"W",
# pep8-naming (style linter, pep8 naming conventions)
"N",
# isort (imports sorting)
"I",
# mccabe (cyclomatic complexity analyzer to prevent overcomplicated functions)
"C90",
# pyupgrade (possible syntax upgrades checker)
"UP",
# eradicate (commented-out code finder for it to be removed)
"ERA",
# flake8-2020 (errors related to sys.version or sys.version_info, just in case)
"YTT",
# flake8-annotations (enforces presense of type hints so the codebase is fully typed)
# "ANN", # too burdensome
# flake8-async (async-related mistakes/errors)
"ASYNC",
# flake8-builtins (checks builtin names shadowing, it's better not to)
"A",
# flake8-commas (to enforce trailing commas)
"COM",
# flake8-future-annotations (to ensure enabling modern (3.7+) postponed evaluation of type hints)
"FA",
# flake8-import-conventions (to enforce standartized import aliases like "import pandas as pd")
"ICN",
# flake8-no-pep420 (to enforce presence of __init__.py in packages)
"INP",
# flake8-print (to disallow print statements)
"T20",
# flake8-pytest-style (to improve pytest-related style consistency)
"PT",
# flake8-quotes (to enforce quotes style)
"Q",
# flake8-return (checks mistakes related to return values)
"RET",
# flake8-use-pathlib (to enforce pathlib usage instead of os.path)
"PTH",
# pandas-vet (pandas-related advices)
"PD",
# tryceratops (try/except-related advices)
"TRY",
# ruff-specific advices
"RUF",
]
ignore = [
"COM812", # The following rules may cause conflicts when used with the formatter: `COM812`.
]

0 comments on commit bc08605

Please sign in to comment.