From 55c85692bf2e05b4789e2fcd1ccb5ab234f28e36 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 1 Sep 2024 17:04:33 +0800 Subject: [PATCH] feat(ci): add lua static analyzer (#438) --- .github/workflows/{stylua.yaml => ci.yaml} | 15 +++++++++++++-- lua/avante/diff.lua | 15 +++------------ lua/avante/sidebar.lua | 5 ++--- lua/avante/utils/init.lua | 8 ++++---- 4 files changed, 22 insertions(+), 21 deletions(-) rename .github/workflows/{stylua.yaml => ci.yaml} (53%) diff --git a/.github/workflows/stylua.yaml b/.github/workflows/ci.yaml similarity index 53% rename from .github/workflows/stylua.yaml rename to .github/workflows/ci.yaml index f2180f9b5..e48f3db73 100644 --- a/.github/workflows/stylua.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: Stylua Check +name: CI on: push: @@ -9,7 +9,8 @@ on: - main jobs: - format: + stylua: + name: Check Lua style runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -18,3 +19,13 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} version: latest args: --check ./lua/ + luacheck: + name: Lint Lua + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Luacheck linter + uses: lunarmodules/luacheck@v1 + with: + args: ./lua/ diff --git a/lua/avante/diff.lua b/lua/avante/diff.lua index 7fc1ebd3f..1eaaf9501 100644 --- a/lua/avante/diff.lua +++ b/lua/avante/diff.lua @@ -100,9 +100,6 @@ local conflict_middle = "^=======" local conflict_end = "^>>>>>>>" local conflict_ancestor = "^|||||||" -local DEFAULT_CURRENT_BG_COLOR = 4218238 -- #405d7e -local DEFAULT_INCOMING_BG_COLOR = 3229523 -- #314753 -local DEFAULT_ANCESTOR_BG_COLOR = 6824314 -- #68217A -----------------------------------------------------------------------------// --- @return table @@ -340,12 +337,6 @@ local function register_cursor_move_events(bufnr) Config.diff.mappings.prev, Config.diff.mappings.next ) - local win_width = api.nvim_win_get_width(0) - local col = win_width - #hint - math.ceil(win_width * 0.3) - 4 - - if col < 0 then - col = 0 - end show_keybinding_hint_extmark_id = api.nvim_buf_set_extmark(bufnr, KEYBINDING_NAMESPACE, lnum - 1, -1, { hl_group = "Keyword", @@ -642,14 +633,14 @@ function M.choose(side) vim.defer_fn(function() local start = api.nvim_buf_get_mark(0, "<")[1] local finish = api.nvim_buf_get_mark(0, ">")[1] - local position = find_position(bufnr, function(line, pos) + local position = find_position(bufnr, function(_, pos) local left = pos.current.range_start >= start - 1 local right = pos.incoming.range_end <= finish + 1 return left and right end) while position ~= nil do M.process_position(bufnr, side, position, false) - position = find_position(bufnr, function(line, pos) + position = find_position(bufnr, function(_, pos) local left = pos.current.range_start >= start - 1 local right = pos.incoming.range_end <= finish + 1 return left and right @@ -674,7 +665,7 @@ function M.choose(side) while pos ~= nil do M.process_position(bufnr, "theirs", pos, false) ---@diagnostic disable-next-line: unused-local - pos = find_position(bufnr, function(line, pos) + pos = find_position(bufnr, function(line, pos_) return true end) end diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index a4b25425a..209d364ca 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -634,7 +634,7 @@ function Sidebar:render_input() ---@diagnostic disable-next-line: undefined-field if _G.MiniIcons ~= nil then ---@diagnostic disable-next-line: undefined-global - icon, _, _ = MiniIcons.get("filetype", filetype) + icon, _, _ = MiniIcons.get("filetype", filetype) -- luacheck: ignore else local ok, devicons = pcall(require, "nvim-web-devicons") if ok then @@ -1571,14 +1571,13 @@ function Sidebar:create_input() end function Sidebar:get_selected_code_size() - local selected_code_lines_count = 0 local selected_code_max_lines_count = 10 local selected_code_size = 0 if self.code.selection ~= nil then local selected_code_lines = vim.split(self.code.selection.content, "\n") - selected_code_lines_count = #selected_code_lines + local selected_code_lines_count = #selected_code_lines selected_code_size = math.min(selected_code_lines_count, selected_code_max_lines_count) end diff --git a/lua/avante/utils/init.lua b/lua/avante/utils/init.lua index f11ebb276..ca9372635 100644 --- a/lua/avante/utils/init.lua +++ b/lua/avante/utils/init.lua @@ -190,7 +190,7 @@ function M.get_visual_selection_and_range() start_line, end_line = end_line, start_line start_col, end_col = end_col, start_col end - local content = "" + local content = "" -- luacheck: ignore local range = Range.new({ line = start_line, col = start_col }, { line = end_line, col = end_col }) -- Check if it's a single-line selection if start_line == end_line then @@ -221,11 +221,11 @@ end ---Wrapper around `api.nvim_buf_get_lines` which defaults to the current buffer ---@param start integer ----@param _end integer +---@param end_ integer ---@param buf integer? ---@return string[] -function M.get_buf_lines(start, _end, buf) - return api.nvim_buf_get_lines(buf or 0, start, _end, false) +function M.get_buf_lines(start, end_, buf) + return api.nvim_buf_get_lines(buf or 0, start, end_, false) end ---Get cursor row and column as (1, 0) based