Skip to content

Commit 81cc44b

Browse files
author
Jose Alvarez
committed
chore: add stylua config and format
1 parent 585b31d commit 81cc44b

34 files changed

+988
-831
lines changed

lua/null-ls/autocommands.lua

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
local api = vim.api
22

3-
local exec = function(...) api.nvim_exec(..., false) end
3+
local exec = function(...)
4+
api.nvim_exec(..., false)
5+
end
46

57
local M = {}
68

7-
local names = {GROUP = "NullLsAutocommands", REGISTERED = "NullLsRegistered"}
9+
local names = { GROUP = "NullLsAutocommands", REGISTERED = "NullLsRegistered" }
810
M.names = names
911

1012
local register = function(trigger, fn, ft)
@@ -16,18 +18,26 @@ local register = function(trigger, fn, ft)
1618
]], names.GROUP))
1719
end
1820

19-
exec(string.format([[
21+
exec(string.format(
22+
[[
2023
augroup %s
2124
autocmd %s %s lua require'null-ls'.%s
2225
augroup END
23-
]], names.GROUP, trigger, ft or "*", fn))
26+
]],
27+
names.GROUP,
28+
trigger,
29+
ft or "*",
30+
fn
31+
))
2432
end
2533

2634
M.setup = function()
2735
register("BufEnter,FocusGained", "try_attach()")
2836
register("User", "attach_or_refresh()", names.REGISTERED)
2937
end
3038

31-
M.trigger = function(name) vim.cmd("doautocmd User " .. name) end
39+
M.trigger = function(name)
40+
vim.cmd("doautocmd User " .. name)
41+
end
3242

3343
return M

lua/null-ls/builtins/diagnostics.lua

+18-15
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@ local M = {}
77

