Skip to content

Commit f494dde

Browse files
authored
Fix typos and enhance clarity in instructions
Corrected typos and improved clarity in Copilot instructions.
1 parent 04c5cab commit f494dde

1 file changed

Lines changed: 61 additions & 87 deletions

File tree

docs/copilot-instructions.md

Lines changed: 61 additions & 87 deletions
Original file line numberDiff line numberDiff 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."
32
# GitHub Copilot instructions
43

54
This file contains repository-wide guidance for GitHub Copilot. Each top-level
65
section below configures Copilot for a specific use case in this repository.
76
Add further top-level sections as needed (general coding conventions, review
87
guidance, etc.).
98

10-
## Agentic autofix for CodeQL Coding Standards
9+
## Autofix for CodeQL Coding Standards
1110

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
12+
[CodeQL Coding Standards](https://github.com/github/codeql-coding-standards/)
13+
project. It applies to alerts for any of the supported standards (MISRA C,
14+
MISRA C++, AUTOSAR C++, CERT C, CERT C++).
1615

1716
### 1. Reference material — where to learn each rule
1817

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.
2420

2521
Project layout (per language / standard):
2622

@@ -29,6 +25,8 @@ Project layout (per language / standard):
2925
<language>/<standard>/test/rules/<rule-id>/ # test cases, with COMPLIANT / NON_COMPLIANT markers
3026
```
3127

28+
When referring to the alerts you are addressing, include a clickable link.
29+
3230
When generating a fix:
3331

3432
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
4644
### 2. Fix discipline — keep changes minimal and standards-compliant
4745

4846
- **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,
5048
reformat unrelated lines, or change public APIs unless strictly required to
5149
satisfy the rule.
5250
- **No drive-by changes.** Do not add features, fix unrelated warnings, change
5351
build flags, update dependencies, or “improve” code that the alert does not
5452
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
9187
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**,
9590
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).
10292

10393
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
107-
relevant `rule-id` / `query-id` / `permit-id` / `code-identifier` / scope
108-
(paths or markers) so reviewers can decide whether to accept the fix or
109-
keep the deviation.
110-
- Do not silently delete or weaken an existing deviation, permit, or
111-
re-categorization entry as part of the fix.
112-
- Propose a code fix that would make the location compliant by
94+
95+
- **Still propose a code fix** that would make the location compliant by
11396
default. Authors may have left the deviation in place pragmatically and
11497
may prefer a real fix.
115-
- Consider whether an existing code identifier should be used
116-
- Consider whether a file-wide exception should be used
117-
- Consider whether a new code identifier should be used
118-
- If using a code-identifier, look for examples to determine whether
119-
to use [[attribute]] form
120-
- If using an [[attribute]], look for project formatting configurations or code
121-
examples to determine how to format the attribute relative to its declaration
122-
- When using deviation comments, consider project formatting, the specific
123-
violation in question, and other example deviation comments in the project to
124-
determine whether to use same-line, next-line, or begin/end comment deviations
125-
Project formatting configuration may be .clang-format, etc.
126-
127-
### 4. False positives — propose a deviation, do not stay silent
128-
129-
Precedence: if an alert is judged to be a false positive, the false-positive
130-
workflow in this section overrides any guidance above about proposing a code
131-
fix when a deviation exists.
98+
- **In the pull request description, explicitly state** that a matching
99+
deviation already exists in the project, referring to the possible deviation marker
100+
so reviewers can decide whether to accept the fix or keep the deviation.
101+
- If the deviation style does not match the coding standards user manual, propose a fix.
102+
- Do not silently delete or weaken an existing deviation, permit, or
103+
re-categorization entry as part of the fix.
104+
105+
### 5. False positives — propose a deviation, do not stay silent
132106

133107
Copilot autofix normally refrains from opening a pull request when it
134108
considers an alert to be a false positive. For CodeQL Coding Standards alerts
@@ -156,8 +130,8 @@ When an alert is judged to be a false positive, the autofix PR must:
156130
or directory is affected;
157131
- a project-wide deviation only when the rule is genuinely inapplicable to
158132
the project.
159-
Use `<standard>` ∈ {`misra`, `autosar`, `cert`} as appropriate for the
160-
alert.
133+
Use `<standard>` ∈ {`misra`, `autosar`, `cert`} as appropriate for the
134+
alert.
161135
3. **Populate the deviation record** with at least:
162136
- `rule-id` matching the alert’s rule identifier;
163137
- `query-id` matching the alert’s `@id` (when the deviation is meant to
@@ -175,7 +149,7 @@ When an alert is judged to be a false positive, the autofix PR must:
175149
5. **In the PR description**, explicitly state that the alert is being
176150
handled as a false positive via a deviation (not by code change), link to
177151
the
178-
[deviation mechanism documentation](https://github.com/github/codeql-coding-standards/blob/main/docs/user_manual.md#applying-deviations),
152+
[deviation mechanism documentation](https://github.com/github/codeql-coding-standards/blob/main/docs/user_manual.md#applying-deviations),
179153
and summarise the justification so a reviewer can approve or reject it.
180154

181155
A false-positive PR should therefore contain **only** the deviation entry

0 commit comments

Comments
 (0)