|
| 1 | +# Linkerd2 Proxy Copilot Instructions |
| 2 | + |
| 3 | +## Code Generation |
| 4 | + |
| 5 | +- Code MUST pass `cargo fmt`. |
| 6 | +- Code MUST pass `cargo clippy --all-targets --all-features -- -D warnings`. |
| 7 | +- Markdown MUST pass `markdownlint-cli2`. |
| 8 | +- Prefer `?` for error propagation. |
| 9 | +- Avoid `unwrap()` and `expect()` outside tests. |
| 10 | +- Use `tracing` crate macros (`tracing::info!`, etc.) for structured logging. |
| 11 | + |
| 12 | +### Comments |
| 13 | + |
| 14 | +Comments should explain **why**, not **what**. Focus on high-level rationale and |
| 15 | +design intent at the function or block level, rather than line-by-line |
| 16 | +descriptions. |
| 17 | + |
| 18 | +- Use comments to capture: |
| 19 | + - System-facing or interface-level concerns |
| 20 | + - Key invariants, preconditions, and postconditions |
| 21 | + - Design decisions and trade-offs |
| 22 | + - Cross-references to architecture or design documentation |
| 23 | +- Avoid: |
| 24 | + - Line-by-line commentary explaining obvious code |
| 25 | + - Restating what the code already clearly expresses |
| 26 | +- For public APIs: |
| 27 | + - Use `///` doc comments to describe the contract, behavior, parameters, and |
| 28 | + usage examples |
| 29 | +- For internal rationale: |
| 30 | + - Use `//` comments sparingly to note non-obvious reasoning or edge-case |
| 31 | + handling |
| 32 | +- Be neutral and factual. |
| 33 | + |
| 34 | +### Rust File Organization |
| 35 | + |
| 36 | +For Rust source files, enforce this layout: |
| 37 | + |
| 38 | +1. **Non‑public imports** |
| 39 | + - Declare all `use` statements for private/internal crates first. |
| 40 | + - Group imports to avoid duplicates and do **not** add blank lines between |
| 41 | + `use` statements. |
| 42 | + |
| 43 | +2. **Module declarations** |
| 44 | + - List all `mod` declarations. |
| 45 | + |
| 46 | +3. **Re‑exports** |
| 47 | + - Follow with `pub use` statements. |
| 48 | + |
| 49 | +4. **Type definitions** |
| 50 | + - Define `struct`, `enum`, `type`, and `trait` declarations. |
| 51 | + - Sort by visibility: `pub` first, then `pub(crate)`, then private. |
| 52 | + - Public types should be documented with `///` comments. |
| 53 | + |
| 54 | +5. **Impl blocks** |
| 55 | + - Implement methods in the same order as types above. |
| 56 | + - Precede each type’s `impl` block with a header comment: `// === <TypeName> ===` |
| 57 | + |
| 58 | +6. **Tests** |
| 59 | + - End with a `tests` module guarded by `#[cfg(test)]`. |
| 60 | + - If the in‑file test module exceeds 100 lines, move it to |
| 61 | + `tests/<filename>.rs` as a child integration‑test module. |
| 62 | + |
| 63 | +## Test Generation |
| 64 | + |
| 65 | +- Async tests MUST use `tokio::test`. |
| 66 | +- Synchronous tests use `#[test]`. |
| 67 | +- Include at least one failing‑edge‑case test per public function. |
| 68 | +- Use `tracing::info!` for logging in tests, usually in place of comments. |
| 69 | + |
| 70 | +## Code Review |
| 71 | + |
| 72 | +### Rust |
| 73 | + |
| 74 | +- Point out any `unsafe` blocks and justify their safety. |
| 75 | +- Flag functions >50 LOC for refactor suggestions. |
| 76 | +- Highlight missing docs on public items. |
| 77 | + |
| 78 | +### Markdown |
| 79 | + |
| 80 | +- Use `markdownlint-cli2` to check for linting errors. |
| 81 | +- Lines SHOULD be wrapped at 80 characters. |
| 82 | +- Fenced code blocks MUST include a language identifier. |
| 83 | + |
| 84 | +### Copilot Instructions |
| 85 | + |
| 86 | +- Start each instruction with an imperative, present‑tense verb. |
| 87 | +- Keep each instruction under 120 characters. |
| 88 | +- Provide one directive per instruction; avoid combining multiple ideas. |
| 89 | +- Use "MUST" and "SHOULD" sparingly to emphasize critical rules. |
| 90 | +- Avoid semicolons and complex punctuation within bullets. |
| 91 | +- Do not reference external links, documents, or specific coding standards. |
| 92 | + |
| 93 | +## Commit Messages |
| 94 | + |
| 95 | +Commits follow the Conventional Commits specification: |
| 96 | + |
| 97 | +### Subject |
| 98 | + |
| 99 | +Subjects are in the form: `<type>[optional scope]: <description>` |
| 100 | + |
| 101 | +- **Type**: feat, fix, docs, refactor, test, chore, ci, build, perf, revert |
| 102 | + (others by agreement) |
| 103 | +- **Scope**: optional, lowercase; may include `/` to denote sub‑modules (e.g. |
| 104 | + `http/detect`) |
| 105 | +- **Description**: imperative mood, present tense, no trailing period |
| 106 | +- MUST be less than 72 characters |
| 107 | +- Omit needless words! |
| 108 | + |
| 109 | +### Body |
| 110 | + |
| 111 | +Non-trivial commits SHOULD include a body summarizing the change. |
| 112 | + |
| 113 | +- Explain *why* the change was needed. |
| 114 | +- Describe *what* was done at a high level. |
| 115 | +- Use present-tense narration. |
| 116 | +- Use complete sentences, paragraphs, and punctuation. |
| 117 | +- Preceded by a blank line. |
| 118 | +- Wrapped at 80 characters. |
| 119 | +- Omit needless words! |
| 120 | + |
| 121 | +### Breaking changes |
| 122 | + |
| 123 | +If the change introduces a backwards-incompatible change, it MUST be marked as |
| 124 | +such. |
| 125 | + |
| 126 | +- Indicated by `!` after the type/scope (e.g. `feat(inbound)!: …`) |
| 127 | +- Optionally including a `BREAKING CHANGE:` section in the footer explaining the |
| 128 | + change in behavior. |
| 129 | + |
| 130 | +### Examples |
| 131 | + |
| 132 | +```text |
| 133 | +feat(auth): add JWT refresh endpoint |
| 134 | +
|
| 135 | +There is currently no way to refresh a JWT token. |
| 136 | +
|
| 137 | +This exposes a new `/refresh` route that returns a refreshed token. |
| 138 | +``` |
| 139 | + |
| 140 | +```text |
| 141 | +feat(api)!: remove deprecated v1 routes |
| 142 | +
|
| 143 | +The `/v1/*` endpoints have been deprecated for a long time and are no |
| 144 | +longer called by clients. |
| 145 | +
|
| 146 | +This change removes the `/v1/*` endpoints and all associated code, |
| 147 | +including integration tests and documentation. |
| 148 | +
|
| 149 | +BREAKING CHANGE: The previously-deprecated `/v1/*` endpoints were removed. |
| 150 | +``` |
| 151 | + |
| 152 | +## Pull Requests |
| 153 | + |
| 154 | +- The subject line MUST be in the conventional commit format. |
| 155 | +- Auto‑generate a PR body summarizing the problem, solution, and verification steps. |
| 156 | +- List breaking changes under a separate **Breaking Changes** heading. |
0 commit comments