Skip to content

Commit 06718e9

Browse files
committed
docs: rewrite CONTRIBUTING.md following chezroot style
- Add comprehensive TLDR section with key requirements - Expand development environment setup with detailed prerequisites - Add coverage enforcement documentation (100% for business logic) - Include testing patterns and best practices - Document automation pipeline and CI workflows - Improve structure with clear sections and table of contents - Model after main-branch/chezroot contributing guide
1 parent 7e34a73 commit 06718e9

1 file changed

Lines changed: 217 additions & 91 deletions

File tree

CONTRIBUTING.md

Lines changed: 217 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,282 @@
11
# Contributing to MkDocs Snippet Lens
22

3-
Thank you for your interest in contributing to MkDocs Snippet Lens! We welcome
4-
contributions from the community.
3+
First, thank you for considering contributing to MkDocs Snippet Lens. This project is
4+
a community effort, and every contribution is valued.
55

6-
## Development Workflow
6+
This guide outlines the standards and procedures for contributing, from setting up your
7+
environment to submitting your changes. Please read it carefully to ensure your
8+
contributions can be merged smoothly.
79

8-
All changes to this project must follow this workflow:
10+
- [TLDR](#tldr)
11+
- [Code of Conduct](#code-of-conduct)
12+
- [Getting Started](#getting-started)
13+
- [Development Environment Setup](#development-environment-setup)
14+
- [Development Workflow](#development-workflow)
15+
- [Testing & Coverage](#testing--coverage)
16+
- [Submitting Changes](#submitting-changes)
17+
- [Automation Pipeline](#automation-pipeline)
918

10-
### 1. Work on a Feature Branch
19+
## TLDR
1120

12-
**Never commit directly to `main`.** All changes must be made on a feature branch:
21+
Here are the most important guidelines:
1322

14-
```bash
15-
git checkout main
16-
git pull origin main
17-
git checkout -b feature/your-feature-name
18-
```
23+
- **Prerequisites**: You must have Node.js (>= 20) and npm installed.
24+
- **One-Time Setup**: Run `npm ci` after cloning to install all development dependencies
25+
and Git hooks.
26+
- **Conventional Commits**: All commit messages must follow the Conventional Commits
27+
standard (e.g., `feat: ...`, `fix: ...`). A local Git hook will enforce this.
28+
- **Tests are Required**: All new features or bug fixes must include corresponding
29+
tests.
30+
- **Update Documentation**: Any change that impacts users (new features, settings, etc.)
31+
must be documented appropriately.
32+
- **Ensure CI passes locally**: Before submitting a pull request, run `npm run test:all`
33+
and ensure all checks (linting, testing, building) pass.
34+
- **Rebase Workflow**: Always work on a new branch. Your pull request must be rebased on
35+
the latest `main` branch before it will be merged with a fast-forward merge.
1936

20-
### 2. Make Your Changes
37+
## Code of Conduct
2138

22-
- Write clear, concise commit messages following
23-
[Conventional Commits](https://www.conventionalcommits.org/)
24-
- Ensure all tests pass: `npm run test:all`
25-
- Maintain 100% test coverage for business logic
26-
- Follow the existing code style (enforced by ESLint)
39+
This project and everyone participating in it is governed by our community standards.
40+
By participating, you are expected to uphold respectful and professional behavior.
2741

28-
### 3. Keep Your Branch Up to Date
42+
## Getting Started
2943

30-
Before creating a pull request, rebase your branch on the latest `main`:
44+
Before you begin, you'll need to fork and clone the repository.
3145

32-
```bash
33-
git checkout main
34-
git pull origin main
35-
git checkout your-feature-branch
36-
git rebase main
37-
```
46+
1. Fork the repository on GitHub.
3847

39-
Resolve any conflicts that arise during the rebase.
48+
2. Clone your fork to your local machine:
4049

41-
### 4. Submit a Pull Request
50+
```bash
51+
git clone https://github.com/YOUR_USERNAME/mkdocs-snippet-lens.git
52+
cd mkdocs-snippet-lens
53+
```
4254

43-
1. Push your feature branch to GitHub:
55+
3. Add the upstream remote to keep your fork in sync:
4456

4557
```bash
46-
git push origin feature/your-feature-name
58+
git remote add upstream https://github.com/main-branch/mkdocs-snippet-lens.git
4759
```
4860

49-
2. Create a pull request on GitHub from your feature branch to `main`
61+
## Development Environment Setup
5062

51-
3. Ensure all CI checks pass (linting, type checking, tests on all platforms)
63+
This project uses Node.js and TypeScript for the VS Code extension, with npm for
64+
dependency management and tooling.
5265

53-
4. Request a review from a maintainer
66+
### Prerequisites
5467

55-
### 5. Pull Request Requirements
68+
You must have the following tools installed on your local machine:
5669

57-
Your pull request **must**:
70+
- **Node.js**: Version 20.0.0 or newer.
71+
- **npm**: This is included with Node.js.
72+
- **Visual Studio Code**: For testing the extension.
5873

59-
- Pass all CI checks (linting, type checking, unit tests, integration tests)
60-
- Be reviewed and approved by at least one maintainer
61-
- Be rebased on the latest `main` branch (no merge commits)
62-
- Have a clean, linear commit history
74+
### Install Dependencies and Tooling
6375

64-
### 6. Merging
76+
Once you have the prerequisites, you can install all project dependencies and
77+
development tools by running:
6578

66-
Once approved, a maintainer will merge your PR using a **fast-forward merge**. This
67-
means:
79+
```bash
80+
npm ci
81+
```
6882

69-
- Your branch must be rebased on the latest `main`
70-
- No merge commits will be created
71-
- The commit history remains linear
83+
This command will:
7284

73-
If `main` has been updated since your last rebase, you'll need to rebase again before
74-
the PR can be merged.
85+
1. Install all Node.js dependencies from the `package-lock.json` file.
86+
2. Run the `prepare` script in `package.json`, which uses Husky to set up the
87+
`commit-msg` Git hook (`.husky/commit-msg`).
7588

76-
## Development Setup
89+
The development tools (`eslint`, `typescript`, `mocha`, `c8`) are managed via
90+
`package.json` and invoked with npm scripts. You do not need to install them globally.
7791

78-
### Prerequisites
92+
If you later pull changes that modify `package-lock.json`, re-run `npm ci` to keep
93+
local development tooling in sync.
7994

80-
- Node.js 20.x or later
81-
- npm 10.x or later
82-
- Visual Studio Code
95+
### Editor Setup (VS Code)
8396

84-
### Setup Steps
97+
For the best development experience, we recommend using VS Code with the following
98+
extensions:
8599

86-
1. Clone the repository:
100+
- **ESLint**: `dbaeumer.vscode-eslint`
101+
- **TypeScript and JavaScript Language Features**: Built-in
87102

88-
```bash
89-
git clone https://github.com/main-branch/mkdocs-snippet-lens.git
90-
cd mkdocs-snippet-lens
91-
```
103+
This repository includes a `.vscode/settings.json` file that will automatically
104+
configure these extensions to use the project's rules.
92105

93-
2. Install dependencies:
106+
## Development Workflow
94107

95-
```bash
96-
npm ci
97-
```
108+
The `package.json` scripts are the single source of truth for all common development
109+
tasks.
98110

99-
3. Build the extension:
111+
### Main Command
100112

101-
```bash
102-
npm run compile
103-
```
113+
Before submitting a pull request, you must run the full test suite locally:
104114

105-
4. Run tests:
115+
```bash
116+
npm run test:all
117+
```
106118

107-
```bash
108-
npm run test:all
109-
```
119+
This command runs unit tests and integration tests on your local machine. This is
120+
similar to what our GitHub workflow uses.
110121

111-
### Available Scripts
122+
### Other Useful Commands
112123

113-
- `npm run lint` - Run ESLint
124+
- `npm run lint` - Run ESLint to check code style
114125
- `npm run check-types` - Run TypeScript type checking
115126
- `npm run test:unit` - Run unit tests with coverage
116-
- `npm run test:integration` - Run integration tests
117-
- `npm run test:all` - Run all tests
127+
- `npm run test:integration` - Run integration tests in VS Code
118128
- `npm run compile` - Build the extension
119129
- `npm run watch` - Watch mode for development
120130

121-
## Testing
131+
## Testing & Coverage
122132

123-
### Unit Tests
133+
This project enforces 100% statement coverage on business logic modules to maintain
134+
code quality and ensure all code paths are tested.
124135

125-
Unit tests are located in `src/test/unit/` and test individual modules in isolation.
126-
All business logic must have 100% test coverage.
136+
### Coverage Requirement
127137

128-
### Integration Tests
138+
All contributions must maintain 100% statement coverage for business logic modules. The
139+
CI pipeline will automatically fail if coverage drops below this threshold.
129140

130-
Integration tests are in `src/test/integration/` and test the extension running in
131-
VS Code.
141+
Note: VS Code integration modules (`extension.ts`, `snippetLinkProvider.ts`,
142+
`snippetHoverProvider.ts`, `previewManager.ts`, `diagnosticManager.ts`) are excluded
143+
from coverage requirements as they are tested via integration tests.
132144

133145
### Running Tests Locally
134146

135147
```bash
136-
# Unit tests only
148+
# Run unit tests with coverage
137149
npm run test:unit
138150

139-
# Integration tests only
151+
# Run integration tests
140152
npm run test:integration
141153

142-
# All tests
154+
# Run all tests
143155
npm run test:all
144156
```
145157

146-
## Code Style
158+
### Understanding Coverage
159+
160+
The coverage tooling measures statement coverage:
161+
162+
- **Statement coverage** = whether each executable statement was run by tests
163+
164+
The coverage report shows:
165+
166+
- Green = covered by tests
167+
- Red = NOT covered (needs tests added)
168+
- Gray = not executable (comments, declarations)
169+
170+
### Adding Tests for New Code
171+
172+
When adding new features or fixing bugs:
173+
174+
1. Write tests that cover all new code paths
175+
2. Run `npm run test:unit` to verify 100% coverage on business logic
176+
3. If coverage is below 100%, review the coverage report to identify uncovered lines
177+
4. Add tests for the uncovered statements
178+
179+
### Common Patterns for Testability
180+
181+
The codebase follows these patterns to enable testing:
182+
183+
- **Separate business logic from VS Code integration**: Business logic modules are in
184+
pure TypeScript functions that can be tested in isolation.
185+
- **Integration tests for VS Code features**: Features that require VS Code APIs are
186+
tested via integration tests that run in a real VS Code environment.
187+
188+
Example:
189+
190+
```typescript
191+
// Business logic (100% coverage required)
192+
export function createDiagnosticInfos(
193+
locations: SnippetLocation[],
194+
resolver: (path: string) => string | null
195+
): DiagnosticInfo[] {
196+
// Pure function - easily testable
197+
}
198+
199+
// VS Code integration (integration tests)
200+
export class DiagnosticManager {
201+
updateDiagnostics(document: vscode.TextDocument): void {
202+
// Uses VS Code APIs - tested via integration
203+
}
204+
}
205+
```
206+
207+
### Viewing Coverage Reports
208+
209+
After running `npm run test:unit`, you can view the coverage report:
210+
211+
1. Open `coverage/lcov-report/index.html` in your browser
212+
2. Click on individual files to see line-by-line coverage
213+
214+
## Submitting Changes
215+
216+
### Commit Message Format
217+
218+
This project uses Conventional Commits. This format is strictly enforced by a Git hook
219+
and our CI pipeline.
220+
221+
For the full specification and examples, see the
222+
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) website.
223+
224+
After running `npm ci`, a `commit-msg` hook is installed that automatically lints your
225+
commit message with `commitlint`.
226+
227+
- Your commit message must follow the format: `<type>(<scope>): <subject>`.
228+
- Allowed types are: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`,
229+
`build`, `ci`, `chore`, `revert`.
230+
- For details on all rules, see `.commitlintrc.yml`.
231+
232+
Examples:
233+
234+
- `feat(diagnostics): add error highlighting for missing files`
235+
- `fix: correct path resolution on Windows`
236+
- `docs: update installation instructions in README`
237+
238+
### Pull Request Process
239+
240+
1. Create a feature branch from the `main` branch.
241+
242+
2. Make your changes.
243+
244+
**Important Contributor Requirements**
245+
246+
- **All new code requires tests**: Any new feature or bug fix must be accompanied by
247+
corresponding tests.
248+
- **Documentation must be updated**: Any change that impacts user behavior (new
249+
commands, settings, etc.) must be documented in the `README.md`.
250+
251+
3. Ensure your code passes all local checks by running `npm run test:all`.
252+
253+
4. Rebase your branch on the latest `main`:
254+
255+
```bash
256+
git fetch upstream
257+
git rebase upstream/main
258+
```
259+
260+
If you encounter conflicts during the rebase, resolve them and continue:
261+
262+
```bash
263+
git add <files>
264+
git rebase --continue
265+
```
266+
267+
5. Push your branch and open a pull request against `main-branch/mkdocs-snippet-lens:main`.
268+
269+
6. Ensure all CI checks on the pull request pass.
270+
271+
## Automation Pipeline
147272

148-
- Follow the existing code patterns
149-
- Use TypeScript strict mode
150-
- Document public APIs with JSDoc comments
151-
- Keep functions small and focused
152-
- Separate VS Code integration from business logic
273+
We use a set of GitHub Actions to automate linting, testing, and quality checks.
153274

154-
## Questions?
275+
- **Continuous Integration**: On every pull request,
276+
`.github/workflows/continuous-integration.yml` runs linting, type checking, unit
277+
tests, integration tests (on Ubuntu, macOS, and Windows), and builds the extension.
278+
- **Conventional Commits**: Commit messages are validated during CI to ensure they
279+
follow the Conventional Commits standard.
280+
- **100% Coverage**: The CI pipeline enforces 100% statement coverage on business logic
281+
modules.
155282

156-
If you have questions about contributing, please open an issue for discussion.

0 commit comments

Comments
 (0)