You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/copilot-instructions.md
+61-87Lines changed: 61 additions & 87 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,22 @@
1
-
[//]: #"Include this file in the repository to provide instructions to GitHub Copilot Autofix. For more information, see https://docs.github.com/copilot/copilot-for-business/copilot-instructions."
2
-
1
+
[//]: #"Include this file in the repository to provide instructions to GitHub Copilot AUtofix. For more information, see https://docs.github.com/copilot/copilot-for-business/copilot-instructions."
3
2
# GitHub Copilot instructions
4
3
5
4
This file contains repository-wide guidance for GitHub Copilot. Each top-level
6
5
section below configures Copilot for a specific use case in this repository.
7
6
Add further top-level sections as needed (general coding conventions, review
8
7
guidance, etc.).
9
8
10
-
## Agentic autofix for CodeQL Coding Standards
9
+
## Autofix for CodeQL Coding Standards
11
10
12
-
This section configures **Agentic Autofix** when generating pull requests to
13
-
remediate alerts produced by [CodeQL Coding Standards](https://github.com/github/codeql-coding-standards/).
14
-
It applies to alerts for any of the supported standards (MISRA C, MISRA C++,
15
-
AUTOSAR C++, CERT C, CERT C++).
11
+
This section configures GitHub Copilot **Autofix** when it generates pull requests to remediate alerts produced by the
project. It applies to alerts for any of the supported standards (MISRA C,
14
+
MISRA C++, AUTOSAR C++, CERT C, CERT C++).
16
15
17
16
### 1. Reference material — where to learn each rule
18
17
19
-
Before proposing a fix, consult the rule’s authoritative implementation as well
20
-
as the corresponding compliant and non-compliant code patterns available as
21
-
test cases in the [`github/codeql-coding-standards` repository](https://github.com/github/codeql-coding-standards/).
22
-
That repository is the single source of truth for what the query
23
-
detects and what compliant code looks like.
18
+
Before proposing a fix, consult the rule’s authoritative implementation as well as the corresponding compliant and non-compliant code patterns available as test cases in the CodeQL Coding Standards [`github/codeql-coding-standards`](https://github.com/github/codeql-coding-standards/)
19
+
repository. That repository is the single source of truth for what the query detects and what compliant code looks like.
24
20
25
21
Project layout (per language / standard):
26
22
@@ -29,6 +25,8 @@ Project layout (per language / standard):
29
25
<language>/<standard>/test/rules/<rule-id>/ # test cases, with COMPLIANT / NON_COMPLIANT markers
30
26
```
31
27
28
+
When referring to the alerts you are addressing, include a clickable link.
29
+
32
30
When generating a fix:
33
31
34
32
1. Locate the rule directory matching the alert’s rule id / query id.
@@ -46,89 +44,65 @@ The full list of supported rules per standard is published as
46
44
### 2. Fix discipline — keep changes minimal and standards-compliant
47
45
48
46
-**Minimum diff.** Modify the smallest possible amount of code that
49
-
eliminates the alert. Do not refactor surrounding code, rename symbols,
47
+
eliminates the assigned alerts. Do not refactor surrounding code, rename symbols,
50
48
reformat unrelated lines, or change public APIs unless strictly required to
51
49
satisfy the rule.
52
50
-**No drive-by changes.** Do not add features, fix unrelated warnings, change
53
51
build flags, update dependencies, or “improve” code that the alert does not
54
52
point at.
55
-
-**Do not attempt at fixing design issues.** A fix should not attempt to
56
-
“improve” the design of the code or address architectural issues.
57
-
Always verify that the code section around the alert is intended to follow
58
-
the standard and add a comment.
59
-
The presence of certain design issues (e.g. dynamic memory allocation) might
60
-
indicate that the code is not intended to be compliant with the standard, and
61
-
that a deviation should be added instead of a code fix.
62
-
-**New code must comply with the same standard.** Any code introduced by the
63
-
fix must itself satisfy the coding standard being verified (e.g. MISRA C++
64
-
2023). Cross-check the inserted code against the COMPLIANT examples in the
65
-
corresponding `test/rules/<rule-id>/` directory and against neighbouring
66
-
rules that are obviously relevant (e.g. don’t fix an integer-conversion rule
67
-
by introducing a cast that violates a different MISRA rule).
68
-
-**Preserve safe and desired functional behavior.** ensure the resulting code
69
-
handles all reasonable real-world scenarios as the code originally intended.
70
-
This may involve precisely maintaining the existing code behavior, or it may
71
-
involve fixing subtle or rare bugs, for instance dangerous overflows,
72
-
that the existing code does not handle and the rule is designed to detect.
73
-
-**Fix dangerous bugs** If the alert is flagging unsafe or undefined behavior,
74
-
critically examine how that safety issue in the code should be properly fixed.
75
-
Add detections and error handling if necessary to make the code safe under
76
-
all conditions without introducing unnecessary complexity. Follow existing
77
-
project guidelines on how to handle rare, dangerous, or unexpected scenarios
78
-
that occur at runtime.
79
-
-**Thoroughly explain analysis and functional changes.** If the alert does not
80
-
introduce any unwanted behavior and the change is functionally equivalent,
81
-
explain your thinking, and clearly show that the code before was safe, and
82
-
that the new code is exactly equivalent in behavior.
83
-
If there was a dangerous edge case or condition, explain exactly how that
84
-
scenario would create problems in the code and how the fix will prevent such
85
-
issues and improve the safety and quality of the codebase.
86
-
87
-
### 3. Deviations — respect project policy and reference it in fixes
88
-
89
-
A project may declare that a rule, file, region, or specific construct is
90
-
intentionally exempt from a coding standard. Such deviations are
53
+
-**New code must comply with the analyzed coding standard.** Any code introduced by the
54
+
fix must itself satisfy every rule of the coding standard being verified
55
+
(e.g. all MISRA C rules). Do not limit the review to the rule targeted by
56
+
the alert: iterate over the full supported rules list for the applicable
57
+
standard and, for each rule, read its help file
58
+
(`<language>/<standard>/src/rules/<rule-id>/<rule-id>.md` or `.qhelp`) to
59
+
understand its intent, then verify that the introduced code does not violate
60
+
it. Cross-check against the COMPLIANT examples in each rule's
61
+
`test/rules/<rule-id>/` directory.
62
+
-**Match the project’s existing style.** Follow the conventions visible in
63
+
the surrounding source files (naming, headers, namespaces, C++ standard
64
+
level, use of `enum class`, etc.).
65
+
-**Preserve behaviour.** A coding-standards fix is a refactor at the source
66
+
level, not a functional change. The fix must not alter observable runtime
67
+
behaviour unless the rule explicitly targets undefined or implementation-
68
+
defined behaviour that has to change.
69
+
70
+
### 3. Do not touch build outputs, generated files, or `.gitignore`
71
+
72
+
Autofix pull requests must only change source files that are part of the
73
+
checked-in project. They must **not** include:
74
+
75
+
- Build directories or files generated during compilation.
76
+
- Editor / IDE state (`.vscode/`, `.idea/`, `.DS_Store`, etc.).
77
+
-**`.gitignore` itself.** Do not add, remove, or reorder entries in
78
+
`.gitignore` as part of an autofix.
79
+
- The CodeQL workflow files under `.github/workflows/` (e.g. `codeql.yml`).
80
+
Suppression or scope changes must use the deviation mechanism (see §4),
81
+
not workflow edits.
82
+
83
+
### 4. Deviations — respect project policy and reference it in fixes
84
+
85
+
A project under analysis may declare that a rule, file, region, or specific
86
+
construct is intentionally exempt from a coding standard. Such deviations are
91
87
not always expressed through the same mechanism: a project may use the
92
-
**standard CodeQL Coding Standards deviation mechanism**, a
93
-
**custom annotation or attribute** convention,
94
-
**in-source line / block comments**,
88
+
**standard CodeQL Coding Standards deviation mechanism**, a **custom
89
+
annotation or attribute** convention, **in-source line / block comments**,
95
90
or a **separate documentation file** (for example a `DEVIATIONS.md`,
96
-
`MISRA-deviations.md`, `coding-standards.yml`, compliance matrix, or similar).
97
-
98
-
Locate the deviations file and explicitly search for matching deviations
99
-
before proposing code changes.
100
-
The fix proposal must take what is found into account and treat it as an
101
-
existing deviation if it clearly covers the alert location and rule.
91
+
`MISRA-deviations.md`, compliance matrix, or similar).
102
92
103
93
If the alert location is covered by an existing deviation:
104
-
- Look for existing deviations of that rule, and see if any should apply
105
-
- In the pull request description, explicitly state that a matching
106
-
deviation already exists in the project, citing the file path and the
0 commit comments