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

Use ruff for linting and formatting #99

Merged
merged 3 commits into from
Jan 30, 2024
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
4 changes: 0 additions & 4 deletions .bandit

This file was deleted.

66 changes: 9 additions & 57 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,66 +24,18 @@ repos:
- id: mypy
additional_dependencies:
- types-toml
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: python-use-type-annotations
- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args: ["--max-line-length", "88", "--extend-ignore", "E501"]
additional_dependencies:
- flake8-bugbear
- flake8-builtins
- repo: https://github.com/PyCQA/bandit
rev: 1.7.6
hooks:
- id: bandit
args: ["-c", ".bandit"]
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
args: ["--convention", "pep257", "--add-ignore", "D100,D102"]
additional_dependencies:
- toml
exclude: airflint/__main__.py|tests/
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.15
hooks:
- id: ruff
args:
- --fix
- --unsafe-fixes
- id: ruff-format
- repo: https://github.com/crate-ci/typos
rev: v1.17.1
rev: v1.17.2
hooks:
- id: typos
- repo: https://github.com/pycqa/autoflake
rev: v2.2.1
hooks:
- id: autoflake
args: ["--remove-all-unused-imports", "--in-place"]
- repo: local
hooks:
- id: pytest
Expand Down
1 change: 1 addition & 0 deletions airflint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Top-level package for airflint."""

from importlib.metadata import version
from os import getcwd
from os.path import dirname, join, realpath
Expand Down
8 changes: 5 additions & 3 deletions airflint/rules/use_jinja_variable_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ def _lookup_template_fields(self, keyword: ast.keyword) -> None:
and scope.can_reach(self.context["scope"].resolve(node))
)
except StopIteration:
raise AssertionError("Could not find import definition. Skipping..")
raise AssertionError(
"Could not find import definition. Skipping.."
) from None
assert (module_name := import_node.module)

# Try to import the module into python.
try:
_module = import_module(module_name)
except ImportError:
raise AssertionError("Could not import module. Skipping..")
except ImportError as e:
raise AssertionError("Could not import module. Skipping..") from e
assert (file_path := _module.__file__)

# Parse the ast to check if the keyword is in template_fields.
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@ build-backend = "poetry.core.masonry.api"

[tool.coverage.run]
omit = ["airflint/__main__.py"]

[tool.ruff]
target-version = "py39"

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "B", "S", "UP", "PGH", "D", "I", "A"]
ignore = ["D100", "D102"]

[tool.ruff.per-file-ignores]
"tests/*" = ["S101", "D"]
"airflint/rules/*.py" = ["S101"]
"airflint/__main__.py" = ["D"]

[tool.ruff.pydocstyle]
convention = "pep257"
Loading