From ad23da054cc9da9ea1892f70c516e4efc6bf67ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Fri, 29 Apr 2022 09:46:45 +0200 Subject: [PATCH] Add luacheck to main workflow --- .github/workflows/main.yml | 8 ++++++ symlinks/config/nvim/.luacheckrc | 8 ++++++ symlinks/config/nvim/init.lua | 2 +- .../config/nvim/lua/fugitive_extensions.lua | 2 +- symlinks/config/nvim/lua/lsp/diagnostic.lua | 4 +++ .../config/nvim/lua/lsp/server_config.lua | 2 +- .../nvim/lua/vim_rest_console_extensions.lua | 14 +++++------ symlinks/config/nvim/plugin/dap.lua | 2 +- symlinks/config/nvim/plugin/rest.lua | 25 +++++++++++-------- 9 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 symlinks/config/nvim/.luacheckrc diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1a64c5f..931ed77 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -54,3 +54,11 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} args: --check . + luacheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run luacheck + uses: lunarmodules/luacheck@v0.26.0 + with: + args: symlinks/config/nvim diff --git a/symlinks/config/nvim/.luacheckrc b/symlinks/config/nvim/.luacheckrc new file mode 100644 index 0000000..ee6cae2 --- /dev/null +++ b/symlinks/config/nvim/.luacheckrc @@ -0,0 +1,8 @@ +-- vim: ft=lua tw=80 +globals = { + "vim", +} + +exclude_files = { + "plugin/packer_compiled.lua", +} diff --git a/symlinks/config/nvim/init.lua b/symlinks/config/nvim/init.lua index 6c28aa4..f1f8d3d 100644 --- a/symlinks/config/nvim/init.lua +++ b/symlinks/config/nvim/init.lua @@ -3,7 +3,7 @@ if require("init.first_load")() then end -- Allow `require('impatient')` to fail, in case plugins are not yet installed -_ = pcall(require, "impatient") +local _ = pcall(require, "impatient") vim.cmd([[filetype plugin indent on]]) diff --git a/symlinks/config/nvim/lua/fugitive_extensions.lua b/symlinks/config/nvim/lua/fugitive_extensions.lua index 1df98c3..70cd54c 100644 --- a/symlinks/config/nvim/lua/fugitive_extensions.lua +++ b/symlinks/config/nvim/lua/fugitive_extensions.lua @@ -14,7 +14,7 @@ local function get_pr_url(...) -- Remove prefix if it is available, for some of common git services local common_services = { "github.com", "bitbucket.org", "gitlab.com" } - for k, service in pairs(common_services) do + for _, service in pairs(common_services) do if string.find(origin_url, service, 1, true) then -- Common mechanism for managing multiple SSH keys origin_url = string.gsub(origin_url, "://.*" .. service, "://" .. service) diff --git a/symlinks/config/nvim/lua/lsp/diagnostic.lua b/symlinks/config/nvim/lua/lsp/diagnostic.lua index f307fd1..cf7d0c3 100644 --- a/symlinks/config/nvim/lua/lsp/diagnostic.lua +++ b/symlinks/config/nvim/lua/lsp/diagnostic.lua @@ -23,6 +23,9 @@ null_ls.setup({ -- Lua null_ls.builtins.formatting.stylua, + null_ls.builtins.diagnostics.luacheck.with({ + extra_args = { "--config", vim.fn.stdpath("config") .. "/.luacheckrc" }, + }), -- Dart null_ls.builtins.formatting.dart_format, @@ -41,6 +44,7 @@ null_ls.setup({ null_ls.builtins.formatting.trim_whitespace, null_ls.builtins.hover.dictionary, null_ls.builtins.code_actions.gitsigns, + null_ls.builtins.code_actions.refactoring, }, on_attach = function(client) if client.resolved_capabilities.document_formatting then diff --git a/symlinks/config/nvim/lua/lsp/server_config.lua b/symlinks/config/nvim/lua/lsp/server_config.lua index fee9854..0933a85 100644 --- a/symlinks/config/nvim/lua/lsp/server_config.lua +++ b/symlinks/config/nvim/lua/lsp/server_config.lua @@ -4,7 +4,7 @@ local M = {} -M.on_attach = function(client, bufnr) +M.on_attach = function(_, bufnr) vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" -- Lsp keymaps diff --git a/symlinks/config/nvim/lua/vim_rest_console_extensions.lua b/symlinks/config/nvim/lua/vim_rest_console_extensions.lua index f029941..35fc9da 100644 --- a/symlinks/config/nvim/lua/vim_rest_console_extensions.lua +++ b/symlinks/config/nvim/lua/vim_rest_console_extensions.lua @@ -9,7 +9,7 @@ end -- Opens up a new tab if current buffer is not empty local function new_tab_if_needed() - if vim.api.nvim_buf_get_name("%") ~= "" then + if vim.api.nvim_buf_get_name(0) ~= "" then -- Current buffer is not empty, open up a new tab vim.cmd("tabnew") end @@ -42,9 +42,9 @@ function M.open_scratch_rest_console() end -- Opens up a rest console which can be saved -- cached by name -function M.open_cached_rest_console(...) - local name = select(1, ...) - if select("#", ...) == 0 then +function M.open_cached_rest_console(args) + local name = args[0] or args[1] + if not name then name = require("common.projects").get_project_id() end open_cached_rest_console(name) @@ -57,9 +57,9 @@ function M.open_named_cached_rest_console(name) end -- Opens up a rest console based on local file path -function M.open_local_rest_console(...) - local file = select(1, ...) - if select("#", ...) == 0 then +function M.open_local_rest_console(args) + local file = args[0] or args[1] + if not file then file = "default" end open_rest_console(file) diff --git a/symlinks/config/nvim/plugin/dap.lua b/symlinks/config/nvim/plugin/dap.lua index b09784d..b14dd65 100644 --- a/symlinks/config/nvim/plugin/dap.lua +++ b/symlinks/config/nvim/plugin/dap.lua @@ -6,7 +6,7 @@ local dap = require("dap") vim.api.nvim_create_autocmd("FileType", { pattern = "dap-repl", - callback = function(args) + callback = function(_) require("dap.ext.autocompl").attach() end, }) diff --git a/symlinks/config/nvim/plugin/rest.lua b/symlinks/config/nvim/plugin/rest.lua index 8328c52..fcec2e0 100644 --- a/symlinks/config/nvim/plugin/rest.lua +++ b/symlinks/config/nvim/plugin/rest.lua @@ -2,15 +2,18 @@ -- - Vim REST Console setup and extra commands - ------------------------------------------------------------------------------- -vim.cmd( - [[command! -nargs=0 ScratchRestConsole :lua require('vim_rest_console_extensions').open_scratch_rest_console()]] -) -vim.cmd( - [[command! -nargs=? RestConsole :lua require('vim_rest_console_extensions').open_cached_rest_console()]] -) -vim.cmd( - [[command! -nargs=? RestConsoleLocal :lua require('vim_rest_console_extensions').open_local_rest_console()]] -) -vim.cmd( - [[command! -nargs=1 RestConsoleCached :lua require('vim_rest_console_extensions').open_named_cached_rest_console()]] +local vim_rest_console_extensions = require("vim_rest_console_extensions") +vim.api.nvim_create_user_command( + "ScratchRestConsole", + vim_rest_console_extensions.open_scratch_rest_console, + { nargs = 0 } ) +vim.api.nvim_create_user_command("RestConsole", function(args) + vim_rest_console_extensions.open_cached_rest_console(args.fargs) +end, { nargs = "?" }) +vim.api.nvim_create_user_command("RestConsoleLocal", function(args) + vim_rest_console_extensions.open_local_rest_console(args.fargs) +end, { nargs = "?" }) +vim.api.nvim_create_user_command("RestConsoleCached", function(args) + vim_rest_console_extensions.open_named_cached_rest_console(args.fargs[0] or args.fargs[1]) +end, { nargs = 1 })