-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathAV Rule 148.ql
More file actions
25 lines (23 loc) · 866 Bytes
/
AV Rule 148.ql
File metadata and controls
25 lines (23 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* @name Use of integer where enum is preferred
* @description Enumeration types should be used instead of integer types (and constants) to select from a limited series of choices.
* @kind problem
* @problem.severity warning
* @precision medium
* @id cpp/integer-used-for-enum
* @tags maintainability
* readability
* language-features
* external/jsf
*/
import cpp
// flag switch statements where every non-default case dispatches on an integer constant
from SwitchStmt s
where
forex(SwitchCase sc | sc = s.getASwitchCase() and not sc instanceof DefaultCase |
sc.getExpr().(VariableAccess).getTarget().isConst()
) and
// Allow switch on character types
not s.getExpr().getUnspecifiedType() instanceof CharType
select s,
"Enumeration types should be used instead of integers to select from a limited series of choices."