Skip to content

Commit

Permalink
feat: introduce ruff for linter
Browse files Browse the repository at this point in the history
and remove flake8, isort, and autoflake
  • Loading branch information
zhongjiajie committed Oct 18, 2023
1 parent b6b067b commit 7f230e4
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 64 deletions.
26 changes: 4 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,12 @@ default_language_version:
python: python3
repos:
# Python API Hooks
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 3.8.0
hooks:
- id: flake8
pass_filenames: false
additional_dependencies: [
'flake8-docstrings>=1.6',
'flake8-black>=0.2',
]
- repo: https://github.com/pycqa/autoflake
rev: v1.4
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.0
hooks:
- id: autoflake
args: [
--remove-all-unused-imports,
--ignore-init-module-imports,
--in-place
]
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
46 changes: 46 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
src = ["src"]

# max-line-length = 88
line-length = 110

extend-select = [
"I", # isort
"D", # pydocstyle
"UP", # pyupgrade
]

ignore = [
# D100 Missing docstring in public module
"D100",
# D100 Missing docstring in public module
"D104",
# D107: Missing docstring in __init__
"D107",
# D105: Missing docstring in magic method
"D105",
# D418: Function/ Method decorated with @overload shouldn’t contain a docstring
"D418",
]

# Exclude a variety of commonly ignored directories.
exclude = [
"__pycache__",
".egg-info",
".eggs",
".git",
".pytest_cache",
".tox",
"build",
"dist",
"examples",
"venv",
]

[isort]
# Mark sqlfluff, test and it's plugins as known first party
known-first-party = [
"stmdency",
]

[pydocstyle]
convention = "google"
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
[![Downloads](https://pepy.tech/badge/stmdency/month)](https://pepy.tech/project/stmdency)
[![Coverage Status](https://img.shields.io/codecov/c/github/zhongjiajie/stmdency/main.svg?style=flat-square)](https://codecov.io/github/zhongjiajie/stmdency?branch=main) <!-- markdown-link-check-disable-line -->
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat-square&labelColor=ef8336)](https://pycqa.github.io/isort)
[![CI](https://github.com/zhongjiajie/stmdency/actions/workflows/ci.yaml/badge.svg)](https://github.com/zhongjiajie/stmdency/actions/workflows/ci.yaml)
[![Documentation Status](https://readthedocs.org/projects/stmdency/badge/?version=latest)](https://stmdency.readthedocs.io/en/latest/?badge=latest)

Expand Down
33 changes: 1 addition & 32 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ stmdency =
dev =
# style
black>=22.8
flake8>=4.0
flake8-docstrings>=1.6
flake8-black>=0.2
isort>=5.10
autoflake>=1.4
ruff>=0.1
# test
pytest>=6.2
pytest-cov>=3.0
Expand All @@ -69,33 +65,6 @@ dev =
sphinx-copybutton>=0.4.0
sphinx-argparse>=0.3.2

[flake8]
max-line-length = 110
exclude =
.git,
__pycache__,
.pytest_cache,
*.egg-info,
build,
dist,
.tox,
examples,
tests,
ignore =
# D107: Don't require docstrings on __init__
D107,
# D105: Missing docstring in magic method
D105,
# D104: Missing docstring in public package
D104,
# D100: Missing docstring in public module
D100,
# W503: Line breaks before binary operators
W503,

[isort]
profile=black

[coverage:run]
command_line = -m pytest

Expand Down
2 changes: 1 addition & 1 deletion src/stmdency/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class StmdencyNode:

# name: str
node: cst.CSTNode
parent: list["StmdencyNode"] = field(default_factory=list)
parent: list[StmdencyNode] = field(default_factory=list)

def __hash__(self):
return hash(self.node)
Expand Down
3 changes: 2 additions & 1 deletion src/stmdency/visitors/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from libcst import AssignTarget, Call, Name

from stmdency.models.node import StmdencyNode
from stmdency.visitors.base import BaseVisitor


@dataclass
Expand All @@ -19,7 +20,7 @@ class AssignVisitor(cst.CSTVisitor):
"""

# current: str
PV: "BaseVisitor" # noqa: F821
PV: BaseVisitor
root_node: cst.CSTNode
name: str = None

Expand Down
3 changes: 2 additions & 1 deletion src/stmdency/visitors/function_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from libcst import Assign, Attribute, Call, FunctionDef, Name, Param

from stmdency.models.node import StmdencyNode
from stmdency.visitors.base import BaseVisitor


@dataclass
Expand All @@ -19,7 +20,7 @@ class FunctionDefVisitor(cst.CSTVisitor):
:param scope: statement scope set to avoid error handle
"""

PV: "BaseVisitor" # noqa: F821
PV: BaseVisitor # noqa: F821
func_name: str | None = None
local_param: set[str] = field(default_factory=set)
# Add scope to determine if the node is in the same scope
Expand Down
1 change: 1 addition & 0 deletions tests/extractor/test_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@

@pytest.mark.parametrize("name, source, expects", assign_cases)
def test_assign(name: str, source: str, expects: dict[str, str]) -> None:
"""Test assignment extraction."""
assert_extract(name, source, expects)
1 change: 1 addition & 0 deletions tests/extractor/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,5 @@ def foo():

@pytest.mark.parametrize("name, source, expects", func_cases)
def test_func(name: str, source: str, expects: dict[str, str]) -> None:
"""Test function extraction."""
assert_extract(name, source, expects)
1 change: 1 addition & 0 deletions tests/extractor/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,5 @@ def bar():

@pytest.mark.parametrize("name, source, expects", import_cases)
def test_import(name: str, source: str, expects: dict[str, str]) -> None:
"""Test import statement."""
assert_extract(name, source, expects)
1 change: 1 addition & 0 deletions tests/extractor/test_module_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ def foo():

@pytest.mark.parametrize("name, source, expects", import_cases)
def test_import(name: str, source: str, expects: dict[str, str]) -> None:
"""Test import statement."""
assert_extract(name, source, expects)
1 change: 1 addition & 0 deletions tests/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


def assert_extract(name: str, source: str, expects: dict[str, str]) -> None:
"""Test tools, asserting the extracted code is the same as expected."""
wrap_source = textwrap.dedent(source)
extractor = Extractor(source=wrap_source)
for expect in expects:
Expand Down
8 changes: 2 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,18 @@ envlist = auto-lint, lint, code-test, local-ci, doc-build, py{38,39,310,311,312}
[testenv]
allowlist_externals =
make
git

[testenv:auto-lint]
extras = dev
commands =
python -m isort .
python -m black .
python -m autoflake --in-place --remove-all-unused-imports --ignore-init-module-imports --recursive .
python -m ruff check --fix .

[testenv:lint]
extras = dev
commands =
python -m isort --check .
python -m black --check .
python -m flake8
python -m autoflake --remove-all-unused-imports --ignore-init-module-imports --check --recursive .
python -m ruff check .

[testenv:doc-build]
extras = doc
Expand Down

0 comments on commit 7f230e4

Please sign in to comment.