From 6905f47b2134d2d3f51e1b82821dd0532f7ceb6c Mon Sep 17 00:00:00 2001 From: Marco Kellershoff <1384938+gorillamoe@users.noreply.github.com> Date: Tue, 13 Aug 2024 00:08:50 +0200 Subject: [PATCH] fix(lint): stylua (#126) --- lua/kulala/config/init.lua | 4 ++-- lua/kulala/inlay/init.lua | 4 ++-- lua/kulala/jumps/init.lua | 4 ++-- lua/kulala/parser/request_variables.lua | 4 ++-- lua/kulala/ui/init.lua | 4 ++-- lua/kulala/ui/winbar.lua | 24 ++++++++++++++++-------- lua/kulala/utils/string.lua | 4 ++-- lua/kulala/utils/table.lua | 9 ++++++--- 8 files changed, 34 insertions(+), 23 deletions(-) diff --git a/lua/kulala/config/init.lua b/lua/kulala/config/init.lua index 6e9f09f..e168233 100644 --- a/lua/kulala/config/init.lua +++ b/lua/kulala/config/init.lua @@ -24,7 +24,7 @@ M.defaults = { ["text/html"] = { ft = "html", formatter = FS.command_exists("xmllint") and { "xmllint", "--format", "--html", "-" } or nil, - pathresolver = nil, + pathresolver = nil, }, }, -- default icons @@ -53,7 +53,7 @@ M.defaults = { "}", }, -- enable winbar - winbar = false; + winbar = false, } M.default_contenttype = { diff --git a/lua/kulala/inlay/init.lua b/lua/kulala/inlay/init.lua index ae2a233..9704a30 100644 --- a/lua/kulala/inlay/init.lua +++ b/lua/kulala/inlay/init.lua @@ -1,4 +1,4 @@ -local NS = vim.api.nvim_create_namespace('jest.nvim') +local NS = vim.api.nvim_create_namespace("jest.nvim") local CONFIG = require("kulala.config") local M = {} @@ -32,7 +32,7 @@ M.show = function(t, linenr) M.clear() local bufnr = vim.api.nvim_get_current_buf() vim.api.nvim_buf_set_extmark(bufnr, NS, linenr - 1, 0, { - virt_text = { { t } } + virt_text = { { t } }, }) end diff --git a/lua/kulala/jumps/init.lua b/lua/kulala/jumps/init.lua index a85711a..fa4dd86 100644 --- a/lua/kulala/jumps/init.lua +++ b/lua/kulala/jumps/init.lua @@ -7,7 +7,7 @@ M.jump_next = function() local _, reqs = PARSER.get_document() local next = PARSER.get_next_request(reqs) if next then - vim.api.nvim_win_set_cursor(0, {next.start_line + 1, 0}) + vim.api.nvim_win_set_cursor(0, { next.start_line + 1, 0 }) end end @@ -16,7 +16,7 @@ M.jump_prev = function() local _, reqs = PARSER.get_document() local prev = PARSER.get_previous_request(reqs) if prev then - vim.api.nvim_win_set_cursor(0, {prev.start_line + 1, 0}) + vim.api.nvim_win_set_cursor(0, { prev.start_line + 1, 0 }) end end diff --git a/lua/kulala/parser/request_variables.lua b/lua/kulala/parser/request_variables.lua index cde2c0f..47b2ee9 100644 --- a/lua/kulala/parser/request_variables.lua +++ b/lua/kulala/parser/request_variables.lua @@ -56,7 +56,7 @@ local function get_body_value_from_path(name, method, subpath) if subpath == "*" then return base_table[method].body end - + if not base_table[method].headers then return nil end @@ -66,7 +66,7 @@ local function get_body_value_from_path(name, method, subpath) return contenttype.pathresolver(base_table[method].body, subpath) elseif type(contenttype.pathresolver) == "table" then local cmd = {} - for k,v in pairs(contenttype.pathresolver) do + for k, v in pairs(contenttype.pathresolver) do if type(v) == "string" then v = string.gsub(v, "{{path}}", subpath) end diff --git a/lua/kulala/ui/init.lua b/lua/kulala/ui/init.lua index 46bcfec..29c76c0 100644 --- a/lua/kulala/ui/init.lua +++ b/lua/kulala/ui/init.lua @@ -176,7 +176,7 @@ M.show_body = function() local body = FS.read_file(GLOBALS.BODY_FILE) local contenttype = INT_PROCESSING.get_config_contenttype() if contenttype.formatter then - body = FORMATTER.format(contenttype.formatter, body) + body = FORMATTER.format(contenttype.formatter, body) end set_buffer_contents(body, contenttype.ft) else @@ -207,7 +207,7 @@ M.show_headers_body = function() local body = FS.read_file(GLOBALS.BODY_FILE) local contenttype = INT_PROCESSING.get_config_contenttype() if contenttype.formatter then - body = FORMATTER.format(contenttype.formatter, body) + body = FORMATTER.format(contenttype.formatter, body) end set_buffer_contents(h .. "\n" .. body, contenttype.ft) else diff --git a/lua/kulala/ui/winbar.lua b/lua/kulala/ui/winbar.lua index da030cb..16eadd4 100644 --- a/lua/kulala/ui/winbar.lua +++ b/lua/kulala/ui/winbar.lua @@ -2,19 +2,19 @@ local CONFIG = require("kulala.config") local M = {} ---set winbar highlight -M.winbar_sethl = function () +M.winbar_sethl = function() vim.api.nvim_set_hl(0, "KulalaTab", { link = "TabLine" }) - vim.api.nvim_set_hl(0, "KulalaTabSel", { link = "TabLineSel"}) + vim.api.nvim_set_hl(0, "KulalaTabSel", { link = "TabLineSel" }) end ---set local key mapping ---@param buf integer|nil Buffer -M.winbar_set_key_mapping = function (buf) +M.winbar_set_key_mapping = function(buf) if buf then - vim.keymap.set('n', 'B', function () + vim.keymap.set("n", "B", function() require("kulala.ui").toggle_headers() end, { silent = true, buffer = buf }) - vim.keymap.set('n', 'H', function () + vim.keymap.set("n", "H", function() require("kulala.ui").toggle_headers() end, { silent = true, buffer = buf }) end @@ -22,12 +22,20 @@ end ---@param win_id integer|nil Window id ---@param view string Body or headers -M.toggle_winbar_tab = function (win_id, view) +M.toggle_winbar_tab = function(win_id, view) if win_id then if view == "body" then - vim.api.nvim_set_option_value("winbar", "%#KulalaTabSel# Body (B) %* %#KulalaTab# Headers (H) %* ", { win = win_id }) + vim.api.nvim_set_option_value( + "winbar", + "%#KulalaTabSel# Body (B) %* %#KulalaTab# Headers (H) %* ", + { win = win_id } + ) elseif view == "headers" then - vim.api.nvim_set_option_value("winbar", "%#KulalaTab# Body (B) %* %#KulalaTabSel# Headers (H) %* ", { win = win_id }) + vim.api.nvim_set_option_value( + "winbar", + "%#KulalaTab# Body (B) %* %#KulalaTabSel# Headers (H) %* ", + { win = win_id } + ) end end end diff --git a/lua/kulala/utils/string.lua b/lua/kulala/utils/string.lua index 7ac58d3..07ead57 100644 --- a/lua/kulala/utils/string.lua +++ b/lua/kulala/utils/string.lua @@ -20,7 +20,7 @@ M.remove_newline = function(str) end M.url_encode = function(str) - if (str) then + if str then str = string.gsub(str, "\n", "\r\n") str = string.gsub(str, "([^%w._~-])", function(c) return string.format("%%%02X", string.byte(c)) @@ -30,7 +30,7 @@ M.url_encode = function(str) end M.url_decode = function(str) - if (str) then + if str then str = string.gsub(str, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end) diff --git a/lua/kulala/utils/table.lua b/lua/kulala/utils/table.lua index 7e94807..8c4541b 100644 --- a/lua/kulala/utils/table.lua +++ b/lua/kulala/utils/table.lua @@ -6,8 +6,12 @@ M.slice = function(tbl, first, last) -- Adjust for out-of-bound indices first = first or 1 last = last or #tbl - if first < 1 then first = 1 end - if last > #tbl then last = #tbl end + if first < 1 then + first = 1 + end + if last > #tbl then + last = #tbl + end -- Extract the slice for i = first, last do @@ -17,5 +21,4 @@ M.slice = function(tbl, first, last) return sliced end - return M