Skip to content

Commit d8dbff9

Browse files
authored
docs: Add JavaScript part into the style guide (#6607)
* docs: Add JavaScript part into the style guide * Make dimensions go first
1 parent 47f63e7 commit d8dbff9

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

docs/content/Guides/Style-Guide.mdx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,53 @@ cubes:
255255
sub_query: true
256256
```
257257

258+
## JavaScript style guide
259+
260+
* Indent with 2 spaces.
261+
* Don't use trailing semicolons.
262+
* Don't use trailing commas after last elements of arrays and objects.
263+
* Use a new line to separate list items that are objects, where appropriate.
264+
* Make sure lines are no longer than 80 characters.
265+
* If quotes are needed around a string, use [backticks][wiki-backtick].
266+
267+
### Example YAML
268+
269+
```javascript
270+
cube(`users`, {
271+
sql_table: `public.users`,
272+
273+
dimensions: {
274+
id: {
275+
sql: `id`,
276+
type: `number`,
277+
primary_key: true
278+
},
279+
280+
city: {
281+
sql: `city`,
282+
type: `string`
283+
},
284+
285+
lifetime_value: {
286+
sql: `${line_items.total_amount}`,
287+
type: `number`,
288+
sub_query: true
289+
}
290+
},
291+
292+
measures: {
293+
count: {
294+
type: `count`
295+
},
296+
297+
total_orders_amount: {
298+
sql: `${lifetime_value}`,
299+
type: `sum`
300+
}
301+
}
302+
})
303+
```
304+
258305
## Credits
259306

260307
This style guide was inspired in part by:
@@ -275,4 +322,5 @@ This style guide was inspired in part by:
275322
[ref-view-params]: /schema/reference/view#parameters
276323
[self-yaml]: #yaml-style-guide
277324
[self-sql]: #sql-style-guide
278-
[wiki-cte]: https://en.wikipedia.org/wiki/Hierarchical_and_recursive_queries_in_SQL#Common_table_expression
325+
[wiki-cte]: https://en.wikipedia.org/wiki/Hierarchical_and_recursive_queries_in_SQL#Common_table_expression
326+
[wiki-backtick]: https://en.wikipedia.org/wiki/Backtick

0 commit comments

Comments
 (0)