Skip to content

Commit

Permalink
feat(ci): add lua static analyzer (yetone#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone authored Sep 1, 2024
1 parent 8dd5db8 commit 55c8569
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/stylua.yaml → .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Stylua Check
name: CI

on:
push:
Expand All @@ -9,7 +9,8 @@ on:
- main

jobs:
format:
stylua:
name: Check Lua style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -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/
15 changes: 3 additions & 12 deletions lua/avante/diff.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ConflictBufferCache>
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lua/avante/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions lua/avante/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 55c8569

Please sign in to comment.