Skip to content

Commit a7a804c

Browse files
committed
add linter config
1 parent f6026a8 commit a7a804c

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed

.editorconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.py]
10+
indent_style = space
11+
indent_size = 4
12+
max_line_length = 88
13+
14+
[*.{yml,yaml}]
15+
indent_style = space
16+
indent_size = 2
17+
18+
[*.{json,js,ts}]
19+
indent_style = space
20+
indent_size = 2
21+
22+
[*.md]
23+
trim_trailing_whitespace = false
24+
25+
[Makefile]
26+
indent_style = tab

.pre-commit-config.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-merge-conflict
10+
- id: check-toml
11+
- id: mixed-line-ending
12+
args: ['--fix=lf']
13+
- id: check-case-conflict
14+
15+
- repo: https://github.com/psf/black
16+
rev: 23.7.0
17+
hooks:
18+
- id: black
19+
language_version: python3
20+
args: [--line-length=88]
21+
22+
- repo: https://github.com/pycqa/isort
23+
rev: 5.12.0
24+
hooks:
25+
- id: isort
26+
args: [--profile=black, --line-length=88]
27+
28+
- repo: https://github.com/charliermarsh/ruff-pre-commit
29+
rev: v0.1.6
30+
hooks:
31+
- id: ruff
32+
args: [--fix, --exit-non-zero-on-fix]
33+
- id: ruff-format
34+
35+
- repo: https://github.com/pre-commit/mirrors-mypy
36+
rev: v1.5.1
37+
hooks:
38+
- id: mypy
39+
additional_dependencies: [types-requests]
40+
exclude: ^(tests/|examples/)

lint.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Lint runner script for pytrickle project.
4+
Runs all configured linting tools with proper 4-space indentation and POSIX line endings.
5+
"""
6+
7+
import subprocess
8+
import sys
9+
from pathlib import Path
10+
11+
12+
def run_command(cmd: list[str], description: str) -> bool:
13+
"""Run a command and return True if successful."""
14+
print(f"\n🔍 Running {description}...")
15+
try:
16+
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
17+
print(f"✅ {description} passed")
18+
if result.stdout:
19+
print(result.stdout)
20+
return True
21+
except subprocess.CalledProcessError as e:
22+
print(f"❌ {description} failed")
23+
if e.stdout:
24+
print("STDOUT:", e.stdout)
25+
if e.stderr:
26+
print("STDERR:", e.stderr)
27+
return False
28+
29+
30+
def main():
31+
"""Run all linting tools."""
32+
project_root = Path(__file__).parent
33+
python_files = ["pytrickle", "tests", "examples"]
34+
35+
# Change to project root
36+
import os
37+
os.chdir(project_root)
38+
39+
success = True
40+
41+
# Run Black formatter
42+
success &= run_command(
43+
["black", "--check", "--diff"] + python_files,
44+
"Black code formatting check"
45+
)
46+
47+
# Run isort import sorting
48+
success &= run_command(
49+
["isort", "--check-only", "--diff"] + python_files,
50+
"isort import sorting check"
51+
)
52+
53+
# Run Ruff linter
54+
success &= run_command(
55+
["ruff", "check"] + python_files,
56+
"Ruff linting"
57+
)
58+
59+
# Run Ruff formatter
60+
success &= run_command(
61+
["ruff", "format", "--check"] + python_files,
62+
"Ruff formatting check"
63+
)
64+
65+
# Run MyPy type checking
66+
success &= run_command(
67+
["mypy"] + python_files,
68+
"MyPy type checking"
69+
)
70+
71+
if success:
72+
print("\n🎉 All linting checks passed!")
73+
return 0
74+
else:
75+
print("\n💥 Some linting checks failed!")
76+
return 1
77+
78+
79+
if __name__ == "__main__":
80+
sys.exit(main())

0 commit comments

Comments
 (0)