From a7a804c0f821527fc813b6b525bbad23935d1a95 Mon Sep 17 00:00:00 2001 From: John | Elite Encoder Date: Thu, 21 Aug 2025 21:22:41 -0400 Subject: [PATCH] add linter config --- .editorconfig | 26 ++++++++++++++ .pre-commit-config.yaml | 40 +++++++++++++++++++++ lint.py | 80 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 .editorconfig create mode 100644 .pre-commit-config.yaml create mode 100644 lint.py diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1179fb3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.py] +indent_style = space +indent_size = 4 +max_line_length = 88 + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 + +[*.{json,js,ts}] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false + +[Makefile] +indent_style = tab diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..71d4a5a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,40 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: check-merge-conflict + - id: check-toml + - id: mixed-line-ending + args: ['--fix=lf'] + - id: check-case-conflict + + - repo: https://github.com/psf/black + rev: 23.7.0 + hooks: + - id: black + language_version: python3 + args: [--line-length=88] + + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + args: [--profile=black, --line-length=88] + + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.1.6 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.5.1 + hooks: + - id: mypy + additional_dependencies: [types-requests] + exclude: ^(tests/|examples/) diff --git a/lint.py b/lint.py new file mode 100644 index 0000000..2bbb8b7 --- /dev/null +++ b/lint.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +""" +Lint runner script for pytrickle project. +Runs all configured linting tools with proper 4-space indentation and POSIX line endings. +""" + +import subprocess +import sys +from pathlib import Path + + +def run_command(cmd: list[str], description: str) -> bool: + """Run a command and return True if successful.""" + print(f"\nšŸ” Running {description}...") + try: + result = subprocess.run(cmd, check=True, capture_output=True, text=True) + print(f"āœ… {description} passed") + if result.stdout: + print(result.stdout) + return True + except subprocess.CalledProcessError as e: + print(f"āŒ {description} failed") + if e.stdout: + print("STDOUT:", e.stdout) + if e.stderr: + print("STDERR:", e.stderr) + return False + + +def main(): + """Run all linting tools.""" + project_root = Path(__file__).parent + python_files = ["pytrickle", "tests", "examples"] + + # Change to project root + import os + os.chdir(project_root) + + success = True + + # Run Black formatter + success &= run_command( + ["black", "--check", "--diff"] + python_files, + "Black code formatting check" + ) + + # Run isort import sorting + success &= run_command( + ["isort", "--check-only", "--diff"] + python_files, + "isort import sorting check" + ) + + # Run Ruff linter + success &= run_command( + ["ruff", "check"] + python_files, + "Ruff linting" + ) + + # Run Ruff formatter + success &= run_command( + ["ruff", "format", "--check"] + python_files, + "Ruff formatting check" + ) + + # Run MyPy type checking + success &= run_command( + ["mypy"] + python_files, + "MyPy type checking" + ) + + if success: + print("\nšŸŽ‰ All linting checks passed!") + return 0 + else: + print("\nšŸ’„ Some linting checks failed!") + return 1 + + +if __name__ == "__main__": + sys.exit(main())