diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 5c9f0bf1..f6e9e1ab 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -14,6 +14,7 @@ By participating in this project, you agree to abide by our [Code of Conduct](.g - [Pull Request Guidelines](#pull-request-guidelines) - [Commit Message Guidelines](#commit-message-guidelines) - [Testing](#testing) +- [Linting](#linting) - [Documentation](#documentation) - [Component-Specific Guidelines](#component-specific-guidelines) - [Backporting Changes](#backporting-changes) @@ -70,6 +71,41 @@ We recommend running tests locally to catch issues before opening a PR. --- +## Linting + +We use [golangci-lint](https://golangci-lint.run/) to enforce code quality standards. The linter runs automatically on all pull requests and will block merging if issues are found. + +### Running the Linter Locally + +```bash +# Run linting (will fail on errors) +make lint + +# Run linting with auto-fix for fixable issues +make lint-fix +``` + +### Configuration + +Linting rules are configured in `.golangci.yml` at the repository root. The configuration enables these linters: + +- **errcheck** - Check for unchecked errors +- **govet** - Report suspicious constructs +- **staticcheck** - Advanced static analysis +- **gofmt/goimports** - Code formatting +- **misspell** - Spelling errors in comments +- **revive** - Extensible linter with many rules +- **unused** - Find unused code +- And more (see `.golangci.yml` for the full list) + +### Best Practices + +- Run `make lint` before committing to catch issues early +- Use `make lint-fix` to automatically fix formatting issues +- If a lint rule seems incorrect for your use case, discuss it in the PR rather than disabling it + +--- + ## Documentation Contributions to documentation are highly valued. If you find any documentation gaps or errors: diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 00000000..8a934e94 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,43 @@ +name: golangci-lint + +on: + push: + branches: + - main + pull_request: + merge_group: + workflow_dispatch: + +permissions: + contents: read + pull-requests: read + +jobs: + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + cache: true + + - name: Download dependencies + run: go mod download + + - name: Generate code + run: make generate + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + # Install from source to match Go 1.24 + install-mode: goinstall + version: v1.62.2 + args: --timeout=5m + # Show only new issues for PRs + only-new-issues: true diff --git a/.golangci.yml b/.golangci.yml index aac8a13f..01945236 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,7 +21,6 @@ linters: enable: - dupl - errcheck - - exportloopref - ginkgolinter - goconst - gocyclo diff --git a/Makefile b/Makefile index bde821da..a78ef5a8 100644 --- a/Makefile +++ b/Makefile @@ -516,7 +516,7 @@ HELMIFY ?= helmify KUSTOMIZE_VERSION ?= v5.4.3 CONTROLLER_TOOLS_VERSION ?= v0.16.5 ENVTEST_VERSION ?= release-0.19 -GOLANGCI_LINT_VERSION ?= v1.59.1 +GOLANGCI_LINT_VERSION ?= v1.62.2 HELM_VERSION ?= v3.14.2 YQ_VERSION ?= v4.40.5