88
M.write_good = h.make_builtin({
99
method = DIAGNOSTICS,
10-
filetypes = {"markdown"},
10+
filetypes = { "markdown" },
1111
generator_opts = {
1212
command = "write-good",
13-
args = {"--text=$TEXT", "--parse"},
13+
args = { "--text=$TEXT", "--parse" },
1414
format = "line",
15-
check_exit_code = function(code) return code == 0 or code == 255 end,
15+
check_exit_code = function(code)
16+
return code == 0 or code == 255
17+
end,
1618
on_output = function(line, params)
1719
local pos = vim.split(string.match(line, "%d+:%d+"), ":")
1820
local row = pos[1]
1921

2022
local message = string.match(line, ":([^:]+)$")
2123

2224
local col, end_col
23-
local issue = string.match(line, "%b\"\"")
25+
local issue = string.match(line, '%b""')
2426
local issue_line = params.content[tonumber(row)]
2527
if issue and issue_line then
26-
local issue_start, issue_end =
27-
string.find(issue_line, string.match(issue, "([^\"]+)"))
28+
local issue_start, issue_end = string.find(issue_line, string.match(issue, '([^"]+)'))
2829
if issue_start and issue_end then
2930
col = tonumber(issue_start) - 1
3031
end_col = issue_end
@@ -37,23 +38,25 @@ M.write_good = h.make_builtin({
3738
end_col = end_col,
3839
message = message,
3940
severity = 1,
40-
source = "write-good"
41+
source = "write-good",
4142
}
42-
end
43+
end,
4344
},
44-
factory = h.generator_factory
45+
factory = h.generator_factory,
4546
})
4647

4748
M.markdownlint = h.make_builtin({
4849
method = DIAGNOSTICS,
49-
filetypes = {"markdown"},
50+
filetypes = { "markdown" },
5051
generator_opts = {
5152
command = "markdownlint",
52-
args = {"--stdin"},
53+
args = { "--stdin" },
5354
to_stdin = true,
5455
to_stderr = true,
5556
format = "line",
56-
check_exit_code = function(code) return code <= 1 end,
57+
check_exit_code = function(code)
58+
return code <= 1
59+
end,
5760
on_output = function(line, params)
5861
local split = vim.split(line, " ")
5962
local rule = split[2]
@@ -78,11 +81,11 @@ M.markdownlint = h.make_builtin({
7881
end_col = end_col,
7982
message = message,
8083
severity = 1,
81-
source = "markdownlint"
84+
source = "markdownlint",
8285
}
83-
end
86+
end,
8487
},
85-
factory = h.generator_factory
88+
factory = h.generator_factory,
8689
})
8790

8891
return M

lua/null-ls/builtins/formatting.lua

+36-23
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,83 @@ local M = {}
77

88
M.lua_format = h.make_builtin({
99
method = FORMATTING,
10-
filetypes = {"lua"},
10+
filetypes = { "lua" },
1111
generator_opts = {
1212
command = "lua-format",
13-
args = {"--single-quote-to-double-quote", "-i"},
14-
to_stdin = true
13+
args = { "-i" },
14+
to_stdin = true,
1515
},
16-
factory = h.formatter_factory
16+
factory = h.formatter_factory,
1717
})
1818

1919
M.stylua = h.make_builtin({
2020
method = FORMATTING,
21-
filetypes = {"lua"},
22-
generator_opts = {command = "stylua", args = {"-"}, to_stdin = true},
23-
factory = h.formatter_factory
21+
filetypes = { "lua" },
22+
generator_opts = { command = "stylua", args = { "-" }, to_stdin = true },
23+
factory = h.formatter_factory,
2424
})
2525

2626
M.prettier = h.make_builtin({
2727
method = FORMATTING,
2828
filetypes = {
29-
"javascript", "javascriptreact", "typescript", "typescriptreact", "css",
30-
"html", "json", "yaml", "markdown"
29+
"javascript",
30+
"javascriptreact",
31+
"typescript",
32+
"typescriptreact",
33+
"css",
34+
"html",
35+
"json",
36+
"yaml",
37+
"markdown",
3138
},
3239
generator_opts = {
3340
command = "prettier",
34-
args = {"--stdin-filepath", "$FILENAME"},
35-
to_stdin = true
41+
args = { "--stdin-filepath", "$FILENAME" },
42+
to_stdin = true,
3643
},
37-
factory = h.formatter_factory
44+
factory = h.formatter_factory,
3845
})
3946

4047
M.prettier_d_slim = h.make_builtin({
4148
method = FORMATTING,
4249
filetypes = {
43-
"javascript", "javascriptreact", "typescript", "typescriptreact"
50+
"javascript",
51+
"javascriptreact",
52+
"typescript",
53+
"typescriptreact",
4454
},
4555
generator_opts = {
4656
command = "prettier_d_slim",
47-
args = {"--stdin", "--stdin-filepath", "$FILENAME"},
48-
to_stdin = true
57+
args = { "--stdin", "--stdin-filepath", "$FILENAME" },
58+
to_stdin = true,
4959
},
50-
factory = h.formatter_factory
60+
factory = h.formatter_factory,
5161
})
5262

5363
M.eslint_d = h.make_builtin({
5464
method = FORMATTING,
5565
filetypes = {
56-
"javascript", "javascriptreact", "typescript", "typescriptreact"
66+
"javascript",
67+
"javascriptreact",
68+
"typescript",
69+
"typescriptreact",
5770
},
5871
generator_opts = {
5972
command = "eslint_d",
60-
args = {"--fix-to-stdout", "--stdin", "--stdin-filename", "$FILENAME"},
61-
to_stdin = true
73+
args = { "--fix-to-stdout", "--stdin", "--stdin-filename", "$FILENAME" },
74+
to_stdin = true,
6275
},
63-
factory = h.formatter_factory
76+
factory = h.formatter_factory,
6477
})
6578

6679
M.trim_whitespace = h.make_builtin({
6780
method = FORMATTING,
6881
generator_opts = {
6982
command = "awk",
70-
args = {"{ sub(/[ \t]+$/, \"\"); print }"},
71-
to_stdin = true
83+
args = { '{ sub(/[ \t]+$/, ""); print }' },
84+
to_stdin = true,
7285
},
73-
factory = h.formatter_factory
86+
factory = h.formatter_factory,
7487
})
7588

7689
return M

lua/null-ls/builtins/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ local diagnostics = require("null-ls.builtins.diagnostics")
22
local formatting = require("null-ls.builtins.formatting")
33
local test = require("null-ls.builtins.test")
44

5-
return {diagnostics = diagnostics, formatting = formatting, _test = test}
5+
return { diagnostics = diagnostics, formatting = formatting, _test = test }

lua/null-ls/builtins/test.lua

+29-30
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ local M = {}
88

99
M.toggle_line_comment = {
1010
method = methods.internal.CODE_ACTION,
11-
filetypes = {"*"},
11+
filetypes = { "*" },
1212
generator = {
1313
fn = function(params)
1414
local bufnr = api.nvim_get_current_buf()
15-
local commentstring =
16-
api.nvim_buf_get_option(bufnr, "commentstring")
15+
local commentstring = api.nvim_buf_get_option(bufnr, "commentstring")
1716
local raw_commentstring = u.string.replace(commentstring, "%s", "")
1817
local line = params.content[params.row]
1918

@@ -23,28 +22,26 @@ M.toggle_line_comment = {
2322
{
2423
title = "Uncomment line",
2524
action = function()
26-
api.nvim_buf_set_lines(bufnr, params.row - 1,
27-
params.row, false, {
28-
u.string.replace(line, raw_commentstring, "")
25+
api.nvim_buf_set_lines(bufnr, params.row - 1, params.row, false, {
26+
u.string.replace(line, raw_commentstring, ""),
2927
})
30-
end
31-
}
28+
end,
29+
},
3230
}
3331
end
3432

3533
return {
3634
{
3735
title = "Comment line",
3836
action = function()
39-
api.nvim_buf_set_lines(bufnr, params.row - 1,
40-
params.row, false, {
41-
string.format(commentstring, line)
37+
api.nvim_buf_set_lines(bufnr, params.row - 1, params.row, false, {
38+
string.format(commentstring, line),
4239
})
43-
end
44-
}
40+
end,
41+
},
4542
}
46-
end
47-
}
43+
end,
44+
},
4845
}
4946

5047
M.mock_code_action = {
@@ -56,35 +53,37 @@ M.mock_code_action = {
5653
title = "Mock action",
5754
action = function()
5855
print("I am a mock action!")
59-
end
60-
}
56+
end,
57+
},
6158
}
62-
end
59+
end,
6360
},
64-
filetypes = {"lua"}
61+
filetypes = { "lua" },
6562
}
6663

