Skip to content

Commit 4d08023

Browse files
authored
Merge pull request #93 from lightspeedwp/claude/config-docs-template-016SXALgwqRUX9zDYQMAuevf
Create documentation template for tool configuration
2 parents 6a4650e + fa978c5 commit 4d08023

File tree

6 files changed

+322
-66
lines changed

6 files changed

+322
-66
lines changed

docs/HUSKY-PRECOMMITS.md

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,106 @@
1-
# Husky Pre-Commit Hooks Documentation
1+
---
2+
title: "Husky Pre-commit Hooks"
3+
description: "Using Husky to enforce quality gates (linting/tests) before commits"
4+
last_updated: "2025-11-14"
5+
version: "1.0"
6+
maintainers: ["LightSpeed DevOps"]
7+
tags: ["husky", "pre-commit", "automation", "linting"]
8+
---
29

3-
This document explains the Husky pre-commit setup, usage, and best practices for this repository. It is designed to be used alongside [LINTING.md](./LINTING.md), which details the linting tools and configuration.
10+
# Husky Pre-commit Hooks
411

5-
---
12+
**`docs/HUSKY-PRECOMMITS.md`***Pre-commit Hook as Quality Gate*
613

7-
## Linting & Quality Checks
14+
We use **Husky** to run linting and formatting checks locally before code is committed, serving as a "first line" quality gate. This ensures that by the time code reaches CI, it has already passed basic standards.
815

9-
Husky is tightly integrated with our linting workflow. For a full list of linting tools, configuration files, and what is checked before each commit, see [LINTING.md](./LINTING.md). This ensures that all code meets our standards before it is committed.
16+
## Status and Rationale
1017

11-
---
18+
**Status:** *Implemented in develop (pending merge to main).* Previously, Husky was not set up in this repo, meaning developers could commit code that failed our style/test checks. We've now added a Husky *pre-commit* hook to mirror the checks that run in CI, closing this gap.
19+
20+
**Why Husky:** Running checks locally speeds up feedback. It prevents "easy" issues (like code style or obvious test failures) from ever reaching the repo, which reduces CI failures and iteration time. This aligns with our goal that *"files are linted properly and tests pass"* before pushing.
21+
22+
## Installation
1223

13-
## Overview
24+
Husky is managed as a dev dependency. To install and enable Husky in a fresh clone:
1425

15-
Husky is used to enforce code quality and consistency by running automated checks (such as linting and tests) before code is committed. This helps prevent errors and maintain standards across the codebase.
26+
1. After running `npm install` (or `npm ci`), activate Husky hooks:
1627

17-
## .husky Folder Structure
28+
```bash
29+
npx husky install
30+
```
31+
32+
This installs Git hooks into the local repo's `.husky/` directory (already present in source).
33+
34+
2. Verify that a `.husky/pre-commit` file exists with our hook. It should have been created in the repo (or by the install command).
1835

19-
- `.husky/` — Contains all Husky hook scripts
20-
- `pre-commit` — Main pre-commit hook script (runs linting, tests, etc.)
21-
- `commit-msg` — Validates commit message format (if present)
22-
- Other hooks as needed (e.g., `pre-push`)
36+
If Husky isn't working, ensure Git isn't bypassing hooks (no `--no-verify` flag used) and that you have the correct Node version. We specify Node version in `.nvmrc` to avoid incompatibilities (our CI uses the same Node version).
2337

24-
## How Pre-Commit Works
38+
## Pre-commit Hook Behavior
2539

26-
When you run `git commit`, Husky automatically executes the scripts in `.husky/pre-commit` before the commit is finalized. If any check fails, the commit is aborted.
40+
Our pre-commit hook is defined in **`.husky/pre-commit`**. It runs our formatting and linting checks before allowing a commit. In summary, it will:
2741

28-
## Bypassing Pre-Commit Hooks
42+
- **Format code** (auto-fix) by running **`npm run format`**.
43+
- **Run linters and tests** by running **`npm run check`** (a composite script that runs all linters and unit tests).
2944

30-
To bypass Husky pre-commit hooks (not recommended except for emergencies):
45+
If *either* of those steps fails, the commit is aborted. You must fix the issues and try again. This prevents committing code that would fail CI.
3146

