Skip to content

Commit 0aa483c

Browse files
Add documentation for baseline suites.
1 parent b35ad17 commit 0aa483c

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- Added tags `codingstandards/baseline/safety` and `codingstandards/baseline/style` to various rules
2+
- These tags are intended to be applied to rules that are well supported, have low false positive rates, and widely applicable, even beyond safety-critical systems that want strict adherence to any particular coding standard for compliance purposes.
3+
- Added packs `coding-standards-cpp-baseline` and `coding-standards-c-baseline`
4+
- These packs have default query suites that include both `safety` and `style` baseline rules for C++ and C coding standards respectively.
5+
- These packs are designed to be suitable for a wide variety of C/C++ projects that are interested in additional code quality and safety checks without the full strictness of a specific coding standard.
6+
- In additional to the default suites which have both style and safety rules, these packs contain `c??-baseline-safety` and `c??-baseline-style` query suites for each area of focus.

docs/development_handbook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ The `generate_package_description.py` script provides a "best-effort" approach t
265265
- `maintainability` - if the query identifies an issue which makes the code harder to maintain.
266266
- `performance` - if the query identifies an issue which has a negative impact on the performance of the code.
267267
- `concurrency` - if the query identifies a concurrency issue.
268+
- `coding-standards/baseline/safety` or `/style` - if the query is part of the baseline safety suite. See the user manual for our definition of `safety` vs `style`.
268269
- Validate the rule package description file using the `validate-rule-package.py` script that validates the rule package descriptions against the schema `rule-package.schema.json` located in the `schemas` directory.
269270
- `python3.9 scripts/validate-rule-package.py <rule_package_name>`
270271

docs/user_manual.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
| 0.25.0 | 2025-01-15 | Mike Fairhurst | Add guidance for the usage of 'strict' queries. |
3434
| 0.26.0 | 2025-02-12 | Luke Cartey | Describe support for new deviation code identifier formats |
3535
| 0.27.0 | 2025-05-15 | Luke Cartey | Documented completed support for MISRA C 2023. |
36+
| 0.28.0 | 2025-12-08 | Mike Fairhurst | Add baseline query suites for C and C++ coding standards. |
3637

3738
## Release information
3839

@@ -90,6 +91,25 @@ The datasheet _"CodeQL Coding Standards: supported rules"_, provided with each r
9091
[^5]: The unimplemented supportable MISRA C 2023 rules are `Rule 9.5`, `Rule 9.6`, `Rule 17.13`. `Rule 9.5`, `Rule 9.6` and `Rule 17.13` require additional support in the CodeQL CLI to ensure the required information is available in the CodeQL database to identify violations of these rules. Note: `Dir 4.14` is covered by the default CodeQL queries, which identify potential security vulnerabilities caused by not validating external input.
9192
[^6]: The rules `5.13.7`, `19.0.1` and `19.1.2` are not planned to be implemented by CodeQL as they are compiler checked in all supported compilers.
9293

94+
## Baseline suites
95+
96+
Queries that are part of the above rules may additionally be added to our C or C++ "baseline suites." The baseline suites are not intended for compliance with any particular coding standard, but rather to provide a set of well-supported, less opinionated, low false positive rate rules. Project maintainers interested in additional code quality and safety checks, and have no specific compliance requirements, may find these suites useful.
97+
98+
Baseline suites are separated by language (C or C++) and area of focus (`safety` or `style`). The difference between style and safety is not always clear-cut. Our project uses the following guidelines to determine whether a rule is more focused on safety or style:
99+
100+
| Characteristic | Focus | Description |
101+
|--------------------|--------|-------------|
102+
| Simplicity | Style | Simpler concepts tend to be added to the style suite. |
103+
| Severity | Safety | Rules that prevent potentially severe issues tend to be added to the safety suite. |
104+
| Undefined behavior | Safety | Rules that detect undefined behavior tend to be added to the safety suite. |
105+
| Bug detection | Safety | Rules detecting misuse of an API or language feature tend to be added to the safety suite. |
106+
| Opinionated | Style | More opinionated rules tend to be added to the style suite. |
107+
| Habit-enforcing | Style | Rules that enforce common coding habits tend to be added to the style suite. |
108+
| Bans | Style | Rules that ban certain language features or coding patterns tend to be added to the style suite. |
109+
| Remediatability | Style | Rules that are easy to remediate tend to be added to the style suite. |
110+
111+
Only the rules in the baseline suites are categorized into `safety` and `style`, the remaining rules are not. Some baseline rules may be categorized as both `safety` and `style`, though this is kept to a minimum.
112+
93113
## Supported environment
94114

95115
This section describes the supported environment for the product.
@@ -254,12 +274,27 @@ If you have downloaded a release artifact containing the packs, you will need to
254274

255275
Alternatively, the packs can be made available to CodeQL without specification on the comamnd line by placing them inside the distribution under the `qlpacks/codeql/` directory, or placed inside a directory adjacent to the folder containing the distribution.
256276

277+
##### Running the baseline suites
278+
279+
Once you have a CodeQL database for your project you can run the baseline style and safety checks using the `codeql database analyze` command by specifying the baseline QL pack which you want to run as an argument, along with a version specifier:
280+
281+
```bash
282+
codeql database analyze --format=sarifv2.1.0 --output=<name-of-results-file>.sarif path/to/<output_database_name> advanced-security/coding-standards-<language>-baseline@version
283+
```
284+
285+
The output of this command will be a [SARIF file](https://sarifweb.azurewebsites.net/) called `<name-of-results-file>.sarif`.
286+
257287
##### Alternative query sets
258288

259-
Each supported standard includes a variety of query suites, which enable the running of different sets of queries based on specified properties. In addition, a custom query suite can be defined as specified by the CodeQL CLI documentation, in order to select any arbitrary sets of queries in this repository. To run
289+
Each supported standard includes a variety of query suites, which enable the running of different sets of queries based on specified properties. The baseline suites optionally expose `safety` and `style` suites as described in the section _Baseline suites_. In addition, any arbitrary set of queries from this repository can be selected via custom query suites as specified by the CodeQL CLI documentation.
290+
291+
To run
260292

261293
```bash
294+
# For a specific coding standard
262295
codeql database analyze --format=sarifv2.1.0 --output=<name-of-results-file>.sarif path/to/<output_database_name> codeql/<standard>-<language>-coding-standard@version:codeql-suites/<alternative-suite>.qls
296+
# or for baseline suites
297+
codeql database analyze --format=sarifv2.1.0 --output=<name-of-results-file>.sarif path/to/<output_database_name> advanced-security/coding-standards-<language>-baseline@version:codeql-suites/<alternative-suite>.qls
263298
```
264299

265300
If modifying the query suite, ensure that all Rules you expect to be covered by CodeQL in your Guideline Enforcement Plan (or similar) are included in the query suite, by running:

0 commit comments

Comments
 (0)