Skip to content

Commit 9aa83d7

Browse files
authored
Merge pull request github#12575 from egregius313/egregius313/ql/dataflow-naming-convention-check
QL: add a check to enforce naming convention for new `DataFlow::ConfigSig` modules
2 parents 1c06aff + d743b31 commit 9aa83d7

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @id ql/dataflow-module-naming-convention
3+
* @name Data flow configuration module naming
4+
* @description The name of a data flow configuration module should end in `Config`
5+
* @kind problem
6+
* @problem.severity warning
7+
* @precision high
8+
*/
9+
10+
import ql
11+
12+
/**
13+
* The DataFlow configuration module signatures (`ConfigSig`, `StateConfigSig`, `FullStateConfigSig`).
14+
*/
15+
class ConfigSig extends TypeExpr {
16+
ConfigSig() { this.getClassName() = ["ConfigSig", "StateConfigSig", "FullStateConfigSig"] }
17+
}
18+
19+
/**
20+
* A module that implements a data flow configuration.
21+
*/
22+
class DataFlowConfigModule extends Module {
23+
DataFlowConfigModule() { this.getImplements(_) instanceof ConfigSig }
24+
}
25+
26+
/**
27+
* A file that is part of the internal dataflow library or dataflow library
28+
* tests.
29+
*/
30+
class DataFlowInternalFile extends File {
31+
DataFlowInternalFile() {
32+
this.getRelativePath()
33+
.matches([
34+
"%/dataflow/internal/%", "%/dataflow/new/internal/%",
35+
"%/ql/test/library-tests/dataflow/%"
36+
])
37+
}
38+
}
39+
40+
from DataFlowConfigModule m
41+
where
42+
not m.getFile() instanceof DataFlowInternalFile and
43+
not m.getName().matches("%Config")
44+
select m, "Modules implementing a data flow configuration should end in `Config`."
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| Test.qll:11:8:11:25 | Module EmptyConfiguration | Modules implementing a data flow configuration should end in `Config`. |
2+
| Test.qll:18:8:18:16 | Module EmptyFlow | Modules implementing a data flow configuration should end in `Config`. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/style/DataFlowConfigModuleNaming.ql
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import semmle.code.java.dataflow.DataFlow
2+
3+
// GOOD - ends with "Config"
4+
module EmptyConfig implements DataFlow::ConfigSig {
5+
predicate isSource(DataFlow::Node src) { none() }
6+
7+
predicate isSink(DataFlow::Node sink) { none() }
8+
}
9+
10+
// BAD - does not end with "Config"
11+
module EmptyConfiguration implements DataFlow::ConfigSig {
12+
predicate isSource(DataFlow::Node src) { none() }
13+
14+
predicate isSink(DataFlow::Node sink) { none() }
15+
}
16+
17+
// BAD - does not end with "Config"
18+
module EmptyFlow implements DataFlow::ConfigSig {
19+
predicate isSource(DataFlow::Node src) { none() }
20+
21+
predicate isSink(DataFlow::Node sink) { none() }
22+
}

0 commit comments

Comments
 (0)