-
Notifications
You must be signed in to change notification settings - Fork 66
Restore deleted deviations suppression query #876
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MichaelRFairhurst
merged 11 commits into
main
from
lcartey/restore-deleted-deviations-suppression-query
Apr 22, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2045a44
Restore deleted deviations suppression query
lcartey 1e4011f
Add change note.
lcartey c25018f
Re-add DeviationsSuppression.ql
lcartey ddd28e6
Test new deviation formats for DeviationSuppressions.ql
lcartey d8ac07f
Add missing results
lcartey 52e6467
Add comment
lcartey 184e5d3
Extract common library for location handling
lcartey 126ed55
Add getLastColumnNumber to shared library
lcartey 5ad61ee
Deviations: Include the final line in ranges
lcartey 6a5f095
Deviations: Store start columns for comment ranges
lcartey 8c2da1c
Deviations: Expand testing for ranges
lcartey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- The `DeviationsSuppression.ql` query has been restored after being incorrectly deleted in a previous release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import cpp | ||
|
||
/** Holds if `lineNumber` is an indexed line number in file `f`. */ | ||
predicate isLineNumber(File f, int lineNumber) { | ||
exists(Location l | l.getFile() = f | | ||
l.getStartLine() = lineNumber | ||
or | ||
l.getEndLine() = lineNumber | ||
) | ||
} | ||
|
||
/** Gets the last line number in `f`. */ | ||
int getLastLineNumber(File f) { result = max(int lineNumber | isLineNumber(f, lineNumber)) } | ||
|
||
/** Gets the last column number on the last line of `f`. */ | ||
int getLastColumnNumber(File f) { | ||
result = | ||
max(Location l | | ||
l.getFile() = f and | ||
l.getEndLine() = getLastLineNumber(f) | ||
| | ||
l.getEndColumn() | ||
) | ||
} | ||
|
||
/** Gets the last column number on the given line of `filepath`. */ | ||
bindingset[filepath, lineNumber] | ||
int getLastColumnNumber(string filepath, int lineNumber) { | ||
result = max(Location l | l.hasLocationInfo(filepath, _, _, lineNumber, _) | l.getEndColumn()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
cpp/common/src/codingstandards/cpp/deviations/DeviationsSuppression.qhelp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd"> | ||
<qhelp> | ||
<overview> | ||
<p>This query generates suppression information for rules that have an associated deviation record.</p> | ||
</overview> | ||
<references> | ||
<li> | ||
MISRA Compliance 2020 document: | ||
<a href="https://www.misra.org.uk/app/uploads/2021/06/MISRA-Compliance-2020.pdf">Chapter 4.2 (page 12) - Deviations.</a> | ||
</li> | ||
</references> | ||
</qhelp> |
102 changes: 102 additions & 0 deletions
102
cpp/common/src/codingstandards/cpp/deviations/DeviationsSuppression.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* @name Deviation suppression | ||
* @description Generates information about files and locations where certain alerts should be considered suppressed by deviations. | ||
* @kind alert-suppression | ||
* @id cpp/coding-standards/deviation-suppression | ||
*/ | ||
|
||
import cpp | ||
import Deviations | ||
import codingstandards.cpp.Locations | ||
|
||
newtype TDeviationScope = | ||
TDeviationRecordFileScope(DeviationRecord dr, File file) { | ||
exists(string deviationPath | | ||
dr.isDeviated(_, deviationPath) and | ||
file.getRelativePath().prefix(deviationPath.length()) = deviationPath | ||
) | ||
} or | ||
TDeviationRecordCodeIdentiferDeviationScope(DeviationRecord dr, CodeIdentifierDeviation c) { | ||
c = dr.getACodeIdentifierDeviation() | ||
} | ||
|
||
/** A deviation scope. */ | ||
class DeviationScope extends TDeviationScope { | ||
/** Gets the location at which this deviation was defined. */ | ||
abstract Locatable getDeviationDefinitionLocation(); | ||
|
||
/** Gets the Query being deviated. */ | ||
abstract Query getQuery(); | ||
|
||
abstract string toString(); | ||
|
||
abstract predicate hasLocationInfo( | ||
string filepath, int startline, int startcolumn, int endline, int endcolumn | ||
); | ||
} | ||
|
||
/** A deviation scope derived from a "path" entry in a `DeviationRecord`. */ | ||
class DeviationRecordFileScope extends DeviationScope, TDeviationRecordFileScope { | ||
private DeviationRecord getDeviationRecord() { this = TDeviationRecordFileScope(result, _) } | ||
|
||
override Locatable getDeviationDefinitionLocation() { result = getDeviationRecord() } | ||
|
||
private File getFile() { this = TDeviationRecordFileScope(_, result) } | ||
|
||
override Query getQuery() { result = getDeviationRecord().getQuery() } | ||
|
||
override predicate hasLocationInfo( | ||
string filepath, int startline, int startcolumn, int endline, int endcolumn | ||
) { | ||
// In an ideal world, we would produce a URL here that informed the AlertSuppression code that | ||
// the whole file was suppressed. However, the alert suppression code only works with locations | ||
// with lines and columns, so we generate a location that covers the whole "indexed" file, by | ||
// finding the location indexed in the database with the latest line and column number. | ||
exists(File f | f = getFile() | | ||
f.getLocation().hasLocationInfo(filepath, _, _, _, _) and | ||
startline = 1 and | ||
startcolumn = 1 and | ||
endline = getLastLineNumber(f) and | ||
endcolumn = getLastColumnNumber(f) | ||
) | ||
} | ||
|
||
override string toString() { | ||
result = "Deviation of " + getDeviationRecord().getQuery() + " for " + getFile() + "." | ||
} | ||
} | ||
|
||
/** | ||
* A deviation scope derived from a comment corresponding to a "code-identifier" entry for a | ||
* `DeviationRecord`. | ||
*/ | ||
class DeviationRecordCommentScope extends DeviationScope, | ||
TDeviationRecordCodeIdentiferDeviationScope | ||
{ | ||
private DeviationRecord getDeviationRecord() { | ||
this = TDeviationRecordCodeIdentiferDeviationScope(result, _) | ||
} | ||
|
||
private CodeIdentifierDeviation getCodeIdentifierDeviation() { | ||
this = TDeviationRecordCodeIdentiferDeviationScope(_, result) | ||
} | ||
|
||
override Locatable getDeviationDefinitionLocation() { result = getDeviationRecord() } | ||
|
||
override Query getQuery() { result = getDeviationRecord().getQuery() } | ||
|
||
override predicate hasLocationInfo( | ||
string filepath, int startline, int startcolumn, int endline, int endcolumn | ||
) { | ||
getCodeIdentifierDeviation() | ||
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | ||
} | ||
|
||
override string toString() { result = getCodeIdentifierDeviation().toString() } | ||
} | ||
|
||
from DeviationScope deviationScope | ||
select deviationScope.getDeviationDefinitionLocation(), // suppression comment | ||
"// lgtm[" + deviationScope.getQuery().getQueryId() + "]", // text of suppression comment (excluding delimiters) | ||
"lgtm[" + deviationScope.getQuery().getQueryId() + "]", // text of suppression annotation | ||
deviationScope // scope of suppression |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
cpp/common/test/deviations/deviations_report_deviated/DeviationsSuppression.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:12:1:12:58 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 12 | | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:14:1:14:65 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 14 | | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:18:1:18:40 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 18 | | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:21:3:27:53 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 21:3:27:53 | | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:29:3:35:53 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 29:3:35:53 | | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/type-long-double-used] | lgtm[cpp/autosar/type-long-double-used] | main.cpp:40:39:41:99 | Deviation of cpp/autosar/type-long-double-used applied to main.cpp Line 40:39:41:99 | | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/unused-return-value] | lgtm[cpp/autosar/unused-return-value] | nested/nested2/test2.h:1:1:6:1 | Deviation of cpp/autosar/unused-return-value for nested/nested2/test2.h. | | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | coding-standards.xml:1:1:17:19 | Deviation of cpp/autosar/useless-assignment for coding-standards.xml. | | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | main.cpp:1:1:44:1 | Deviation of cpp/autosar/useless-assignment for main.cpp. | | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | nested/coding-standards.xml:1:1:13:19 | Deviation of cpp/autosar/useless-assignment for nested/coding-standards.xml. | | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | nested/nested2/test2.h:1:1:6:1 | Deviation of cpp/autosar/useless-assignment for nested/nested2/test2.h. | | ||
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | nested/test.h:1:1:6:1 | Deviation of cpp/autosar/useless-assignment for nested/test.h. | |
1 change: 1 addition & 0 deletions
1
cpp/common/test/deviations/deviations_report_deviated/DeviationsSuppression.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
codingstandards/cpp/deviations/DeviationsSuppression.ql |
18 changes: 18 additions & 0 deletions
18
cpp/common/test/deviations/deviations_report_deviated/TypeLongDoubleUsed.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
| main.cpp:11:15:11:16 | d1 | Use of long double type. | | ||
| main.cpp:12:15:12:16 | d2 | Use of long double type. | | ||
| main.cpp:14:15:14:16 | d3 | Use of long double type. | | ||
| main.cpp:16:15:16:16 | d4 | Use of long double type. | | ||
| main.cpp:18:15:18:16 | d5 | Use of long double type. | | ||
| main.cpp:19:15:19:16 | d6 | Use of long double type. | | ||
| main.cpp:22:15:22:16 | d7 | Use of long double type. | | ||
| main.cpp:24:15:24:16 | d8 | Use of long double type. | | ||
| main.cpp:26:15:26:16 | d9 | Use of long double type. | | ||
| main.cpp:28:15:28:17 | d10 | Use of long double type. | | ||
| main.cpp:30:15:30:17 | d11 | Use of long double type. | | ||
| main.cpp:32:15:32:17 | d12 | Use of long double type. | | ||
| main.cpp:34:15:34:17 | d13 | Use of long double type. | | ||
| main.cpp:36:15:36:17 | d14 | Use of long double type. | | ||
| main.cpp:40:15:40:17 | d15 | Use of long double type. | | ||
| main.cpp:40:108:40:110 | d16 | Use of long double type. | | ||
| main.cpp:41:15:41:17 | d17 | Use of long double type. | | ||
| main.cpp:41:113:41:115 | d18 | Use of long double type. | |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.