77import cpp
88import semmle.code.cpp.XML
99import codingstandards.cpp.exclusions.RuleMetadata
10+ import codingstandards.cpp.Config
1011
1112predicate applyDeviationsAtQueryLevel ( ) {
1213 not exists ( CodingStandardsReportDeviatedAlerts reportDeviatedResults |
@@ -15,26 +16,6 @@ predicate applyDeviationsAtQueryLevel() {
1516 )
1617}
1718
18- /** A `coding-standards.xml` configuration file (usually generated from an YAML configuration file). */
19- class CodingStandardsFile extends XMLFile {
20- CodingStandardsFile ( ) {
21- this .getBaseName ( ) = "coding-standards.xml" and
22- // Must be within the users source code.
23- exists ( this .getRelativePath ( ) )
24- }
25- }
26-
27- /** A "Coding Standards" configuration file */
28- class CodingStandardsConfig extends XMLElement {
29- CodingStandardsConfig ( ) {
30- any ( CodingStandardsFile csf ) .getARootElement ( ) = this and
31- this .getName ( ) = "codingstandards"
32- }
33-
34- /** Gets a deviation record for this configuration. */
35- DeviationRecord getADeviationRecord ( ) { result = getAChild ( ) .( DeviationRecords ) .getAChild ( ) }
36- }
37-
3819/** An element which tells the analysis whether to report deviated results. */
3920class CodingStandardsReportDeviatedAlerts extends XMLElement {
4021 CodingStandardsReportDeviatedAlerts ( ) {
@@ -44,19 +25,13 @@ class CodingStandardsReportDeviatedAlerts extends XMLElement {
4425}
4526
4627/** A container of deviation records. */
47- class DeviationRecords extends XMLElement {
48- DeviationRecords ( ) {
49- getParent ( ) instanceof CodingStandardsConfig and
50- hasName ( "deviations" )
51- }
28+ class DeviationRecords extends CodingStandardsConfigSection {
29+ DeviationRecords ( ) { hasName ( "deviations" ) }
5230}
5331
5432/** A container for the deviation permits records. */
55- class DeviationPermits extends XMLElement {
56- DeviationPermits ( ) {
57- getParent ( ) instanceof CodingStandardsConfig and
58- hasName ( "deviation-permits" )
59- }
33+ class DeviationPermits extends CodingStandardsConfigSection {
34+ DeviationPermits ( ) { hasName ( "deviation-permits" ) }
6035}
6136
6237/** A deviation permit record, that is specified by a permit identifier */
@@ -357,6 +332,13 @@ class DeviationRecord extends XMLElement {
357332 hasPermitId ( ) and
358333 not hasADeviationPermit ( ) and
359334 result = "There is no deviation permit with id `" + getPermitId ( ) + "`."
335+ or
336+ exists ( Query q | q .getQueryId ( ) = getQueryId ( ) |
337+ not q .getEffectiveCategory ( ) .permitsDeviation ( ) and
338+ result =
339+ "The deviation is applied to a query with the rule category '" +
340+ q .getEffectiveCategory ( ) .toString ( ) + "' that does not permit a deviation."
341+ )
360342 }
361343
362344 /** Holds if the deviation record is valid */
0 commit comments