feat(ci): add lua static analyzer (#438)

This commit is contained in:
yetone 2024-09-01 17:04:33 +08:00 committed by GitHub
parent 8dd5db8923
commit 55c85692bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 21 deletions

View File

@ -1,4 +1,4 @@
name: Stylua Check name: CI
on: on:
push: push:
@ -9,7 +9,8 @@ on:
- main - main
jobs: jobs:
format: stylua:
name: Check Lua style
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -18,3 +19,13 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
version: latest version: latest
args: --check ./lua/ 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/

View File

@ -100,9 +100,6 @@ local conflict_middle = "^======="
local conflict_end = "^>>>>>>>" local conflict_end = "^>>>>>>>"
local conflict_ancestor = "^|||||||" 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> --- @return table<string, ConflictBufferCache>
@ -340,12 +337,6 @@ local function register_cursor_move_events(bufnr)
Config.diff.mappings.prev, Config.diff.mappings.prev,
Config.diff.mappings.next 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, { show_keybinding_hint_extmark_id = api.nvim_buf_set_extmark(bufnr, KEYBINDING_NAMESPACE, lnum - 1, -1, {
hl_group = "Keyword", hl_group = "Keyword",
@ -642,14 +633,14 @@ function M.choose(side)
vim.defer_fn(function() vim.defer_fn(function()
local start = api.nvim_buf_get_mark(0, "<")[1] local start = api.nvim_buf_get_mark(0, "<")[1]
local finish = 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 left = pos.current.range_start >= start - 1
local right = pos.incoming.range_end <= finish + 1 local right = pos.incoming.range_end <= finish + 1
return left and right return left and right
end) end)
while position ~= nil do while position ~= nil do
M.process_position(bufnr, side, position, false) 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 left = pos.current.range_start >= start - 1
local right = pos.incoming.range_end <= finish + 1 local right = pos.incoming.range_end <= finish + 1
return left and right return left and right
@ -674,7 +665,7 @@ function M.choose(side)
while pos ~= nil do while pos ~= nil do
M.process_position(bufnr, "theirs", pos, false) M.process_position(bufnr, "theirs", pos, false)
---@diagnostic disable-next-line: unused-local ---@diagnostic disable-next-line: unused-local
pos = find_position(bufnr, function(line, pos) pos = find_position(bufnr, function(line, pos_)
return true return true
end) end)
end end

View File

@ -634,7 +634,7 @@ function Sidebar:render_input()
---@diagnostic disable-next-line: undefined-field ---@diagnostic disable-next-line: undefined-field
if _G.MiniIcons ~= nil then if _G.MiniIcons ~= nil then
---@diagnostic disable-next-line: undefined-global ---@diagnostic disable-next-line: undefined-global
icon, _, _ = MiniIcons.get("filetype", filetype) icon, _, _ = MiniIcons.get("filetype", filetype) -- luacheck: ignore
else else
local ok, devicons = pcall(require, "nvim-web-devicons") local ok, devicons = pcall(require, "nvim-web-devicons")
if ok then if ok then
@ -1571,14 +1571,13 @@ function Sidebar:create_input()
end end
function Sidebar:get_selected_code_size() function Sidebar:get_selected_code_size()
local selected_code_lines_count = 0
local selected_code_max_lines_count = 10 local selected_code_max_lines_count = 10
local selected_code_size = 0 local selected_code_size = 0
if self.code.selection ~= nil then if self.code.selection ~= nil then
local selected_code_lines = vim.split(self.code.selection.content, "\n") 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) selected_code_size = math.min(selected_code_lines_count, selected_code_max_lines_count)
end end

View File

@ -190,7 +190,7 @@ function M.get_visual_selection_and_range()
start_line, end_line = end_line, start_line start_line, end_line = end_line, start_line
start_col, end_col = end_col, start_col start_col, end_col = end_col, start_col
end end
local content = "" local content = "" -- luacheck: ignore
local range = Range.new({ line = start_line, col = start_col }, { line = end_line, col = end_col }) local range = Range.new({ line = start_line, col = start_col }, { line = end_line, col = end_col })
-- Check if it's a single-line selection -- Check if it's a single-line selection
if start_line == end_line then if start_line == end_line then
@ -221,11 +221,11 @@ end
---Wrapper around `api.nvim_buf_get_lines` which defaults to the current buffer ---Wrapper around `api.nvim_buf_get_lines` which defaults to the current buffer
---@param start integer ---@param start integer
---@param _end integer ---@param end_ integer
---@param buf integer? ---@param buf integer?
---@return string[] ---@return string[]
function M.get_buf_lines(start, _end, buf) function M.get_buf_lines(start, end_, buf)
return api.nvim_buf_get_lines(buf or 0, start, _end, false) return api.nvim_buf_get_lines(buf or 0, start, end_, false)
end end
---Get cursor row and column as (1, 0) based ---Get cursor row and column as (1, 0) based