README.md (2122B)
1 # 05 — Lint & Fix on Pre-Commit 2 3 Run lint checks automatically before every `git commit` using Jaypore CI. 4 This example targets a Django project (Python-heavy) but includes stubs for 5 Go and JavaScript files in the same repo. 6 7 ## What it does 8 9 | Language | Tool | Action | 10 |------------|----------------------------|-------------------------------------| 11 | Python | `py_compile`, `black` | Syntax-check all `.py` files; verify formatting | 12 | Go | `gofmt` | List unformatted `.go` files | 13 | JavaScript | `eslint --fix` | Auto-fix and report remaining errors | 14 15 Results are saved to `$JCI_OUTPUT_DIR/lint-results.txt` so Jaypore CI can 16 render them in its dashboard. 17 18 ## Setup 19 20 ### 1. Copy the CI script into your project 21 22 ```bash 23 mkdir -p .jci 24 cp .jci/run.sh /path/to/your/project/.jci/run.sh 25 ``` 26 27 ### 2. Install the pre-commit hook 28 29 ```bash 30 ./install-hook.sh # uses the current repo 31 # or 32 ./install-hook.sh /path/to/your/project 33 ``` 34 35 This creates `.git/hooks/pre-commit` which calls `git jci run` before each 36 commit. If any lint check fails the commit is blocked. 37 38 ### 3. Commit as usual 39 40 ```bash 41 git add . 42 git commit -m "my changes" 43 # Jaypore CI runs automatically; commit proceeds only if all checks pass. 44 ``` 45 46 ## How it works 47 48 1. Git fires the **pre-commit** hook before creating a commit object. 49 2. The hook runs `git jci run`, which executes `.jci/run.sh`. 50 3. `run.sh` walks through Python, Go, and JS checks, recording output to 51 `lint-results.txt`. 52 4. If **any** check fails, `run.sh` exits non-zero → the hook exits non-zero 53 → Git aborts the commit. 54 5. Fix the reported issues, `git add` the fixes, and commit again. 55 56 ## Skipping the hook 57 58 In an emergency you can bypass the pre-commit hook: 59 60 ```bash 61 git commit --no-verify -m "skip lint this time" 62 ``` 63 64 ## Files 65 66 ``` 67 05-lint-fix-precommit/ 68 ├── .jci/ 69 │ └── run.sh # Jaypore CI script — lint checks 70 ├── install-hook.sh # Helper to install the git hook 71 └── README.md # This file 72 ```