Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc25018f

Browse files
committed
Re-add DeviationsSuppression.ql
This is required for our reporting scripts.Changes implemented to support reporting of locations andmessages for new deviation formats.
1 parent1e4011f commitc25018f

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

‎cpp/common/src/codingstandards/cpp/deviations/CodeIdentifierDeviation.qll‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,20 @@ class DeviationAttribute extends StdAttribute {
226226

227227
DeviationRecordgetADeviationRecord(){result=record}
228228

229-
pragma[nomagic]
230-
ElementgetASuppressedElement(){
229+
/** Gets the element to which this attribute was applied. */
230+
ElementgetPrimarySuppressedElement(){
231231
result.(Type).getAnAttribute()=this
232232
or
233233
result.(Stmt).getAnAttribute()=this
234234
or
235235
result.(Variable).getAnAttribute()=this
236236
or
237237
result.(Function).getAnAttribute()=this
238+
}
239+
240+
pragma[nomagic]
241+
ElementgetASuppressedElement(){
242+
result=this.getPrimarySuppressedElement()
238243
or
239244
result.(Expr).getEnclosingStmt()=this.getASuppressedElement()
240245
or
@@ -336,26 +341,60 @@ class CodeIdentifierDeviation extends TCodeIndentifierDeviation {
336341
)
337342
}
338343

344+
predicatehasLocationInfo(
345+
stringfilepath,intsuppressedLine,intsuppressedColumn,intendline,intendcolumn
346+
){
347+
exists(CommentcommentMarker|
348+
this=TSingleLineDeviation(_,commentMarker,filepath,suppressedLine)and
349+
suppressedColumn=1and
350+
endline=suppressedLine
351+
|
352+
ifcommentMarkerinstanceofDeviationEndOfLineMarker
353+
thenendcolumn=commentMarker.(DeviationEndOfLineMarker).getLocation().getEndColumn()
354+
else
355+
// Find the last column for a location on the next line
356+
endcolumn=
357+
max(Locationl|
358+
l.hasLocationInfo(filepath, _, _, _, _)and
359+
l.getEndLine()=suppressedLine
360+
|
361+
l.getEndColumn()
362+
)
363+
)
364+
or
365+
this=TMultiLineDeviation(_, _, _,filepath,suppressedLine,endline)and
366+
suppressedColumn=1and
367+
endcolumn=1
368+
or
369+
exists(DeviationAttributeattribute|
370+
this=TCodeIdentifierDeviation(_,attribute)and
371+
attribute
372+
.getPrimarySuppressedElement()
373+
.getLocation()
374+
.hasLocationInfo(filepath,suppressedLine,suppressedColumn,endline,endcolumn)
375+
)
376+
}
377+
339378
stringtoString(){
340379
exists(stringfilepath|
341380
exists(intsuppressedLine|
342381
this=TSingleLineDeviation(_, _,filepath,suppressedLine)and
343382
result=
344-
"Deviationrecord "+getADeviationRecord()+" applied to "+filepath+" Line "+
383+
"Deviationof "+getADeviationRecord().getQuery()+" applied to "+filepath+" Line "+
345384
suppressedLine
346385
)
347386
or
348387
exists(intsuppressedStartLine,intsuppressedEndLine|
349388
this=TMultiLineDeviation(_, _, _,filepath,suppressedStartLine,suppressedEndLine)and
350389
result=
351-
"Deviationrecord "+getADeviationRecord()+" applied to "+filepath+" Line"+
390+
"Deviationof "+getADeviationRecord().getQuery()+" applied to "+filepath+" Line"+
352391
suppressedStartLine+":"+suppressedEndLine
353392
)
354393
)
355394
or
356395
exists(DeviationAttributeattribute|
357396
this=TCodeIdentifierDeviation(_,attribute)and
358-
result="Deviationrecord "+getADeviationRecord()+" applied to "+attribute
397+
result="Deviationof "+getADeviationRecord().getQuery()+" applied to "+attribute
359398
)
360399
}
361400
}

‎cpp/common/src/codingstandards/cpp/deviations/DeviationsSuppression.ql‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ newtype TDeviationScope =
3838
file.getRelativePath().prefix(deviationPath.length())=deviationPath
3939
)
4040
}or
41-
TDeviationRecordCommentScope(DeviationRecorddr,Commentc){c=dr.getACodeIdentifierComment()}
41+
TDeviationRecordCodeIdentiferDeviationScope(DeviationRecorddr,CodeIdentifierDeviationc){
42+
c=dr.getACodeIdentifierDeviation()
43+
}
4244

4345
/** A deviation scope. */
4446
classDeviationScopeextendsTDeviationScope{
@@ -91,10 +93,16 @@ class DeviationRecordFileScope extends DeviationScope, TDeviationRecordFileScope
9193
* A deviation scope derived from a comment corresponding to a "code-identifier" entry for a
9294
* `DeviationRecord`.
9395
*/
94-
classDeviationRecordCommentScopeextendsDeviationScope,TDeviationRecordCommentScope{
95-
privateDeviationRecordgetDeviationRecord(){this=TDeviationRecordCommentScope(result, _)}
96+
classDeviationRecordCommentScopeextendsDeviationScope,
97+
TDeviationRecordCodeIdentiferDeviationScope
98+
{
99+
privateDeviationRecordgetDeviationRecord(){
100+
this=TDeviationRecordCodeIdentiferDeviationScope(result, _)
101+
}
96102

97-
privateCommentgetComment(){this=TDeviationRecordCommentScope(_,result)}
103+
privateCodeIdentifierDeviationgetCodeIdentifierDeviation(){
104+
this=TDeviationRecordCodeIdentiferDeviationScope(_,result)
105+
}
98106

99107
overrideLocatablegetDeviationDefinitionLocation(){result=getDeviationRecord()}
100108

@@ -103,14 +111,11 @@ class DeviationRecordCommentScope extends DeviationScope, TDeviationRecordCommen
103111
overridepredicatehasLocationInfo(
104112
stringfilepath,intstartline,intstartcolumn,intendline,intendcolumn
105113
){
106-
getComment().getLocation().hasLocationInfo(filepath,startline, _,endline,endcolumn)and
107-
startcolumn=1
114+
getCodeIdentifierDeviation()
115+
.hasLocationInfo(filepath,startline,startcolumn,endline,endcolumn)
108116
}
109117

110-
overridestringtoString(){
111-
result=
112-
"Deviation of "+getDeviationRecord().getQuery()+" for comment "+getComment()+"."
113-
}
118+
overridestringtoString(){result=getCodeIdentifierDeviation().toString()}
114119
}
115120

116121
fromDeviationScopedeviationScope

‎cpp/common/test/deviations/deviations_report_deviated/DeviationsSuppression.expected‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| 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-usedfor comment // a-0-4-2-deviation COMPLIANT[DEVIATED]. |
1+
| 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-usedapplied to main.cpp Line 12 |
22
| 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. |
33
| 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. |
44
| file://:0:0:0:0 | (no string representation) | // lgtm[cpp/autosar/useless-assignment] | lgtm[cpp/autosar/useless-assignment] | main.cpp:1:1:14:1 | Deviation of cpp/autosar/useless-assignment for main.cpp. |

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp