Skip to content

Commit 0026763

Browse files
committed
Implementation of check for DataFlow naming convention
1 parent dce81cf commit 0026763

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 not part of the internal dataflow library.
28+
*/
29+
class DataFlowInternalFile extends File {
30+
DataFlowInternalFile() {
31+
this.getRelativePath()
32+
.matches([
33+
"%/dataflow/internal/%", "%/dataflow/new/internal/%",
34+
"%/ql/test/library-tests/dataflow/%"
35+
])
36+
}
37+
}
38+
39+
from DataFlowConfigModule m
40+
where
41+
not m.getFile() instanceof DataFlowInternalFile and
42+
not m.getName().matches("%Config")
43+
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)