6764
M.slow_code_action = h.make_builtin({
6865
method = methods.internal.CODE_ACTION,
69-
filetypes = {"lua"},
66+
filetypes = { "lua" },
7067
generator_opts = {
7168
command = "bash",
72-
args = {"./test/scripts/sleep-and-echo.sh"},
69+
args = { "./test/scripts/sleep-and-echo.sh" },
7370
timeout = 100,
7471
on_output = function(params, done)
75-
if not params.output then return done() end
72+
if not params.output then
73+
return done()
74+
end
7675

7776
return done({
7877
{
7978
title = "Slow mock action",
8079
action = function()
8180
print("I took too long!")
82-
end
83-
}
81+
end,
82+
},
8483
})
85-
end
84+
end,
8685
},
87-
factory = h.generator_factory
86+
factory = h.generator_factory,
8887
})
8988

9089
M.mock_diagnostics = {
@@ -97,12 +96,12 @@ M.mock_diagnostics = {
9796
row = 1,
9897
message = "There is something wrong with this file!",
9998
severity = 1,
100-
source = "mock-diagnostics"
101-
}
99+
source = "mock-diagnostics",
100+
},
102101
}
103-
end
102+
end,
104103
},
105-
filetypes = {"markdown"}
104+
filetypes = { "markdown" },
106105
}
107106

108107
return M

0 commit comments

Comments
 (0)