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

Appearance settings

Commit afbfbec

Browse filesBrowse files
Merge pull request #807 from github/lcartey/extend-deviations
Add support for deviations on next line and multiple lines
2 parents 16b8355 + b273d0f commit afbfbec
Copy full SHA for afbfbec
Expand file treeCollapse file tree

22 files changed

+705
-184
lines changed

‎change_notes/2025-02-13-deviations.md

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- A new in code deviation format has been introduced, using the C/C++ attribute syntax:
2+
```
3+
[[codeql::<standard>_deviation("<code-identifier>")]]
4+
```
5+
This can be applied to functions, statements and variables to apply a deviation from the Coding Standards configuration file. The user manual has been updated to describe the new format.
6+
- For those codebases that cannot use standard attributes, we have also introduced a comment based syntax
7+
```
8+
// codeql::<standard>_deviation(<code-identifier>)
9+
// codeql::<standard>_deviation_next_line(<code-identifier>)
10+
// codeql::<standard>_deviation_begin(<code-identifier>)
11+
// codeql::<standard>_deviation_end(<code-identifier>)
12+
```
13+
Further information is available in the user manual.

‎cpp/common/src/codingstandards/cpp/Exclusions.qll

Copy file name to clipboardExpand all lines: cpp/common/src/codingstandards/cpp/Exclusions.qll
+8-13Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,14 @@ predicate isExcluded(Element e, Query query, string reason) {
3535
) and
3636
reason = "Query has an associated deviation record for the element's file."
3737
or
38-
// The element is on the same line as a suppression comment
39-
exists(Comment c |
40-
c = dr.getACodeIdentifierComment() and
41-
query = dr.getQuery()
42-
|
43-
exists(string filepath, int endLine |
44-
// Comment occurs on the same line as the end line of the element
45-
e.getLocation().hasLocationInfo(filepath, _, _, endLine, _) and
46-
c.getLocation().hasLocationInfo(filepath, endLine, _, _, _)
47-
)
48-
) and
49-
reason =
50-
"Query has an associated deviation record with a code identifier that is applied to the element."
38+
// The element is annotated by a code identifier that deviates this rule
39+
exists(CodeIdentifierDeviation deviationInCode |
40+
dr.getQuery() = query and
41+
deviationInCode = dr.getACodeIdentifierDeviation() and
42+
deviationInCode.isElementMatching(e) and
43+
reason =
44+
"Query has an associated deviation record with a code identifier that is applied to the element."
45+
)
5146
)
5247
or
5348
// The effective category of the query is 'Disapplied'.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.