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
2 changes: 2 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
Expand All @@ -55,6 +56,7 @@ jobs:
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: '>=1.26.2'
cache: true
- name: Set up terraform
uses: hashicorp/setup-terraform@dfe3c3f87815947d99a8997f908cb6525fc44e9e # v4.0.1
- name: Run pylint and yapf, go vet
Expand Down
29 changes: 23 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,43 @@ The project uses `poetry` for Python dependency management, `pnpm` for website f
---

## Code Style & Formatting
Always format and lint your code before proposing changes. The repository provides a unified script to check for style violations:
Always format and lint your code before proposing changes. The repository provides a unified script to check for style violations with smart incremental checking:

- **Run Linters & Format Checks**:
- **Run Linters & Format Checks (Smart Auto-Detect)**:
By default, this automatically checks only the files and Go modules changed relative to `master` (or full repo if on clean master):
```bash
poetry run tools/lint_and_format.sh
```
*Note: This script only checks for violations and does not automatically format code.*
- **Run Full Check on Entire Repo**:
```bash
poetry run tools/lint_and_format.sh --all
```
- **Run on Staged Changes Only**:
```bash
poetry run tools/lint_and_format.sh --staged
```
- **Automatically Fix/Format Files**:
```bash
poetry run tools/lint_and_format.sh --fix
```
- **Lint Specific Files**:
```bash
poetry run tools/lint_and_format.sh osv/bug.py go/cmd/worker/main.go
```

### Python Standards
- Formatter: `yapf` (config: [`.style.yapf`](.style.yapf))
- Linter: `pylint` (config: [`.pylintrc`](.pylintrc))
- Formatter: `yapf` (config: [`.style.yapf`](.style.yapf), runs in parallel via `-p`)
- Linter: `pylint` (config: [`.pylintrc`](.pylintrc), runs in parallel via `-j 0`)
- **Formatting Command**: To automatically format Python files, run:
```bash
poetry run yapf -i <path_to_file>.py
```
*(Or run `poetry run tools/lint_and_format.sh --fix`)*
- **Rule**: When running Python scripts, always use `poetry run`.

### Go Standards
- Linter: `golangci-lint`
- **Running Go Linters**: Run `golangci-lint` using `go run` directly within the module directory (`go/`, `vulnfeeds/`, or `bindings/go/`):
- **Running Go Linters**: Run `golangci-lint` using `go run` directly within the module directory (`go/`, `vulnfeeds/`, or `bindings/go/`), or run `tools/lint_and_format.sh` which automatically maps changed files to the enclosing module:
```bash
cd go && go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0 run ./...
```
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ api-server-tests: ## Run Go API server integration tests
update-api-snapshots: ## Update API query snapshots
UPDATE_SNAPS=true ./tools/apitester/run_tests.sh

lint: ## Run linters and format checks
lint: ## Run linters and format checks (smart auto-detect: changed files)
GOTOOLCHAIN=auto $(run-cmd) tools/lint_and_format.sh

lint-all: ## Run linters and format checks across all files
GOTOOLCHAIN=auto $(run-cmd) tools/lint_and_format.sh --all

format: ## Automatically format files where supported
GOTOOLCHAIN=auto $(run-cmd) tools/lint_and_format.sh --fix


build-osv-protos:
cd osv && $(run-cmd) python -m grpc_tools.protoc --python_out=. --mypy_out=. --proto_path=. --proto_path=osv-schema/proto vulnerability.proto importfinding.proto

Expand Down
Loading
Loading