Skip to content

Commit f50a4dd

Browse files
authored
Merge pull request #11617 from github/smowton/admin/docs-river-example-codeql-style
Docs: Make river-crossing example comply with the CodeQL style guide
2 parents d196704 + 37b2b0a commit f50a4dd

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

docs/codeql/writing-codeql-queries/river-answer-1-path.ql

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66
/** A possible cargo item. */
77
class Cargo extends string {
88
Cargo() {
9-
this = "Nothing" or
10-
this = "Goat" or
11-
this = "Cabbage" or
12-
this = "Wolf"
9+
this = ["Nothing", "Goat", "Cabbage", "Wolf"]
1310
}
1411
}
1512

16-
/** One of two shores. */
13+
/** A shore, named either `Left` or `Right`. */
1714
class Shore extends string {
1815
Shore() {
1916
this = "Left" or
@@ -93,7 +90,7 @@ class Cargo extends string {
9390
// Reachable by first following pathSoFar and then ferrying cargo
9491
exists(string pathSoFar, string visitedStatesSoFar, Cargo cargo |
9592
result = this.reachesVia(pathSoFar, visitedStatesSoFar).safeFerry(cargo) and
96-
not exists(int i | i = visitedStatesSoFar.indexOf(result)) and // resulting state is not visited yet
93+
not exists(visitedStatesSoFar.indexOf(result)) and // resulting state is not visited yet
9794
visitedStates = visitedStatesSoFar + "_" + result and
9895
path = pathSoFar + ",\nthen " + cargo + " is ferried " + result.towards()
9996
)

docs/codeql/writing-codeql-queries/river-answer-2-abstract-class.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class Shore extends string {
154154
State reachesVia(string path) {
155155
exists(string pathSoFar |
156156
result = this.reachesVia(pathSoFar).transition() and
157-
not exists(int i | i = pathSoFar.indexOf(result.toString())) and
157+
not exists(pathSoFar.indexOf(result.toString())) and
158158
path = pathSoFar + "\n↓\n" + result
159159
)
160160
}
@@ -169,7 +169,7 @@ class Shore extends string {
169169
}
170170

171171
override State reachesVia(string path) {
172-
path = this + "\n↓\n" + result and result = transition()
172+
path = this + "\n↓\n" + result and result = this.transition()
173173
or
174174
result = super.reachesVia(path)
175175
}

docs/codeql/writing-codeql-queries/river-answer-3-datatypes.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class State extends TState {
118118
State reachesVia(string path) {
119119
exists(string pathSoFar |
120120
result = this.reachesVia(pathSoFar).transition() and
121-
not exists(int i | i = pathSoFar.indexOf(result.toString())) and
121+
not exists(pathSoFar.indexOf(result.toString())) and
122122
path = pathSoFar + "\n" + result
123123
)
124124
}
@@ -133,7 +133,7 @@ class InitialState extends State {
133133
}
134134

135135
override State reachesVia(string path) {
136-
path = this + "\n" + result and result = transition()
136+
path = this + "\n" + result and result = this.transition()
137137
or
138138
result = super.reachesVia(path)
139139
}

0 commit comments

Comments
 (0)