Skip to content

Commit b73f92a

Browse files
committed
Add pre-commit instructions
1 parent 86b49f9 commit b73f92a

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

CONTRIBUTING.MD

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,68 @@ based on the labels of the pull requests merged into the `main` branch.
5656

5757
See the [release-drafter configuration](./.github/release-drafter.yml) for more details.
5858

59+
## Pre-commit Hooks
60+
61+
This repository uses [pre-commit](https://pre-commit.com/) to automatically format and validate code before commits.
62+
63+
### What Gets Checked
64+
65+
The following hooks run automatically on staged files:
66+
67+
- **dotnet format** - Formats C# and F# files
68+
- **prettier** - Formats TypeScript, JavaScript, CSS, and other files in `src/Elastic.Documentation.Site/`
69+
- **TypeScript** - Type checks TypeScript files with `tsc --noEmit`
70+
- **ESLint** - Lints and fixes JavaScript/TypeScript files
71+
72+
### Installation
73+
74+
#### Install pre-commit
75+
76+
```bash
77+
# macOS/Linux
78+
pip install pre-commit
79+
80+
# macOS with Homebrew
81+
brew install pre-commit
82+
83+
# Windows
84+
pip install pre-commit
85+
```
86+
87+
#### Install the hooks
88+
89+
```bash
90+
pre-commit install
91+
```
92+
93+
### Usage
94+
95+
Once installed, hooks run automatically when you commit:
96+
97+
```bash
98+
git add .
99+
git commit -m "your message"
100+
```
101+
102+
**Note:** If hooks modify files (prettier, eslint, dotnet format), the commit will fail so you can review the changes. Simply run the commit command again to commit the formatted code.
103+
104+
#### Manual Execution
105+
106+
Run hooks on all files:
107+
```bash
108+
pre-commit run --all-files
109+
```
110+
111+
Run a specific hook:
112+
```bash
113+
pre-commit run prettier --all-files
114+
pre-commit run dotnet-format --all-files
115+
```
116+
117+
#### CI Integration
118+
119+
Pre-commit hooks also run in GitHub Actions on all pull requests to ensure code quality and consistency.
120+
59121
## Creating a New Release
60122

61123
To create a new release trigger the [release](https://github.com/elastic/docs-builder/actions/workflows/release.yml) workflow on the `main` branch.

0 commit comments

Comments
 (0)