Skip to content

Commit 9b66c33

Browse files
author
Jose Alvarez
authored
chore: set up cbfmt and format documentation (#981)
1 parent 47c0499 commit 9b66c33

File tree

10 files changed

+83
-72
lines changed

10 files changed

+83
-72
lines changed

.cbfmt.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[languages]
2+
lua = ["stylua -s -"]

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ local markdownlint = {
154154
local success = code <= 1
155155

156156
if not success then
157-
-- can be noisy for things that run often (e.g. diagnostics), but can
158-
-- be useful for things that run on demand (e.g. formatting)
159-
print(stderr)
157+
-- can be noisy for things that run often (e.g. diagnostics), but can
158+
-- be useful for things that run on demand (e.g. formatting)
159+
print(stderr)
160160
end
161161

162162
return success
@@ -231,7 +231,7 @@ use a plugin like [trouble.nvim](https://github.com/folke/trouble.nvim).
231231

232232
```lua
233233
require("null-ls").setup({
234-
debug = true
234+
debug = true,
235235
})
236236
```
237237

doc/BUILTINS.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -708,12 +708,11 @@ Shader to SPIR-V compiler.
708708
#### Usage
709709

710710
```lua
711-
local sources = {
712-
null_ls.builtins.diagnostics.glslc.with({
713-
extra_args = { "--target-env=opengl" } -- use opengl instead of vulkan1.0
714-
})
715-
}
716-
711+
local sources = {
712+
null_ls.builtins.diagnostics.glslc.with({
713+
extra_args = { "--target-env=opengl" }, -- use opengl instead of vulkan1.0
714+
}),
715+
}
717716
```
718717

719718
#### Defaults
@@ -1344,9 +1343,9 @@ A SQL linter and auto-formatter for Humans
13441343

13451344
```lua
13461345
local sources = {
1347-
null_ls.builtins.diagnostics.sqlfluff.with({
1348-
extra_args = {"--dialect", "postgres"} -- change to your dialect
1349-
})
1346+
null_ls.builtins.diagnostics.sqlfluff.with({
1347+
extra_args = { "--dialect", "postgres" }, -- change to your dialect
1348+
}),
13501349
}
13511350
```
13521351

@@ -3175,9 +3174,9 @@ A SQL linter and auto-formatter for Humans
31753174

31763175
```lua
31773176
local sources = {
3178-
null_ls.builtins.formatting.sqlfluff.with({
3179-
extra_args = {"--dialect", "postgres"} -- change to your dialect
3180-
})
3177+
null_ls.builtins.formatting.sqlfluff.with({
3178+
extra_args = { "--dialect", "postgres" }, -- change to your dialect
3179+
}),
31813180
}
31823181
```
31833182

doc/BUILTIN_CONFIG.md

+21-20
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@ null-ls exposes built-ins on `null_ls.builtins`, which contains the following
1919
groups of sources:
2020

2121
```lua
22+
local null_ls = require("null-ls")
23+
2224
-- code action sources
23-
null_ls.builtins.code_actions
25+
local code_actions = null_ls.builtins.code_actions
2426

2527
-- diagnostic sources
26-
null_ls.builtins.diagnostics
28+
local diagnostics = null_ls.builtins.diagnostics
2729

2830
-- formatting sources
29-
null_ls.builtins.formatting
31+
local formatting = null_ls.builtins.formatting
3032

3133
-- hover sources
32-
null_ls.builtins.hover
34+
local hover = null_ls.builtins.hover
3335

3436
-- completion sources
35-
null_ls.builtins.completion
37+
local completion = null_ls.builtins.completion
3638
```
3739

3840
You can then register sources by passing a `sources` list into your `setup`
@@ -115,9 +117,9 @@ To add more arguments to a source's defaults, use `extra_args`:
115117
```lua
116118
local sources = {
117119
null_ls.builtins.formatting.shfmt.with({
118-
extra_args = { "-i", "2", "-ci" }
119-
})
120-
}
120+
extra_args = { "-i", "2", "-ci" },
121+
}),
122+
}
121123
```
122124

123125
You can also override a source's arguments entirely using `with({ args = your_args })`.
@@ -151,9 +153,9 @@ operating system variables.
151153
```lua
152154
local sources = {
153155
null_ls.builtins.formatting.prettierd.with({
154-
env = {
155-
PRETTIERD_DEFAULT_CONFIG = vim.fn.expand "~/.config/nvim/utils/linter-config/.prettierrc.json",
156-
}
156+
env = {
157+
PRETTIERD_DEFAULT_CONFIG = vim.fn.expand("~/.config/nvim/utils/linter-config/.prettierrc.json"),
158+
},
157159
}),
158160
}
159161
```
@@ -181,8 +183,8 @@ local sources = {
181183
null_ls.builtins.diagnostics.eslint_d.with({
182184
-- ignore prettier warnings from eslint-plugin-prettier
183185
filter = function(diagnostic)
184-
return diagnostic.code != "prettier/prettier"
185-
end
186+
return diagnostic.code ~= "prettier/prettier"
187+
end,
186188
}),
187189
}
188190
```
@@ -196,7 +198,7 @@ setting `diagnostics_format`:
196198
local sources = {
197199
-- will show code and source name
198200
null_ls.builtins.diagnostics.shellcheck.with({
199-
diagnostics_format = "[#{c}] #{m} (#{s})"
201+
diagnostics_format = "[#{c}] #{m} (#{s})",
200202
}),
201203
}
202204
```
@@ -222,8 +224,7 @@ diagnostic.
222224
local sources = {
223225
null_ls.builtins.diagnostics.write_good.with({
224226
diagnostics_postprocess = function(diagnostic)
225-
diagnostic.severity = diagnostic.message:find("really")
226-
and vim.diagnostic.severity["ERROR"]
227+
diagnostic.severity = diagnostic.message:find("really") and vim.diagnostic.severity["ERROR"]
227228
or vim.diagnostic.severity["WARN"]
228229
end,
229230
}),
@@ -264,7 +265,7 @@ local sources = {
264265
cwd = function(params)
265266
-- falls back to root if return value is nil
266267
return params.root:match("my-special-project") and "my-special-cwd"
267-
end
268+
end,
268269
}),
269270
}
270271
```
@@ -279,7 +280,7 @@ set a different `timeout`:
279280
local sources = {
280281
null_ls.builtins.formatting.prettier.with({
281282
-- milliseconds
282-
timeout = 10000
283+
timeout = 10000,
283284
}),
284285
}
285286
```
@@ -303,7 +304,7 @@ to `false`:
303304
```lua
304305
local sources = {
305306
null_ls.builtins.formatting.phpstan.with({
306-
to_temp_file = false
307+
to_temp_file = false,
307308
}),
308309
}
309310
```
@@ -344,7 +345,7 @@ if the command is not available on your `$PATH`:
344345
```lua
345346
local sources = {
346347
null_ls.builtins.formatting.prettier.with({
347-
command = "/path/to/prettier"
348+
command = "/path/to/prettier",
348349
}),
349350
}
350351
```

doc/CONTRIBUTING.md

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
[busted](https://github.com/Olivine-Labs/busted). If you're unsure how to
3232
write tests for your PR, please let us know and we can help.
3333

34+
- To format Lua code blocks in our Markdown documentation, we recommend
35+
[cbfmt](https://github.com/lukas-reineke/cbfmt), which is available as a
36+
null-ls built-in.
37+
3438
## Contributing built-ins
3539

3640
- Check if there is an open issue requesting the built-in you are adding and

doc/MAIN.md

+29-23
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,12 @@ All return values are **required** unless specified as optional.
281281
#### Code Actions
282282

283283
```lua
284-
return { {
285-
title, -- string
286-
action, -- function (callback with no arguments)
287-
} }
284+
return {
285+
{
286+
title, -- string
287+
action, -- function (callback with no arguments)
288+
},
289+
}
288290
```
289291

290292
Once generated, null-ls stores code action results in its internal state and
@@ -298,18 +300,20 @@ safe to call any API function.
298300

299301
```lua
300302
-- null-ls assumes ranges are 1-indexed, so sources should offset if not
301-
return { {
302-
row, -- number, optional (defaults to first line)
303-
col, -- number, optional (defaults to beginning of line)
304-
end_row, -- number, optional (defaults to row)
305-
end_col, -- number, optional (defaults to end of line),
306-
source, -- string, optional (defaults to "null-ls")
307-
code, -- number, optional
308-
message, -- string
309-
severity, -- 1 (error), 2 (warning), 3 (information), 4 (hint)
310-
filename, -- string, optional (requires generator.multiple_files)
311-
bufnr, -- number, optional (requires generator.multiple_files)
312-
} }
303+
return {
304+
{
305+
row, -- number, optional (defaults to first line)
306+
col, -- number, optional (defaults to beginning of line)
307+
end_row, -- number, optional (defaults to row)
308+
end_col, -- number, optional (defaults to end of line),
309+
source, -- string, optional (defaults to "null-ls")
310+
code, -- number, optional
311+
message, -- string
312+
severity, -- 1 (error), 2 (warning), 3 (information), 4 (hint)
313+
filename, -- string, optional (requires generator.multiple_files)
314+
bufnr, -- number, optional (requires generator.multiple_files)
315+
},
316+
}
313317
```
314318

315319
null-ls generates diagnostics in response to LSP notifications and publishes
@@ -329,13 +333,15 @@ described in [CONFIG](./CONFIG.md).
329333
#### Formatting
330334

331335
```lua
332-
return { {
333-
row, -- number, optional (see diagnostics for defaults)
334-
col, -- number, optional
335-
end_row, -- number, optional
336-
end_col, -- number, optional
337-
text, -- string
338-
} }
336+
return {
337+
{
338+
row, -- number, optional (see diagnostics for defaults)
339+
col, -- number, optional
340+
end_row, -- number, optional
341+
end_col, -- number, optional
342+
text, -- string
343+
},
344+
}
339345
```
340346

341347
null-ls applies formatting results to the matching buffer and, depending on the

doc/SOURCES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ local example_source = {
3030
return "I am a source!"
3131
end,
3232
},
33-
id = 1
33+
id = 1,
3434
}
3535
```
3636

lua/null-ls/builtins/diagnostics/glslc.lua

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ return h.make_builtin({
1313
[[the `--target-env` can be specified in `extra_args`. Defaults to vulkan1.0. Check `man glslc` for more possible targets environments.]],
1414
},
1515
usage = [[
16-
local sources = {
17-
null_ls.builtins.diagnostics.glslc.with({
18-
extra_args = { "--target-env=opengl" } -- use opengl instead of vulkan1.0
19-
})
20-
}
21-
]],
16+
local sources = {
17+
null_ls.builtins.diagnostics.glslc.with({
18+
extra_args = { "--target-env=opengl" }, -- use opengl instead of vulkan1.0
19+
}),
20+
}]],
2221
},
2322
method = DIAGNOSTICS,
2423
filetypes = { "glsl" },

lua/null-ls/builtins/diagnostics/sqlfluff.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ return helpers.make_builtin({
1111
},
1212
usage = [[
1313
local sources = {
14-
null_ls.builtins.diagnostics.sqlfluff.with({
15-
extra_args = {"--dialect", "postgres"} -- change to your dialect
16-
})
14+
null_ls.builtins.diagnostics.sqlfluff.with({
15+
extra_args = { "--dialect", "postgres" }, -- change to your dialect
16+
}),
1717
}]],
1818
},
1919
method = null_ls.methods.DIAGNOSTICS,

lua/null-ls/builtins/formatting/sqlfluff.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ return h.make_builtin({
1313
},
1414
usage = [[
1515
local sources = {
16-
null_ls.builtins.formatting.sqlfluff.with({
17-
extra_args = {"--dialect", "postgres"} -- change to your dialect
18-
})
16+
null_ls.builtins.formatting.sqlfluff.with({
17+
extra_args = { "--dialect", "postgres" }, -- change to your dialect
18+
}),
1919
}]],
2020
},
2121
method = FORMATTING,

0 commit comments

Comments
 (0)