| 1 |
--- |
| 2 |
layout: default |
| 3 |
title: Tooling |
| 4 |
--- |
| 5 |
|
| 6 |
<div class="hgroup"> |
| 7 |
<div class="hgroup-inline"> |
| 8 |
<div class="panel"> |
| 9 |
<h1 id="tooling">Tooling</h1> |
| 10 |
</div> |
| 11 |
<div style="clear: both"></div> |
| 12 |
</div> |
| 13 |
</div> |
| 14 |
|
| 15 |
<div class="hgroup"> |
| 16 |
<div class="hgroup-inline"> |
| 17 |
<div class="panel"> |
| 18 |
<p> |
| 19 |
Aside from the Jsonnet interpreters (which execute the Jsonnet code) these additional |
| 20 |
software tools allow you to get the most out of Jsonnet: |
| 21 |
</p> |
| 22 |
<ul> |
| 23 |
<li>Formatter, for automatically fixing stylistic problems</li> |
| 24 |
<li>Linter, for drawing attention to red flags that cannot be fixed automatically</li> |
| 25 |
<li>Bazel rules, for config generation as part of your build system</li> |
| 26 |
<li> |
| 27 |
Editor integration for syntax highlighting and other features |
| 28 |
<ul> |
| 29 |
<li> |
| 30 |
<a href="https://github.com/grafana/jsonnet-language-server">Language |
| 31 |
Server Protocol (LSP) server</a> |
| 32 |
(maintained by <a href="https://grafana.com">Grafana Labs</a>) |
| 33 |
</li> |
| 34 |
<li> |
| 35 |
<a href="https://github.com/grafana/vscode-jsonnet">vscode</a> |
| 36 |
(maintained by <a href="https://grafana.com">Grafana Labs</a>) |
| 37 |
</li> |
| 38 |
<li> |
| 39 |
<a href="https://github.com/google/vim-jsonnet">Vim</a> |
| 40 |
</li> |
| 41 |
<li> |
| 42 |
<a href="https://github.com/google/codemirror-mode-jsonnet">Codemirror,</a> |
| 43 |
the editor widget used by this website |
| 44 |
</li> |
| 45 |
<li> |
| 46 |
<a href="https://github.com/google/language-jsonnet">Atom</a> |
| 47 |
</li> |
| 48 |
<li> |
| 49 |
<a href="https://github.com/gburiola/sublime-jsonnet-syntax">Sublime</a> |
| 50 |
</li> |
| 51 |
<li> |
| 52 |
<a href="https://databricks.com/">Databricks</a> maintain an <a |
| 53 |
href="https://github.com/databricks/intellij-jsonnet">IntelliJ</a> |
| 54 |
plugin with jump to imported files and local variables |
| 55 |
</li> |
| 56 |
<li> |
| 57 |
Another <a href="https://github.com/zzehring/intellij-jsonnet">Intellij</a> |
| 58 |
with support for Grafana's LSP server |
| 59 |
</li> |
| 60 |
<li> |
| 61 |
An <a href="https://github.com/tminor/jsonnet-mode">Emacs mode</a> is also |
| 62 |
available |
| 63 |
</li> |
| 64 |
</ul> |
| 65 |
</li> |
| 66 |
</ul> |
| 67 |
</div> |
| 68 |
<div style="clear: both"></div> |
| 69 |
</div> |
| 70 |
</div> |
| 71 |
|
| 72 |
<div class="hgroup"> |
| 73 |
<div class="hgroup-inline"> |
| 74 |
<div class="panel"> |
| 75 |
<h2 id="formatter">Formatter Demo</h2> |
| 76 |
</div> |
| 77 |
<div style="clear: both"></div> |
| 78 |
</div> |
| 79 |
</div> |
| 80 |
|
| 81 |
<div class="hgroup"> |
| 82 |
<div class="hgroup-inline"> |
| 83 |
<div class="panel"> |
| 84 |
<p> |
| 85 |
The formatter is a command-line utility bundled with the C++ build of Jsonnet. You can |
| 86 |
reformat files in place as so: |
| 87 |
</p> |
| 88 |
<pre>jsonnetfmt -i *.jsonnet</pre> |
| 89 |
<p> |
| 90 |
It will manage indenting and horizontal spacing within a line and remove excess vertical |
| 91 |
spacing. It will convert string literals, comments, fields and some operators into |
| 92 |
canonical forms as well as enforcing trailing commas. It will sort imports and remove |
| 93 |
excess nesting of parentheses. It will break lines in certain places. |
| 94 |
</p> |
| 95 |
</div> |
| 96 |
<div style="clear: both"></div> |
| 97 |
</div> |
| 98 |
</div> |
| 99 |
|
| 100 |
<div class="inverse hgroup"> |
| 101 |
<div class=hgroup-inline> |
| 102 |
<div class="tab-window-input" id="formatter-input"> |
| 103 |
<div class="tab-header"> |
| 104 |
</div> |
| 105 |
<textarea id=input-jsonnet> |
| 106 |
# Edit me! |
| 107 |
local b = import "b.libsonnet"; # comment |
| 108 |
local a = import "a.libsonnet"; |
| 109 |
|
| 110 |
local f(x,y)=x+y; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
local Template = {z: "foo"}; |
| 115 |
|
| 116 |
Template + { |
| 117 |
"f": ((3)) , |
| 118 |
"g g": |
| 119 |
f(4,2), |
| 120 |
arr: [[ |
| 121 |
1, 2, |
| 122 |
], |
| 123 |
3, |
| 124 |
] |
| 125 |
} |
| 126 |
</textarea> |
| 127 |
</div> |
| 128 |
<div class="bigarrow">➡</div> |
| 129 |
<div class="tab-window-output" id="formatter-output"> |
| 130 |
<div class="tab-header"> |
| 131 |
<div class=selected onclick="tab_click(this, 'formatter-output')">output.jsonnet</div> |
| 132 |
</div> |
| 133 |
<textarea readonly class="selected code-json" id="formatter-output"> |
| 134 |
// Edit me! |
| 135 |
local a = import 'a.libsonnet'; |
| 136 |
local b = import 'b.libsonnet'; // comment |
| 137 |
|
| 138 |
local f(x, y) = x + y; |
| 139 |
|
| 140 |
|
| 141 |
local Template = { z: 'foo' }; |
| 142 |
|
| 143 |
Template { |
| 144 |
f: (3), |
| 145 |
'g g': |
| 146 |
f(4, 2), |
| 147 |
arr: [ |
| 148 |
[ |
| 149 |
1, |
| 150 |
2, |
| 151 |
], |
| 152 |
3, |
| 153 |
], |
| 154 |
} |
| 155 |
</textarea> |
| 156 |
</div> |
| 157 |
<script> |
| 158 |
fmt_demo( |
| 159 |
'formatter-input', |
| 160 |
'input-jsonnet', |
| 161 |
'input.jsonnet', |
| 162 |
'formatter-output', |
| 163 |
); |
| 164 |
</script> |
| 165 |
<div style="clear: both"></div> |
| 166 |
</div> |
| 167 |
</div> |
| 168 |
|
| 169 |
<div class="hgroup"> |
| 170 |
<div class="hgroup-inline"> |
| 171 |
<div class="panel"> |
| 172 |
<h2 id="formatter">Linter</h2> |
| 173 |
</div> |
| 174 |
<div style="clear: both"></div> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
|
| 178 |
<div class="hgroup"> |
| 179 |
<div class="hgroup-inline"> |
| 180 |
<div class="panel"> |
| 181 |
<p> |
| 182 |
The linter is another command-line utility bundled with the Go build of Jsonnet. You can |
| 183 |
check files as so: |
| 184 |
</p> |
| 185 |
<pre>jsonnet-lint file.jsonnet</pre> |
| 186 |
<p> |
| 187 |
Currently it is rudimentary and only checks for unused variables. |
| 188 |
</p> |
| 189 |
</div> |
| 190 |
<div style="clear: both"></div> |
| 191 |
</div> |
| 192 |
</div> |
| 193 |
|
| 194 |
<div class="hgroup"> |
| 195 |
<div class="hgroup-inline"> |
| 196 |
<div class="panel"> |
| 197 |
<h2 id="formatter">Bazel Jsonnet Rules</h2> |
| 198 |
</div> |
| 199 |
<div style="clear: both"></div> |
| 200 |
</div> |
| 201 |
</div> |
| 202 |
|
| 203 |
<div class="hgroup"> |
| 204 |
<div class="hgroup-inline"> |
| 205 |
<div class="panel"> |
| 206 |
<p> |
| 207 |
<a href="https://github.com/bazelbuild/rules_jsonnet">Jsonnet rules</a>, provides the following rules to your Bazel build: |
| 208 |
</p> |
| 209 |
<pre>jsonnet_library</pre> |
| 210 |
<pre>jsonnet_to_json</pre> |
| 211 |
<pre>jsonnet_to_json_test</pre> |
| 212 |
<div style="clear: both"></div> |
| 213 |
</div> |
| 214 |
</div> |