|
| 1 | +# ADR-001b: Python linting and formatting 🧾 |
| 2 | + |
| 3 | +> | | | |
| 4 | +> | ------------ | ----------------------------------------------- | |
| 5 | +> | Date | `2026-02-08` when the decision was last updated | |
| 6 | +> | Status | `Accepted` | |
| 7 | +> | Significance | `Quality attributes, Delivery & build` | |
| 8 | +
|
| 9 | +--- |
| 10 | + |
| 11 | +- [ADR-001b: Python linting and formatting 🧾](#adr-001b-python-linting-and-formatting-) |
| 12 | + - [Context 🧭](#context-) |
| 13 | + - [Decision ✅](#decision-) |
| 14 | + - [Assumptions 🧩](#assumptions-) |
| 15 | + - [Drivers 🎯](#drivers-) |
| 16 | + - [Options 🔀](#options-) |
| 17 | + - [Option A: Ruff (Selected) ✅](#option-a-ruff-selected-) |
| 18 | + - [Option B: Black + isort + Flake8](#option-b-black--isort--flake8) |
| 19 | + - [Option C: Pylint + Black](#option-c-pylint--black) |
| 20 | + - [Option D: autopep8 + pycodestyle](#option-d-autopep8--pycodestyle) |
| 21 | + - [Option E: YAPF + Flake8](#option-e-yapf--flake8) |
| 22 | + - [Outcome 🏁](#outcome-) |
| 23 | + - [Rationale 🧠](#rationale-) |
| 24 | + - [Consequences ⚖️](#consequences-️) |
| 25 | + - [Compliance 📏](#compliance-) |
| 26 | + - [Notes 🔗](#notes-) |
| 27 | + - [Actions ✅](#actions-) |
| 28 | + - [Tags 🏷️](#tags-️) |
| 29 | + |
| 30 | +## Context 🧭 |
| 31 | + |
| 32 | +The Python tech stack needs a single, fast, consistent approach for linting and formatting that can run in CI and locally without heavy configuration. |
| 33 | + |
| 34 | +## Decision ✅ |
| 35 | + |
| 36 | +### Assumptions 🧩 |
| 37 | + |
| 38 | +- Python 3.14.3 is the baseline runtime. |
| 39 | +- Formatting must be deterministic and consistent across the codebase. |
| 40 | +- Linting should catch correctness and style issues with low noise. |
| 41 | + |
| 42 | +### Drivers 🎯 |
| 43 | + |
| 44 | +- One-tool workflow where possible |
| 45 | +- Fast execution for local and CI use |
| 46 | +- Deterministic formatting |
| 47 | +- High signal linting |
| 48 | +- Active maintenance and ecosystem support |
| 49 | + |
| 50 | +### Options 🔀 |
| 51 | + |
| 52 | +#### Option A: Ruff (Selected) ✅ |
| 53 | + |
| 54 | +Use [`ruff`](https://github.com/astral-sh/ruff) for both linting and formatting. |
| 55 | + |
| 56 | +| Criteria | Score/Notes | |
| 57 | +| ---------------------- | ------------------------------- | |
| 58 | +| Formatting consistency | ⭐⭐⭐ Built-in formatter | |
| 59 | +| Lint coverage | ⭐⭐⭐ Broad checks in one tool | |
| 60 | +| Performance | ⭐⭐⭐ Very fast | |
| 61 | +| Configuration overhead | ⭐⭐ Simple unified config | |
| 62 | +| Ecosystem support | ⭐⭐⭐ Strong and growing | |
| 63 | +| Effort | S | |
| 64 | + |
| 65 | +#### Option B: Black + isort + Flake8 |
| 66 | + |
| 67 | +Use [`Black`](https://github.com/psf/black), [`isort`](https://github.com/PyCQA/isort), and [`Flake8`](https://github.com/PyCQA/flake8) together. |
| 68 | + |
| 69 | +| Criteria | Score/Notes | |
| 70 | +| ---------------------- | --------------------------------- | |
| 71 | +| Formatting consistency | ⭐⭐⭐ Black is stable | |
| 72 | +| Lint coverage | ⭐⭐ Needs multiple plugins | |
| 73 | +| Performance | ⭐⭐ Multiple tools add overhead | |
| 74 | +| Configuration overhead | ⭐⭐ Many configs to keep in sync | |
| 75 | +| Ecosystem support | ⭐⭐⭐ Mature and stable | |
| 76 | +| Effort | M | |
| 77 | + |
| 78 | +**Why not chosen**: Good quality but slower and more complex than a single tool. |
| 79 | + |
| 80 | +#### Option C: Pylint + Black |
| 81 | + |
| 82 | +Use [`Pylint`](https://github.com/pylint-dev/pylint) for linting and Black for formatting. |
| 83 | + |
| 84 | +| Criteria | Score/Notes | |
| 85 | +| ---------------------- | ----------------------------------- | |
| 86 | +| Formatting consistency | ⭐⭐⭐ Black is stable | |
| 87 | +| Lint coverage | ⭐⭐⭐ Deep checks but can be noisy | |
| 88 | +| Performance | ⭐⭐ Slower on large codebases | |
| 89 | +| Configuration overhead | ⭐⭐ Significant tuning | |
| 90 | +| Ecosystem support | ⭐⭐ Stable but heavier | |
| 91 | +| Effort | M | |
| 92 | + |
| 93 | +**Why not chosen**: Higher noise and slower than Ruff for the default stack. |
| 94 | + |
| 95 | +#### Option D: autopep8 + pycodestyle |
| 96 | + |
| 97 | +Use [`autopep8`](https://github.com/hhatto/autopep8) and [`pycodestyle`](https://github.com/PyCQA/pycodestyle). |
| 98 | + |
| 99 | +| Criteria | Score/Notes | |
| 100 | +| ---------------------- | ------------------------------------- | |
| 101 | +| Formatting consistency | ⭐⭐ Less strict and less predictable | |
| 102 | +| Lint coverage | ⭐ Low, basic checks | |
| 103 | +| Performance | ⭐⭐⭐ Fast | |
| 104 | +| Configuration overhead | ⭐⭐ Moderate | |
| 105 | +| Ecosystem support | ⭐⭐ Stable but older stack | |
| 106 | +| Effort | M | |
| 107 | + |
| 108 | +**Why not chosen**: Weaker lint coverage and less deterministic formatting. |
| 109 | + |
| 110 | +#### Option E: YAPF + Flake8 |
| 111 | + |
| 112 | +Use [`YAPF`](https://github.com/google/yapf) with Flake8. |
| 113 | + |
| 114 | +| Criteria | Score/Notes | |
| 115 | +| ---------------------- | -------------------------------- | |
| 116 | +| Formatting consistency | ⭐⭐ Configurable but subjective | |
| 117 | +| Lint coverage | ⭐⭐ Depends on Flake8 plugins | |
| 118 | +| Performance | ⭐⭐ Reasonable | |
| 119 | +| Configuration overhead | ⭐⭐ More tuning required | |
| 120 | +| Ecosystem support | ⭐⭐ Maintained but less common | |
| 121 | +| Effort | M | |
| 122 | + |
| 123 | +**Why not chosen**: More configuration with no clear benefit over Ruff. |
| 124 | + |
| 125 | +### Outcome 🏁 |
| 126 | + |
| 127 | +Adopt `ruff` for both linting and formatting. This decision is reversible if tooling changes or if ruff ceases to meet coverage needs. |
| 128 | + |
| 129 | +### Rationale 🧠 |
| 130 | + |
| 131 | +Ruff provides a fast, single-tool workflow with strong lint coverage and a built-in formatter. It keeps the toolchain simple and consistent. |
| 132 | + |
| 133 | +## Consequences ⚖️ |
| 134 | + |
| 135 | +- Projects should configure Ruff in `pyproject.toml`. |
| 136 | +- Additional linters require explicit justification. |
| 137 | + |
| 138 | +## Compliance 📏 |
| 139 | + |
| 140 | +- `uv run ruff format --check .` produces no changes. |
| 141 | +- `uv run ruff check .` succeeds in CI. |
| 142 | + |
| 143 | +## Notes 🔗 |
| 144 | + |
| 145 | +- Tech Radar: `./Tech_Radar.md` |
| 146 | + |
| 147 | +## Actions ✅ |
| 148 | + |
| 149 | +- [x] Copilot, 2026-02-08, record the linting and formatting decision |
| 150 | + |
| 151 | +## Tags 🏷️ |
| 152 | + |
| 153 | +`#quality #consistency #maintainability` |
0 commit comments