Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit11a0820

Browse files
authored
Add a new instruction for commenting (#93)
1 parentf1c532c commit11a0820

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Team and project-specific instructions to enhance GitHub Copilot's behavior for
5959
|[ReactJS Development Instructions](instructions/reactjs.instructions.md)| ReactJS development standards and best practices|[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Freactjs.instructions.md)[![Install in VS Code](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Freactjs.instructions.md)|
6060
|[Ruby on Rails](instructions/ruby-on-rails.instructions.md)| Ruby on Rails coding conventions and guidelines|[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fruby-on-rails.instructions.md)[![Install in VS Code](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fruby-on-rails.instructions.md)|
6161
|[Secure Coding and OWASP Guidelines](instructions/security-and-owasp.instructions.md)| Comprehensive secure coding instructions for all languages and frameworks, based on OWASP Top 10 and industry best practices.|[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fsecurity-and-owasp.instructions.md)[![Install in VS Code](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fsecurity-and-owasp.instructions.md)|
62+
| [Self-explanatory Code Commenting Instructions](instructions/self-explanatory-code-commenting.instructions.md) | Guidelines for GitHub Copilot to write comments to achieve self-explanatory code with less comments. Examples are in JavaScript but it should work on any language that has comments. | [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fself-explanatory-code-commenting.instructions.md) [![Install in VS Code](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fself-explanatory-code-commenting.instructions.md) |
6263
|[Spring Boot Development](instructions/springboot.instructions.md)| Guidelines for building Spring Boot base applications|[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fspringboot.instructions.md)[![Install in VS Code](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fspringboot.instructions.md)|
6364
|[SQL Development](instructions/sql-sp-generation.instructions.md)| Guidelines for generating SQL statements and stored procedures|[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fsql-sp-generation.instructions.md)[![Install in VS Code](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Fsql-sp-generation.instructions.md)|
6465
|[Taming Copilot](instructions/taming-copilot.instructions.md)| Prevent Copilot from wreaking havoc across your codebase, keeping it under control.|[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftaming-copilot.instructions.md)[![Install in VS Code](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Achat-instructions%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Finstructions%2Ftaming-copilot.instructions.md)|
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
---
2+
description:'Guidelines for GitHub Copilot to write comments to achieve self-explanatory code with less comments. Examples are in JavaScript but it should work on any language that has comments.'
3+
applyTo:'**'
4+
---
5+
6+
#Self-explanatory Code Commenting Instructions
7+
8+
##Core Principle
9+
**Write code that speaks for itself. Comment only when necessary to explain WHY, not WHAT.**
10+
We do not need comments most of the time.
11+
12+
##Commenting Guidelines
13+
14+
###❌ AVOID These Comment Types
15+
16+
**Obvious Comments**
17+
```javascript
18+
// Bad: States the obvious
19+
let counter=0;// Initialize counter to zero
20+
counter++;// Increment counter by one
21+
```
22+
23+
**Redundant Comments**
24+
```javascript
25+
// Bad: Comment repeats the code
26+
functiongetUserName() {
27+
returnuser.name;// Return the user's name
28+
}
29+
```
30+
31+
**Outdated Comments**
32+
```javascript
33+
// Bad: Comment doesn't match the code
34+
// Calculate tax at 5% rate
35+
consttax= price*0.08;// Actually 8%
36+
```
37+
38+
###✅ WRITE These Comment Types
39+
40+
**Complex Business Logic**
41+
```javascript
42+
// Good: Explains WHY this specific calculation
43+
// Apply progressive tax brackets: 10% up to 10k, 20% above
44+
consttax=calculateProgressiveTax(income, [0.10,0.20], [10000]);
45+
```
46+
47+
**Non-obvious Algorithms**
48+
```javascript
49+
// Good: Explains the algorithm choice
50+
// Using Floyd-Warshall for all-pairs shortest paths
51+
// because we need distances between all nodes
52+
for (let k=0; k< vertices; k++) {
53+
for (let i=0; i< vertices; i++) {
54+
for (let j=0; j< vertices; j++) {
55+
// ... implementation
56+
}
57+
}
58+
}
59+
```
60+
61+
**Regex Patterns**
62+
```javascript
63+
// Good: Explains what the regex matches
64+
// Match email format: username@domain.extension
65+
constemailPattern=/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
66+
```
67+
68+
**API Constraints or Gotchas**
69+
```javascript
70+
// Good: Explains external constraint
71+
// GitHub API rate limit: 5000 requests/hour for authenticated users
72+
awaitrateLimiter.wait();
73+
constresponse=awaitfetch(githubApiUrl);
74+
```
75+
76+
##Decision Framework
77+
78+
Before writing a comment, ask:
79+
1.**Is the code self-explanatory?** → No comment needed
80+
2.**Would a better variable/function name eliminate the need?** → Refactor instead
81+
3.**Does this explain WHY, not WHAT?** → Good comment
82+
4.**Will this help future maintainers?** → Good comment
83+
84+
##Special Cases for Comments
85+
86+
###Public APIs
87+
```javascript
88+
/**
89+
* Calculate compound interest using the standard formula.
90+
*
91+
*@param{number}principal - Initial amount invested
92+
*@param{number}rate - Annual interest rate (as decimal, e.g., 0.05 for 5%)
93+
*@param{number}time - Time period in years
94+
*@param{number}compoundFrequency - How many times per year interest compounds (default: 1)
95+
*@returns{number} Final amount after compound interest
96+
*/
97+
functioncalculateCompoundInterest(principal,rate,time,compoundFrequency=1) {
98+
// ... implementation
99+
}
100+
```
101+
102+
###Configuration and Constants
103+
```javascript
104+
// Good: Explains the source or reasoning
105+
constMAX_RETRIES=3;// Based on network reliability studies
106+
constAPI_TIMEOUT=5000;// AWS Lambda timeout is 15s, leaving buffer
107+
```
108+
109+
###Annotations
110+
```javascript
111+
// TODO: Replace with proper user authentication after security review
112+
// FIXME: Memory leak in production - investigate connection pooling
113+
// HACK: Workaround for bug in library v2.1.0 - remove after upgrade
114+
// NOTE: This implementation assumes UTC timezone for all calculations
115+
// WARNING: This function modifies the original array instead of creating a copy
116+
// PERF: Consider caching this result if called frequently in hot path
117+
// SECURITY: Validate input to prevent SQL injection before using in query
118+
// BUG: Edge case failure when array is empty - needs investigation
119+
// REFACTOR: Extract this logic into separate utility function for reusability
120+
// DEPRECATED: Use newApiFunction() instead - this will be removed in v3.0
121+
```
122+
123+
##Anti-Patterns to Avoid
124+
125+
###Dead Code Comments
126+
```javascript
127+
// Bad: Don't comment out code
128+
// const oldFunction = () => { ... };
129+
constnewFunction= ()=> {... };
130+
```
131+
132+
###Changelog Comments
133+
```javascript
134+
// Bad: Don't maintain history in comments
135+
// Modified by John on 2023-01-15
136+
// Fixed bug reported by Sarah on 2023-02-03
137+
functionprocessData() {
138+
// ... implementation
139+
}
140+
```
141+
142+
###Divider Comments
143+
```javascript
144+
// Bad: Don't use decorative comments
145+
//=====================================
146+
// UTILITY FUNCTIONS
147+
//=====================================
148+
```
149+
150+
##Quality Checklist
151+
152+
Before committing, ensure your comments:
153+
-[ ] Explain WHY, not WHAT
154+
-[ ] Are grammatically correct and clear
155+
-[ ] Will remain accurate as code evolves
156+
-[ ] Add genuine value to code understanding
157+
-[ ] Are placed appropriately (above the code they describe)
158+
-[ ] Use proper spelling and professional language
159+
160+
##Summary
161+
162+
Remember:**The best comment is the one you don't need to write because the code is self-documenting.**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp