AOSSIE-Org / AOSSIE-Org/Template-Repo

Config: Add Go-Specific Review Instructions to .coderabbit.yaml

未关闭
#95 5 条评论 0 个 reaction 已指派 1 人 已被 @Okd2006 认领 在 GitHub 查看
主要语言
YAML
星标
17
派生
29
平均合并
3 天 13 小时
30 天内合并 PR
6

描述

## Overview

`golangci-lint` is already enabled in `.coderabbit.yaml`, but there are no Go-specific `path_instructions` to guide CodeRabbit's review logic for `.go` files. This issue tracks adding a dedicated Go review instruction block to improve the quality and depth of reviews on AOSSIE's Go-based projects.

---

## Proposed Change

Add the following block to the `path_instructions` section in `.coderabbit.yaml`:

```yaml
path_instructions:
- path: "**/*.go"
instructions: |
Go code review guidelines:

**Naming & Style**
- Follow Effective Go naming conventions (MixedCaps, not underscores).
- Package names should be lowercase, single-word, and descriptive.
- Exported functions, types, and variables must have godoc comments.

**Error Handling**
- Errors must not be silently ignored (no bare `_` discards for error returns).
- Prefer wrapping errors with `fmt.Errorf("...: %w", err)` to preserve stack context.
- Avoid `panic` except in truly unrecoverable situations; prefer returning errors.

**Goroutine & Concurrency Hygiene**
- Every goroutine must have a clear lifetime and ownership.
- Ensure `sync.WaitGroup` or context cancellation is used to manage goroutine teardown.
- Flag potential data races: shared state accessed from multiple goroutines without synchronization.
- Prefer channels for communication over shared memory where appropriate.

**Context Propagation**
- Functions that perform I/O, network calls, or long computations should accept `context.Context` as the first parameter.
- Ensure contexts are not stored in structs; pass them explicitly.
- Check that context cancellation/deadlines are respected in loops and blocking calls.

**Testing**
- Prefer table-driven tests using `[]struct{...}` test case slices.
- Test function names should follow the `TestFunctionName_Scenario` pattern.
- Ensure test coverage for error paths and edge cases, not just happy paths.
- Flag missing tests for exported functions.

**Initialization**
- Flag usage of `init()` functions unless there is clear justification (e.g., driver registration).
- Prefer explicit initialization over side-effect imports.

**Performance & Resource Management**
- Ensure `defer` is used correctly for resource cleanup (files, mutexes, connections).
- Flag unnecessary allocations inside hot loops.
- Prefer pre-allocated slices (`make([]T, 0, n)`) when the size is known in advance.

**Security**
- Flag use of `unsafe` package and require justification.
- Check for SQL injection risks in dynamically constructed queries.
- Ensure sensitive data is not logged.
```

---

## Acceptance Criteria

- [ ] `.coderabbit.yaml` updated with the above `path_instructions` block for `**/*.go` files.
- [ ] The `template-sync.yml` workflow propagates the updated config to child repos using this template.
- [ ] Verified that CodeRabbit applies the Go-specific instructions when reviewing `.go` files.

---

## References

- CodeRabbit path-based instructions: https://docs.coderabbit.ai/guides/review-instructions
- Effective Go: https://go.dev/doc/effective_go
- golangci-lint: https://golangci-lint.run/

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。