Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"**/*.{js,jsx,ts,tsx,json,md}": ["prettier --write"],
"**/*.js": ["jest --findRelatedTests --passWithNoTests"]
"**/*.js": ["jest --findRelatedTests --passWithNoTests"],
"tools/spectral/ipa/**/*.yaml": ["node tools/spectral/ipa/scripts/generateRulesetReadme.js"],
"**/*.go": ["./tools/cli/precommit.sh"]
}
24 changes: 21 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Node.js v20 or later
- npm v8 or later
- Git
- Go 1.21 or later (for CLI development)

### Installation

Expand All @@ -21,11 +22,17 @@
npm install
```

3. Set up Git hooks (optional):
3. Set up Git hooks (recommended):
```bash
npm run precommit
```

4. If working on the Go CLI, set up the Go environment:
```bash
cd tools/cli
make setup
```

This will install Husky, which manages Git hooks for the project. The hooks ensure code quality by automatically running various checks before commits.

## Development Workflow
Expand All @@ -34,17 +41,28 @@ This will install Husky, which manages Git hooks for the project. The hooks ensu

This project uses the following Git hooks:

- **pre-commit**: Automatically formats your code using Prettier and runs tests for staged JavaScript files to ensure code quality before each commit.
- **pre-commit**:
- Automatically formats your code using Prettier and runs tests for staged JavaScript files
- If you get the message `hint: The '.husky/pre-commit' hook was ignored because it's not set as executable.` during the commit, you can run `chmod ug+x .husky/*` to make it executable.
- For Go files, runs formatting, linting, and tests using the project's Makefile

### Available Scripts

#### JavaScript/Node.js
- `npm run format` - Format all files with Prettier
- `npm run format-check` - Check formatting without modifying files
- `npm run lint-js` - Lint JavaScript files
- `npm run test` - Run all tests

#### IPA specific targets

- `npm run gen-ipa-docs` - Generate IPA ruleset documentation (see `./tools` folder for more information)
- `npm run ipa-validation` - Run OpenAPI validation with Spectral

#### Go OpenAPI CLI (internal)
When working in the `tools/cli` directory:
- `make fmt` - Format Go code
- `make lint` - Run golangci-lint
- `make unit-test` - Run Go unit tests
- `make e2e-test` - Run end-to-end tests
- `make build` - Build the CLI binary
- `make gen-docs` - Generate CLI documentation
3 changes: 3 additions & 0 deletions tools/cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ gen-mocks: ## Generate mocks
@echo "==> Generating mocks"
go generate ./internal...

.PHONY: pre-commit
pre-commit: fmt lint unit-test ## Run pre-commit checks

.PHONY: help
.DEFAULT_GOAL := help
help:
Expand Down
11 changes: 11 additions & 0 deletions tools/cli/precommit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e

# Get the root directory of the project
ROOT_DIR=$(git rev-parse --show-toplevel)

pushd "$ROOT_DIR/tools/cli"
make pre-commit
popd

exit 0
Loading