Skip to content

Commit 21a4432

Browse files
committed
updated rule metadata based on PR feedback
1 parent c8b550b commit 21a4432

5 files changed

Lines changed: 18 additions & 13 deletions

File tree

c/misra/src/rules/RULE-16-2/NestSwitchLabelInSwitchStatement.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* @id c/misra/nest-switch-label-in-switch-statement
3-
* @name RULE-16-2: A switch label shall only be used when the most closely-enclosing compound statement is the body of
4-
* @description Nested switch labels cause undefined behaviour.
3+
* @name RULE-16-2: Nested switch labels shall not be used.
4+
* @description Nested switch labels can lead to unstructured code.
55
* @kind problem
66
* @precision very-high
7-
* @problem.severity error
7+
* @problem.severity recommendation
88
* @tags external/misra/id/rule-16-2
99
* maintainability
1010
* readability

cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
138138
isPreprocessor6QueryMetadata(query, queryId, ruleId, category) or
139139
isSideEffects1QueryMetadata(query, queryId, ruleId, category) or
140140
isSideEffects2QueryMetadata(query, queryId, ruleId, category) or
141+
isStatements1QueryMetadata(query, queryId, ruleId, category) or
141142
isStrings1QueryMetadata(query, queryId, ruleId, category) or
142143
isStrings2QueryMetadata(query, queryId, ruleId, category) or
143144
isStrings3QueryMetadata(query, queryId, ruleId, category) or

cpp/common/src/codingstandards/cpp/exclusions/c/Statements1.qll

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,42 @@ newtype Statements1Query =
99
TEverySwitchShallHaveDefaultLabelQuery() or
1010
TDefaultNotFirstOrLastOfSwitchQuery()
1111

12-
predicate isStatements1QueryMetadata(Query query, string queryId, string ruleId) {
12+
predicate isStatements1QueryMetadata(Query query, string queryId, string ruleId, string category) {
1313
query =
1414
// `Query` instance for the `nestSwitchLabelInSwitchStatement` query
1515
Statements1Package::nestSwitchLabelInSwitchStatementQuery() and
1616
queryId =
1717
// `@id` for the `nestSwitchLabelInSwitchStatement` query
1818
"c/misra/nest-switch-label-in-switch-statement" and
19-
ruleId = "RULE-16-2"
19+
ruleId = "RULE-16-2" and
20+
category = "required"
2021
or
2122
query =
2223
// `Query` instance for the `breakShallTerminateSwitchClause` query
2324
Statements1Package::breakShallTerminateSwitchClauseQuery() and
2425
queryId =
2526
// `@id` for the `breakShallTerminateSwitchClause` query
2627
"c/misra/break-shall-terminate-switch-clause" and
27-
ruleId = "RULE-16-3"
28+
ruleId = "RULE-16-3" and
29+
category = "required"
2830
or
2931
query =
3032
// `Query` instance for the `everySwitchShallHaveDefaultLabel` query
3133
Statements1Package::everySwitchShallHaveDefaultLabelQuery() and
3234
queryId =
3335
// `@id` for the `everySwitchShallHaveDefaultLabel` query
3436
"c/misra/every-switch-shall-have-default-label" and
35-
ruleId = "RULE-16-4"
37+
ruleId = "RULE-16-4" and
38+
category = "required"
3639
or
3740
query =
3841
// `Query` instance for the `defaultNotFirstOrLastOfSwitch` query
3942
Statements1Package::defaultNotFirstOrLastOfSwitchQuery() and
4043
queryId =
4144
// `@id` for the `defaultNotFirstOrLastOfSwitch` query
4245
"c/misra/default-not-first-or-last-of-switch" and
43-
ruleId = "RULE-16-5"
46+
ruleId = "RULE-16-5" and
47+
category = "required"
4448
}
4549

4650
module Statements1Package {

cpp/common/src/codingstandards/cpp/rules/nestedlabelinswitch/NestedLabelInSwitch.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ abstract class NestedLabelInSwitchSharedQuery extends Query { }
1111
Query getQuery() { result instanceof NestedLabelInSwitchSharedQuery }
1212

1313
query predicate problems(
14-
SwitchCase case, string message, Location caseLocation, string caseLabel, SwitchStmt switch,
14+
SwitchCase nestedCase, string message, SwitchCase case, string caseLabel, SwitchStmt switch,
1515
string switchLabel
1616
) {
1717
not isExcluded(nestedCase, getQuery()) and
18-
switch.getASwitchCase() = nestedCase and
18+
switch.getASwitchCase() = case and
1919
not nestedCase.getParentStmt() = switch.getChildStmt() and
2020
nestedCase = case and
2121
message =

rule_packages/c/Statements1.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
},
77
"queries": [
88
{
9-
"description": "Nested switch labels cause undefined behaviour.",
9+
"description": "Nested switch labels can lead to unstructured code.",
1010
"kind": "problem",
11-
"name": "A switch label shall only be used when the most closely-enclosing compound statement is the body of",
11+
"name": "Nested switch labels shall not be used.",
1212
"precision": "very-high",
13-
"severity": "error",
13+
"severity": "recommendation",
1414
"short_name": "NestSwitchLabelInSwitchStatement",
1515
"shared_implementation_short_name": "NestedLabelInSwitch",
1616
"tags": [

0 commit comments

Comments
 (0)