Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for deviations on next line and multiple lines #807

Merged
merged 23 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f3a6c3f
Deviations: remove no longer required query
lcartey Dec 2, 2024
7b2a2e0
Add library for more complex code identifier deviations
lcartey Dec 3, 2024
f173072
Deviations: Integrate extended code-identifier deviations
lcartey Dec 3, 2024
e36828d
Deviations: Add test cases for new code-identifier deviations
lcartey Dec 3, 2024
e077935
Update user manual for new code identifier deviations
lcartey Dec 3, 2024
6e68fb8
Deviations: Support an attribute like comment syntax
lcartey Jan 23, 2025
1a24541
Deviations: Support C/C++ attributes
lcartey Jan 28, 2025
4283652
Deviations: Switch to new deviations format
lcartey Feb 10, 2025
c65f635
Remove deviation suppression query tests
lcartey Feb 10, 2025
f56fa0f
Detect invalid deviation markers
lcartey Feb 12, 2025
bf62d9a
Merge branch 'main' into lcartey/extend-deviations
lcartey Feb 12, 2025
5a6d7ca
Deviations: Support attribute inheritence
lcartey Feb 13, 2025
e38e416
Reformatting test file
lcartey Feb 13, 2025
9f35565
Add change note, update manual.
lcartey Feb 13, 2025
d2f8670
Reformat file
lcartey Feb 13, 2025
0de32d3
Update expected results
lcartey Feb 13, 2025
029537d
Fix typos
lcartey Feb 18, 2025
3f1997b
Deviations: Highlight invalid starts
lcartey Feb 18, 2025
665a7d1
Improve documentation
lcartey Feb 18, 2025
8437c7c
Deviation: Refactor begin/end for clarity.
lcartey Feb 18, 2025
20669c7
Deviation: Clarification in user manual.
lcartey Feb 18, 2025
9e35e59
Deviations: use getADeviationRecord
lcartey Feb 18, 2025
b273d0f
Deviations: Update expected tests
lcartey Feb 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions change_notes/2025-02-13-deviations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- A new in code deviation format has been introduced, using the C/C++ attribute syntax:
```
[[codeql::<standard>_deviation("<code-identifier>")]]
```
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.
- For those codebases that cannot use standard attributes, we have also introduced a comment based syntax
```
// codeql::<standard>_deviation(<code-identifier>)
// codeql::<standard>_deviation_next_line(<code-identifier>)
// codeql::<standard>_deviation_begin(<code-identifier>)
// codeql::<standard>_deviation_end(<code-identifier>)
```
Further information is available in the user manual.
21 changes: 8 additions & 13 deletions cpp/common/src/codingstandards/cpp/Exclusions.qll
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,14 @@ predicate isExcluded(Element e, Query query, string reason) {
) and
reason = "Query has an associated deviation record for the element's file."
or
// The element is on the same line as a suppression comment
exists(Comment c |
c = dr.getACodeIdentifierComment() and
query = dr.getQuery()
|
exists(string filepath, int endLine |
// Comment occurs on the same line as the end line of the element
e.getLocation().hasLocationInfo(filepath, _, _, endLine, _) and
c.getLocation().hasLocationInfo(filepath, endLine, _, _, _)
)
) and
reason =
"Query has an associated deviation record with a code identifier that is applied to the element."
// The element is annotated by a code identifier that deviates this rule
exists(CodeIdentifierDeviation deviationInCode |
dr.getQuery() = query and
deviationInCode = dr.getACodeIdentifierDeviation() and
deviationInCode.isElementMatching(e) and
reason =
"Query has an associated deviation record with a code identifier that is applied to the element."
)
)
or
// The effective category of the query is 'Disapplied'.
Expand Down
Loading
Loading