You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/ROOT/pages/styleguide.adoc
+123Lines changed: 123 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,12 @@ The purpose of the Cypher styleguide is to make queries as easy to read as possi
9
9
10
10
For rules and recommendations for naming of labels, relationship types and properties, please see the xref::syntax/naming.adoc[Naming rules and recommendations].
11
11
12
+
The best way to make sure your queries follow the styling rules is to use `cypherfmt`, the official Cypher formatter.
13
+
It is available as part of the https://marketplace.visualstudio.com/items?itemName=neo4j-extensions.neo4j-for-vscode[Neo4j VS Code Extension],
14
+
and as a command line tool through the https://www.npmjs.com/package/@neo4j-cypher/language-support[Neo4j Cypher Language Support npm package].
15
+
16
+
17
+
12
18
[[cypher-styleguide-general-recommendations]]
13
19
== General recommendations
14
20
@@ -115,6 +121,123 @@ WHERE EXISTS { (a)-->(b:B) }
115
121
RETURN a.prop
116
122
----
117
123
124
+
* Limit line length to 80 characters if possible. Line breaks should be applied starting from the outermost group, with each nested group breaking
125
+
until either the line fits or no more line breaks can be inserted. Add two spaces of indentation for each nested broken group.
126
+
127
+
.Bad
128
+
[source, cypher]
129
+
----
130
+
MATCH (n)
131
+
WHERE n.prop <> 'a' AND n.prop <> 'b' AND n.prop <> 'c' AND n.prop <> 'd' AND n.prop <> 'e'
132
+
RETURN n
133
+
----
134
+
135
+
.Good
136
+
[source, cypher]
137
+
----
138
+
MATCH (n)
139
+
WHERE
140
+
n.prop <> 'a' AND
141
+
n.prop <> 'b' AND
142
+
n.prop <> 'c' AND
143
+
n.prop <> 'd' AND
144
+
n.prop <> 'e'
145
+
RETURN n
146
+
----
147
+
148
+
* Start ORDER BY and LIMIT clauses on new lines.
149
+
150
+
.Bad
151
+
[source, cypher]
152
+
----
153
+
MATCH (n)
154
+
RETURN 5 ORDER BY n.prop LIMIT 10
155
+
----
156
+
157
+
.Good
158
+
[source, cypher]
159
+
----
160
+
MATCH (n)
161
+
RETURN 5
162
+
ORDER BY n.prop
163
+
LIMIT 10
164
+
----
165
+
166
+
* A group containing a CASE expression should always split, and each WHEN, ELSE, and END should be put on a new line. Additionally, WHEN and ELSE should add two spaces of indentation.
167
+
168
+
.Bad
169
+
[source, cypher]
170
+
----
171
+
MATCH (n:Person {name: 'Alice'})
172
+
RETURN CASE WHEN n.age >= 18 THEN 'Adult' ELSE 'Minor' END AS ageGroup
173
+
----
174
+
175
+
.Good
176
+
[source, cypher]
177
+
----
178
+
MATCH (n:Person {name: 'Alice'})
179
+
RETURN
180
+
CASE
181
+
WHEN n.age >= 18 THEN 'Adult'
182
+
ELSE 'Minor'
183
+
END AS ageGroup-
184
+
----
185
+
186
+
* Lines that end with a list or map literal and do not fit within the maximum width should leave
187
+
the opening bracket/brace on the previous line and use only two additional spaces of indentation.
188
+
189
+
.Bad
190
+
[source, cypher]
191
+
----
192
+
RETURN
193
+
[
194
+
"Alice",
195
+
"Bob",
196
+
"Charlie",
197
+
"David",
198
+
"Eve",
199
+
"Frank",
200
+
"Grace",
201
+
"Heidi",
202
+
"Ivan",
203
+
"Judy"
204
+
]
205
+
----
206
+
207
+
.Good
208
+
[source, cypher]
209
+
----
210
+
RETURN [
211
+
"Alice",
212
+
"Bob",
213
+
"Charlie",
214
+
"David",
215
+
"Eve",
216
+
"Frank",
217
+
"Grace",
218
+
"Heidi",
219
+
"Ivan",
220
+
"Judy"
221
+
]
222
+
----
223
+
224
+
* A single blank line may be used to separate clauses, queries or comments.
0 commit comments