32-
```sh
33-
git commit --no-verify
47+
Below is the content of our `.husky/pre-commit` file for reference:
48+
49+
```bash
50+
#!/bin/sh
51+
. "$(dirname "$0")/_/husky.sh"
52+
53+
npm run format && npm run check
3454
```
3555

36-
> **Note:** Use this only if you have a valid reason. All skipped checks must be run manually before pushing.
56+
This uses Husky's shell script shim and then runs our tasks. The `&&` ensures that if formatting fails or leaves changes, or if any check fails, the process halts with a non-zero exit (blocking the commit).
3757

38-
## Suppression Storage & Management
58+
## Adding Husky to an Existing Clone
3959

40-
- Husky does not store suppressions by default. If you bypass a hook, it is not recorded.
41-
- If you want to re-enable hooks, simply commit as normal (without `--no-verify`).
42-
- To update or remove a hook, edit or delete the relevant script in `.husky/`.
60+
If you already have the repo and just pulled the updated config, run `npm install` (to get Husky) and then `npx husky install` to set up the hooks. This is a one-time step per clone. After that, Git will trigger the hook on commits automatically.
4361

44-
## Recommended Commands
62+
## Ignoring Specific Files or Bypassing
4563

46-
- **Install Husky hooks:**
64+
Our goal is to run the hook on all source changes. However, large binary files or documentation-only changes shouldn't block a commit on lint rules:
4765

48-
```sh
49-
npx husky install
66+
- Husky will only lint the files you're committing (through our `npm run ...` scripts configuration). For instance, if you edit only Markdown, JS lint won't run, etc.
67+
- If absolutely necessary (e.g. an urgent hotfix), you can bypass hooks with `git commit --no-verify`. **Use this sparingly.** Bypassing means CI will catch any issues later.
5068

51-
```
69+
We intentionally do not run lengthy end-to-end tests on pre-commit (those run in CI), to keep commits fast. The pre-commit focuses on quick checks (formatting, linters, unit tests). This strikes a balance between safety and speed.
5270

53-
- **Add a new hook:**
71+
## CI Integration
5472

55-
```sh
56-
npx husky add .husky/pre-commit "npm run lint:js && npm run lint:css && npm run lint:md && npm test"
73+
The pre-commit hook runs the same `npm run check` that CI does. In our GitHub Actions CI, we also execute the full test suite on push. The idea is "fail fast, locally":
5774

