diff --git a/lua/guard/events.lua b/lua/guard/events.lua index 6b6b6cf0..cc2c839f 100644 --- a/lua/guard/events.lua +++ b/lua/guard/events.lua @@ -16,31 +16,31 @@ end local function create_lspattach_autocmd(fmt_on_save) api.nvim_create_autocmd('LspAttach', { - group = group, - callback = function(args) - local client = vim.lsp.get_client_by_id(args.data.client_id) - ---@diagnostic disable-next-line: need-check-nil - if not client.supports_method('textDocument/formatting') then - return - end - local ft = vim.bo[args.buf].filetype - if not(ft_handler[ft] and ft_handler[ft].format) then - ft_handler(ft):fmt('lsp') - end + group = group, + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + ---@diagnostic disable-next-line: need-check-nil + if not client.supports_method('textDocument/formatting') then + return + end + local ft = vim.bo[args.buf].filetype + if not (ft_handler[ft] and ft_handler[ft].format) then + ft_handler(ft):fmt('lsp') + end - if - fmt_on_save - and #api.nvim_get_autocmds({ - group = group, - event = 'FileType', - pattern = ft, - }) - == 0 - then - format.attach_to_buf(args.buf) - end - end, - }) + if + fmt_on_save + and #api.nvim_get_autocmds({ + group = group, + event = 'FileType', + pattern = ft, + }) + == 0 + then + format.attach_to_buf(args.buf) + end + end, + }) end return { diff --git a/lua/guard/filetype.lua b/lua/guard/filetype.lua index 8174efcb..1b2d6ad7 100644 --- a/lua/guard/filetype.lua +++ b/lua/guard/filetype.lua @@ -44,7 +44,7 @@ local function box() function tbl:env(env) vim.validate({ - env = { env, 'table' } + env = { env, 'table' }, }) if vim.tbl_count(env) == 0 then return self @@ -57,7 +57,7 @@ local function box() tool.env = {} env = vim.tbl_extend('force', vim.uv.os_environ(), env or {}) for k, v in pairs(env) do - tool.env[#tool.env + 1 ] = ('%s=%s'):format(k, tostring(v)) + tool.env[#tool.env + 1] = ('%s=%s'):format(k, tostring(v)) end return self end diff --git a/lua/guard/tools/formatter.lua b/lua/guard/tools/formatter.lua index fd50efc9..83cbfa55 100644 --- a/lua/guard/tools/formatter.lua +++ b/lua/guard/tools/formatter.lua @@ -27,7 +27,7 @@ M['clang-format'] = { M.djhtml = { cmd = 'djhtml', args = { '-' }, - stdin = true + stdin = true, } M.fish_indent = { @@ -78,7 +78,7 @@ M.mixformat = { M.pg_format = { cmd = 'pg_format', - stdin = true + stdin = true, } M.prettier = { @@ -126,7 +126,7 @@ M.swiftformat = { M['swift-format'] = { cmd = 'swift-format', - stdin = true + stdin = true, } M['sql-formatter'] = { diff --git a/lua/guard/tools/linter/shellcheck.lua b/lua/guard/tools/linter/shellcheck.lua index a93cdee0..b69c9a60 100644 --- a/lua/guard/tools/linter/shellcheck.lua +++ b/lua/guard/tools/linter/shellcheck.lua @@ -16,7 +16,7 @@ return { error = 1, warning = 2, info = 3, - style = 4 + style = 4, } local diags = {} @@ -33,5 +33,5 @@ return { end, comments) return diags - end + end, } diff --git a/test/filetype_spec.lua b/test/filetype_spec.lua index 420cdc37..8356199e 100644 --- a/test/filetype_spec.lua +++ b/test/filetype_spec.lua @@ -153,10 +153,18 @@ describe('filetype module', function() end) it('can add extra command arguments', function() - ft('c'):fmt('clang-format'):extra('--verbose'):lint('clang-tidy'):extra('--fix') + ft('c') + :fmt({ + cmd = 'clang-format', + args = '--style=Mozilla', + stdin = true, + }) + :extra('--verbose') + :lint('clang-tidy') + :extra('--fix') same({ cmd = 'clang-format', - args = { '--verbose', '-style=file' }, + args = { '--style=Mozilla', '--verbose' }, stdin = true, }, require('guard.tools.formatter')['clang-format'])