Skip to content

Commit 3790800

Browse files
committed
fix: add lint and typing check
1 parent ca85ddb commit 3790800

File tree

4 files changed

+573
-40
lines changed

4 files changed

+573
-40
lines changed

.github/workflows/validate.yaml

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
name: Validate
1+
---
2+
name: validate
23

34
on:
45
push:
6+
branches: [main]
57
pull_request:
8+
branches: [main]
69

710
env:
811
PIP_DISABLE_PIP_VERSION_CHECK: true
@@ -11,57 +14,50 @@ env:
1114
PIP_ROOT_USER_ACTION: ignore
1215

1316
jobs:
14-
create-venv:
17+
lint-yaml:
18+
name: lint workflow yaml
1519
runs-on: ubuntu-latest
16-
name: Setup Python + uv
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Run yamllint
23+
uses: karancode/yamllint-github-action@master
24+
with:
25+
yamllint_file_or_dir: .github/workflows
26+
27+
validate-and-lint:
28+
name: Validate and Run Linters
29+
runs-on: ubuntu-latest
30+
needs: [lint-yaml]
1731
steps:
1832
- name: Checkout code
1933
uses: actions/checkout@v4
2034

21-
- name: Set up Python 3.12
35+
- name: set up python
2236
uses: actions/setup-python@v5
2337
with:
24-
python-version: 3.12
38+
python-version: '3.12'
2539

26-
- name: Install uv and dependencies
27-
run: |
28-
pip install uv
29-
uv venv
30-
uv pip install --group bandit --group mypy --group ruff --group secret
31-
env:
32-
PIP_INDEX_URL: ${{ env.PIP_INDEX_URL }}
40+
- name: set up uv
41+
uses: astral-sh/setup-uv@v4
3342

34-
- name: Save env variable
35-
run: echo "PYPI_MIRROR=${{ env.PIP_INDEX_URL }}" >> $GITHUB_ENV
43+
- name: create virtual enviroment
44+
run: uv venv
3645

37-
bandit:
38-
runs-on: ubuntu-latest
39-
needs: create-venv
40-
steps:
41-
- uses: actions/checkout@v4
42-
- name: Run bandit
43-
run: .venv/bin/bandit -c pyproject.toml -r .
46+
- name: Install dependencies
47+
run: uv sync --group dev --group lint --group security --group typing
48+
49+
- name: Run Bandit
50+
run: uv run bandit -c pyproject.toml -r .
4451

45-
mypy:
46-
runs-on: ubuntu-latest
47-
needs: create-venv
48-
steps:
49-
- uses: actions/checkout@v4
5052
- name: Run mypy
51-
run: .venv/bin/mypy .
53+
run: uv run mypy .
5254

53-
ruff:
54-
runs-on: ubuntu-latest
55-
needs: create-venv
56-
steps:
57-
- uses: actions/checkout@v4
5855
- name: Run ruff
59-
run: .venv/bin/ruff check .
56+
run: uv run ruff check .
6057

61-
secrets:
62-
runs-on: ubuntu-latest
63-
needs: create-venv
64-
steps:
65-
- uses: actions/checkout@v4
6658
- name: Run detect-secrets
67-
run: .venv/bin/detect-secrets-hook --baseline .secrets.baseline
59+
run: |
60+
FILES_TO_SCAN=$(git ls-files -z | xargs -0)
61+
uv run detect-secrets-hook \
62+
--baseline .secrets.baseline \
63+
"${FILES_TO_SCAN}"

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def main():
1+
def main() -> None:
22
print("Hello from mmdocparser!")
33

44

pyproject.toml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,66 @@ description = "Add your description here"
55
readme = "README.md"
66
requires-python = ">=3.12"
77
dependencies = []
8+
9+
10+
[dependency-groups]
11+
all-dev = [
12+
{include-group = "dev"},
13+
{include-group = "lint"},
14+
{include-group = "security"},
15+
{include-group = "typing"}
16+
]
17+
dev = [
18+
"pytest>=8.4.1",
19+
"pytest-cov>=6.2.1",
20+
]
21+
lint = [
22+
"bandit>=1.8.6",
23+
"ruff>=0.12.7",
24+
]
25+
security = [
26+
"detect-secrets>=1.5.0",
27+
]
28+
typing = [
29+
"mypy>=1.17.1",
30+
]
31+
32+
[tool.bandit]
33+
exclude_dirs = [".venv", ".git", ".mypy_cache"]
34+
skips = ["B101", "B601"]
35+
36+
[tool.mypy]
37+
python_version = "3.12"
38+
warn_return_any = true
39+
warn_unused_configs = true
40+
disallow_untyped_defs = true
41+
disallow_incomplete_defs = true
42+
check_untyped_defs = true
43+
disallow_untyped_decorators = true
44+
no_implicit_optional = true
45+
warn_redundant_casts = true
46+
warn_unused_ignores = true
47+
warn_no_return = true
48+
warn_unreachable = true
49+
strict_equality = true
50+
51+
[tool.ruff]
52+
target-version = "py312"
53+
line-length = 88
54+
select = [
55+
"E", # pycodestyle errors
56+
"W", # pycodestyle warnings
57+
"F", # pyflakes
58+
"I", # isort
59+
"B", # flake8-bugbear
60+
"C4", # flake8-comprehensions
61+
"UP", # pyupgrade
62+
]
63+
ignore = [
64+
"E501", # line too long, handled by black
65+
"B008", # do not perform function calls in argument defaults
66+
"C901", # too complex
67+
]
68+
69+
[tool.ruff.per-file-ignores]
70+
"__init__.py" = ["F401"]

0 commit comments

Comments
 (0)