58-
```
75+
- By the time CI runs, code should already be formatted and pass linting. CI then mainly validates integration (and runs heavier tests).
76+
- If a contributor bypasses Husky (or Husky wasn't installed), the CI will still fail on the same `npm run check` script in our workflow, acting as a safety net.
5977

60-
- **Bypass hooks:**
78+
Having duplicate checks may seem redundant, but it's intentional. It virtually eliminates trivial CI failures (saving time) and acts as a double-insurance policy.
6179

62-
```sh
63-
git commit --no-verify
64-
```
80+
## Setup Commands (for reference)
6581

66-
## Getting Started
82+
For maintainers, these were the steps used to set up Husky in this repo:
6783

68-
1. Run `npm install` to install dependencies (including Husky).
69-
2. Run `npx husky install` to set up hooks (usually done automatically on install).
70-
3. Commit as usual — Husky will run checks before each commit.
84+
```bash
85+
npm install --save-dev husky # Add Husky to devDependencies
86+
npx husky install # Install Git hooks (creates .husky/ folder)
87+
npx husky add .husky/pre-commit "npm run format && npm run check"
88+
```
7189

72-
## Best Practices
90+
This added the pre-commit file with the content shown above. Our `package.json` already had the necessary `format` and `check` scripts defined (mapping to Prettier/ESLint and our test runner).
7391

74-
- Do not bypass hooks unless absolutely necessary.
75-
- Keep hook scripts up to date with project standards.
76-
- Review and update hooks as new linting or test scripts are added.
77-
- See [docs/LINTING.md](./LINTING.md) for details on what is checked by each hook.
92+
*(No changes are needed to developers' workflows aside from running `npm install` and having Node per `.nvmrc`. Commits are now gated, improving code quality upstream.)*
7893

7994
## Related Files & Further Reading
8095

8196
- [docs/LINTING.md](./LINTING.md) — Linting tools and configuration
82-
- [docs/HUSKY-LINITING-TASKS.md](./HUSKY-LINITING-TASKS.md) — Task list for Husky and linting documentation
97+
- [docs/METRICS.md](./METRICS.md) — Metrics and telemetry
98+
- [docs/config/workflow-husky.md](./config/workflow-husky.md) — Detailed Husky configuration
8399
- [package.json](../package.json) — NPM scripts run by hooks
84-
- [.husky/](../../.husky/) — Actual hook scripts
100+
- [.husky/](../.husky/) — Actual hook scripts
85101

86102
---
87103

88-
### Last updated
104+
### Last Updated
89105

90-
24 October 2025
106+
2025-11-14

docs/METRICS.md

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,75 @@
1+
---
2+
title: "Metrics & Telemetry"
3+
description: "Defining key quality metrics and our telemetry policy"
4+
last_updated: "2025-11-14"
5+
version: "1.0"
6+
maintainers: ["LightSpeed Engineering Ops"]
7+
tags: ["metrics", "telemetry", "CI", "analytics"]
8+
---
9+
110
# Metrics & Telemetry
211

3-
- **What we track:** CI failure mix, PR time-to-merge, non-semantic diff ratio, docs↔scripts parity errors, schema test coverage, lint rule churn.
4-
- **How:** Weekly workflow `ci-metrics.yml``scripts/gather-metrics.js`.
5-
- **Telemetry:** No local collection by default; any local telemetry is opt-in and documented.
12+
**`docs/METRICS.md`***Metrics & Telemetry Definition*
13+
14+
To continuously improve our processes, we track certain **development metrics**. These help us quantitatively verify that our community health files and automations are delivering value. Below we define what we measure (and what we **don't** measure):
15+
16+
## Key Metrics Tracked
17+
18+
- **CI Failure Breakdown:** We categorize CI failures by type. For example, how many pipeline failures are due to formatting/lint issues vs. test failures vs. other causes. This helps identify if our pre-commit checks are effective (in an ideal state, CI failures from linting should approach zero).
19+
- **Pre-commit vs CI Catch Rate:** We monitor how often our Husky pre-commit hook prevents an issue *before* CI. If something slips to CI that Husky should catch (e.g. a lint error), that indicates a gap. Our goal is a high pre-commit "pass rate" – meaning most commits meet quality standards, and CI failures are rare and usually for more complex issues.
20+
- **PR Cycle Time:** The average time from PR open to merge. Since our automation (like issue templates, labeling, and pre-commit checks) aims to reduce friction, a decreasing PR cycle time (or time-to-merge) is a positive signal. We'll track median and 90th percentile times.
21+
- **Non-Functional Churn (Formatting Noise):** We measure what percentage of lines changed in a PR are purely formatting/styling (non-functional changes). A low percentage means developers have fewer "noise" changes – indicating that auto-formatting is being applied consistently. High values might mean folks need to run `npm run format` more often.
22+
- **Lint Rule "Churn":** Each quarter, we'll review how many lint rules were added, removed, or disabled. Frequent rule changes may indicate instability in standards; our goal is a fairly stable lint baseline (with planned updates, not constant toggling).
23+
24+
Each metric is collected via scripts or the GitHub API and aggregated in a periodic report.
25+
26+
## Collection Method
27+
28+
A GitHub Action workflow (see **ci-metrics.yml** in workflows) runs on a schedule (weekly). It uses a custom Node script to gather data:
29+
30+
- For CI failures: It pulls recent workflow runs and tallies failure reasons (by parsing logs or using GitHub's run conclusion and job names).
31+
- For PR cycle time: It queries recent closed PRs' open-to-merge intervals.
32+
- For formatting churn: It scans merged PR diffs to calculate the ratio of whitespace/style-only changes (this requires parsing diffs; we approximate via known patterns).
33+
- For lint rule churn: It looks at our ESLint/Stylelint config changes or count of `eslint-disable` comments added in the codebase over time.
34+
35+
The results are output as a Markdown summary (and in the future, maybe as an issue or dashboard). **Owner: Engineering Ops** will review this report quarterly and identify any action items (e.g. an uptick in formatting noise might prompt a reminder to developers to run Prettier, or an adjustment in our tools).
36+
37+
## Sample Metrics Report (illustrative)
38+
39+
- **This Week's CI Failures:** 10 total – *6 from unit tests, 4 from linting.* (👍 lint issues down from 10 last week, indicating Husky is working.)
40+
- **Pre-commit Hook Effectiveness:** 95% of pushes had no CI lint errors (i.e. Husky caught issues locally). 5% of pushes had lint problems in CI *(likely Husky was skipped or a new rule was added)*.
41+
- **Median PR Cycle Time:** 2.1 days (from open to merge). *Down from ~3 days last quarter – possibly due to better issue templates and automated labeling.*
42+
- **Formatting Churn:** 8% of lines changed in PRs were non-functional (formatting or comments). *This is relatively low, suggesting developers are using the auto-formatting tools.*
43+
- **Lint Rule Churn:** 2 ESLint rules tweaked this quarter, 1 new Markdownlint rule added. *All were part of planned updates (see Changelog). No excessive rule thrash.*
44+
45+
These numbers will be tracked over time to spot trends.
46+
47+
## Telemetry Policy
48+
49+
**No personal telemetry is collected.** We do **not** track individual usage of editors or any keystroke data. Our focus is on repository-level metrics (as described above) and outcomes like CI results or PR durations.
50+
51+
- **Editor/IDE Telemetry:** We do not gather any data from user editors (e.g. we do *not* use VS Code or Copilot telemetry for this). While VS Code's MCP extension can provide some insights, we have chosen not to enable any tracking there by default.
52+
- **Optional Future Telemetry:** If we introduce a local tool to measure, for example, how often certain AI **instructions** are triggered or used, it will be strictly opt-in. We would clearly document how to enable it and what is collected, and it would never include sensitive or personally identifiable information.
53+
- **Data Handling:** Metrics collected by our scripts (as outlined in the **Collection Method** section) are aggregated and used internally to improve our tooling. They do not include contributor identities (we anonymize or focus on aggregates).
54+
- **Retention:** Metrics reports will be kept for trend analysis (likely in a `metrics/` directory or as issues). Raw data (e.g. API query results) is not stored long-term.
55+
56+
In summary, our approach to telemetry is *conservative*: we measure what we need to improve dev workflows and nothing more. We respect developer privacy and adhere to GitHub's policies (no tracking beyond our repo boundaries without consent).
57+
58+
## Outcome Tracking
59+
60+
Over time, these metrics will tell us if our efforts are paying off. For example, if we see PR times dropping and fewer CI fails, that validates the efficiency gains we expected. Conversely, any negative trends will prompt investigation (perhaps via a retro or by adding an agent to assist). Metrics give us a feedback loop to continuously adjust our automation and documentation.
61+
62+
*(The Metrics Action is set up but initial data will be sparse. The first full report is expected next quarter as we accumulate data.)*
63+
64+
## Related Files & Further Reading
65+
66+
- [docs/HUSKY-PRECOMMITS.md](./HUSKY-PRECOMMITS.md) — Pre-commit hooks setup
67+
- [docs/LINTING.md](./LINTING.md) — Linting strategy and tools
68+
- [.github/workflows/ci-metrics.yml](../.github/workflows/ci-metrics.yml) — Metrics collection workflow
69+
- [scripts/gather-metrics.js](../scripts/gather-metrics.js) — Metrics gathering script
70+
71+
---
72+
73+
### Last Updated
74+
75+
2025-11-14

docs/config/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,32 @@ All configuration documentation in this directory follows these standards:
111111
- **Troubleshooting**: Common issues and solutions
112112
- **Cross-References**: Links to related configurations and documentation
113113

114+
### Documentation Template
115+
116+
All configuration documentation follows the standardized template defined in:
117+
118+
- **[Tool Configuration Documentation Template](./tools.instructions.md)** - Blueprint for all config documentation
119+
120+
This template ensures consistency across all tool configuration files and includes:
121+
- Purpose and scope
122+
- When and how the tool runs
123+
- Exact scripts and commands
124+
- Severity and failure modes
125+
- Suppression and ignoring strategies
126+
- Version pinning and reproducibility
127+
- Maintenance ownership and review cadence
128+
- ROI vs cost analysis
129+
- References and further reading
130+
114131
## Contributing
115132

116133
When adding new configuration documentation:
117134

118-
1. Follow the template structure from existing files
135+
1. Follow the **[Tool Configuration Documentation Template](./tools.instructions.md)**
119136
2. Include practical examples and use cases
120137
3. Document integration with other tools
121138
4. Update this index file with the new configuration
122139
5. Cross-reference in related documentation
140+
6. Ensure all npm script references are validated by `scripts/verify-docs-commands.js`
123141

124142
See [Contributing Guidelines](../../CONTRIBUTING.md) for more details.

0 commit comments

Comments
 (0)