From 3774ac0eba34db6b4dbe9ac07fbd1533ee1cb3c1 Mon Sep 17 00:00:00 2001 From: ray-x Date: Wed, 27 Jul 2022 02:21:58 +1000 Subject: [PATCH] lint --- lua/go.lua | 1 - lua/go/alt_getopt.lua | 2 +- lua/go/coverage.lua | 6 +-- lua/go/format.lua | 2 +- lua/go/gopls.lua | 2 +- lua/go/impl.lua | 4 +- lua/go/mockgen.lua | 6 +-- lua/go/utils.lua | 4 +- lua/snips/all.lua | 6 +-- lua/tests/go_fillstruct_spec.lua | 2 +- lua/tests/go_fmt_spec.lua | 6 +-- lua/tests/go_impl_spec.lua | 2 +- lua/tests/go_make_spec.lua | 2 +- lua/tests/go_tags_spec.lua | 17 +++++---- lua/tests/go_test_spec.lua | 2 +- lua/tests/go_ts_node_spec.lua | 7 ++-- selene.toml | 9 ++++- stylua.toml | 1 + vim.toml | 57 ---------------------------- vim.yml | 65 ++++++++++++++++++++++++++++++++ 20 files changed, 110 insertions(+), 93 deletions(-) delete mode 100644 vim.toml create mode 100644 vim.yml diff --git a/lua/go.lua b/lua/go.lua index ef47c47..89016ac 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -30,7 +30,6 @@ _GO_NVIM_CFG = { -- when lsp_cfg is true lsp_on_client_start = nil, -- it is a function with same signature as on_attach, will be called at end of -- on_attach and allows you override some setup - lsp_format_on_save = 1, lsp_document_formatting = true, -- set to true: use gopls to format -- false if you want to use other formatter tool(e.g. efm, nulls) diff --git a/lua/go/alt_getopt.lua b/lua/go/alt_getopt.lua index fc1462e..a566af2 100644 --- a/lua/go/alt_getopt.lua +++ b/lua/go/alt_getopt.lua @@ -176,7 +176,7 @@ function test_arg(arg) } local opts - local optarg + local optarg, unparsed local optind arg = arg or { "-t", "-r", "-c", "path1", "-g", "unit,integration", "path" } -- arg = arg or { "-t", "-r", "-c", "-g", "unit,integration" } diff --git a/lua/go/coverage.lua b/lua/go/coverage.lua index e1b3717..1f4277b 100644 --- a/lua/go/coverage.lua +++ b/lua/go/coverage.lua @@ -293,9 +293,9 @@ M.run = function(...) if vim.fn.filereadable(covfn) == 0 then vim.notify("no cov file specified or existed, will rerun coverage test", vim.lsp.log_levels.INFO) else - local cov = M.read_cov(covfn) - vim.notify(string.format("total coverage: %d%%", cov.total_covered / cov.total_lines * 100)) - return cov + local test_coverage = M.read_cov(covfn) + vim.notify(string.format("total coverage: %d%%", test_coverage.total_covered / test_coverage.total_lines * 100)) + return test_coverage end end if load == "-t" then diff --git a/lua/go/format.lua b/lua/go/format.lua index 592e1f6..38dbe2d 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -163,7 +163,7 @@ M.goimport = function(...) -- golines base formatter is goimports local a = {} if goimport == "golines" then - local a = vim.deepcopy(goimport_args) + a = vim.deepcopy(goimport_args) end run(a, buf, goimport) end diff --git a/lua/go/gopls.lua b/lua/go/gopls.lua index 5649e2b..820733d 100644 --- a/lua/go/gopls.lua +++ b/lua/go/gopls.lua @@ -95,7 +95,7 @@ M.list_imports = function(path) local resp = cmds.list_imports({ URI = path, }) - result = {} + local result = {} for _, v in pairs(resp) do if v.result then for k, val in pairs(v.result) do diff --git a/lua/go/impl.lua b/lua/go/impl.lua index 38f171c..743c3b9 100644 --- a/lua/go/impl.lua +++ b/lua/go/impl.lua @@ -54,7 +54,7 @@ local run = function(...) utils.log(#arg, arg) local recv = get_type_name() - local iface = get_interface_name() + iface = get_interface_name() if #arg == 0 then iface = vfn.input("Impl: generating method stubs for interface: ") @@ -82,7 +82,7 @@ local run = function(...) if iface ~= nil then -- " i.e: ':GoImpl s TypeName' recv = select(1, ...) - recv_type = select(2, ...) + local recv_type = select(2, ...) recv = string.lower(recv) .. " *" .. recv_type else recv_name = select(1, ...) diff --git a/lua/go/mockgen.lua b/lua/go/mockgen.lua index bf0c648..6bc5794 100644 --- a/lua/go/mockgen.lua +++ b/lua/go/mockgen.lua @@ -41,7 +41,7 @@ local run = function(opts) local optarg, _, reminder = getopt.get_opts(args, short_opts, long_opts) local mockgen_cmd = { mockgen } - utils.log(arg) + utils.log(arg, reminder) local sep = require("go.utils").sep() @@ -93,7 +93,7 @@ local run = function(opts) utils.log(mockgen_cmd) -- vim.cmd("normal! $%") -- do a bracket match. changed to treesitter - local opts = { + local mock_opts = { on_exit = function(code, signal, data) if code ~= 0 or signal ~= 0 then -- there will be error popup from runner @@ -112,7 +112,7 @@ local run = function(opts) end, } local runner = require("go.runner") - runner.run(mockgen_cmd, opts) + runner.run(mockgen_cmd, mock_opts) return mockgen_cmd end diff --git a/lua/go/utils.lua b/lua/go/utils.lua index e736618..6872032 100644 --- a/lua/go/utils.lua +++ b/lua/go/utils.lua @@ -712,7 +712,7 @@ function util.run_command(cmd, ...) return result end -util.debounce = function(fn, duration) +util.debounce = function(func, duration) local timer = vim.loop.new_timer() local function inner(args) timer:stop() @@ -720,7 +720,7 @@ util.debounce = function(fn, duration) duration, 0, vim.schedule_wrap(function() - fn(args) + func(args) end) ) end diff --git a/lua/snips/all.lua b/lua/snips/all.lua index 3703cda..b380709 100644 --- a/lua/snips/all.lua +++ b/lua/snips/all.lua @@ -8,7 +8,7 @@ local aws = vim.split( "," ) local function filter(prefix) - result = { ls.t("") } + local result = { ls.t("") } print("filter", prefix) if #prefix == 1 then for _, v in pairs(aws) do @@ -87,8 +87,8 @@ ls.add_snippets("all", { if not tonumber(lines) then lines = 1 end - local l = vim.split(utils.lorem(), ", ") - return vim.list_slice(l, lines) + local lor = vim.split(utils.lorem(), ", ") + return vim.list_slice(lor, lines) end) ), }) diff --git a/lua/tests/go_fillstruct_spec.lua b/lua/tests/go_fillstruct_spec.lua index 97984a8..d129857 100644 --- a/lua/tests/go_fillstruct_spec.lua +++ b/lua/tests/go_fillstruct_spec.lua @@ -8,7 +8,7 @@ local cur_dir = vim.fn.expand("%:p:h") describe("should run fillstruct", function() vim.cmd([[packadd go.nvim]]) - status = require("plenary.reload").reload_module("go.nvim") + require("plenary.reload").reload_module("go.nvim") require("go").setup({ verbose = true }) -- _GO_NVIM_CFG.fillstruct = "fillstruct" it("should run fillstruct", function() diff --git a/lua/tests/go_fmt_spec.lua b/lua/tests/go_fmt_spec.lua index f463781..f72fb8b 100644 --- a/lua/tests/go_fmt_spec.lua +++ b/lua/tests/go_fmt_spec.lua @@ -5,7 +5,7 @@ local busted = require("plenary/busted") describe("should run gofmt", function() -- vim.fn.readfile('minimal.vim') -- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name) - status = require("plenary.reload").reload_module("go.nvim") + require("plenary.reload").reload_module("go.nvim") it("should run fmt", function() local name = vim.fn.tempname() .. ".go" print("tmp:" .. name) @@ -33,7 +33,7 @@ describe("should run gofmt", function() print("fmt" .. fmt) vim.fn.assert_equal(fmt, expected) eq(expected, fmt) - local cmd = "bd! " .. name + cmd = "bd! " .. name vim.cmd(cmd) end) it("should run fmt sending from buffer", function() @@ -63,7 +63,7 @@ describe("should run gofmt", function() print("fmt" .. fmt) vim.fn.assert_equal(fmt, expected) eq(expected, fmt) - local cmd = "bd! " .. name + cmd = "bd! " .. name vim.cmd(cmd) end) it("should run import from file", function() diff --git a/lua/tests/go_impl_spec.lua b/lua/tests/go_impl_spec.lua index bddfa6d..f59a808 100644 --- a/lua/tests/go_impl_spec.lua +++ b/lua/tests/go_impl_spec.lua @@ -15,7 +15,7 @@ describe("should run impl", function() vim.cmd([[packadd go.nvim]]) vim.cmd([[packadd nvim-treesitter]]) - status = require("plenary.reload").reload_module("go.nvim") + local status = require("plenary.reload").reload_module("go.nvim") status = require("plenary.reload").reload_module("nvim-treesitter/nvim-treesitter") require("go").setup({ verbose = true }) diff --git a/lua/tests/go_make_spec.lua b/lua/tests/go_make_spec.lua index 762aaec..bb6029a 100644 --- a/lua/tests/go_make_spec.lua +++ b/lua/tests/go_make_spec.lua @@ -5,7 +5,7 @@ local busted = require("plenary/busted") describe("should run func make", function() -- vim.fn.readfile('minimal.vim') -- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name) - status = require("plenary.reload").reload_module("go.nvim") + require("plenary.reload").reload_module("go.nvim") it("should make function", function() -- -- go.nvim may not auto loaded diff --git a/lua/tests/go_tags_spec.lua b/lua/tests/go_tags_spec.lua index 65256c4..4d05e51 100644 --- a/lua/tests/go_tags_spec.lua +++ b/lua/tests/go_tags_spec.lua @@ -8,6 +8,7 @@ local cur_dir = vim.fn.expand("%:p:h") -- local ulog = require('go.utils').log describe("should run gotags", function() + local cmd -- vim.fn.readfile('minimal.vim') -- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name) -- status = require("plenary.reload").reload_module("go.nvim") @@ -20,7 +21,7 @@ describe("should run gotags", function() local expected = vim.fn.join(vim.fn.readfile(cur_dir .. "/lua/tests/fixtures/tags/add_all_golden.go"), "\n") - local cmd = " silent exe 'e " .. name .. "'" + cmd = " silent exe 'e " .. name .. "'" vim.cmd(cmd) local bufn = vim.fn.bufnr("") @@ -42,7 +43,7 @@ describe("should run gotags", function() -- ulog("tagged file: " .. fmt) vim.fn.assert_equal(fmt, expected) eq(expected, fmt) - local cmd = "bd! " .. name + cmd = "bd! " .. name vim.cmd(cmd) end) it("should rm json tags", function() @@ -54,7 +55,7 @@ describe("should run gotags", function() local expected = vim.fn.join(vim.fn.readfile(cur_dir .. "/lua/tests/fixtures/tags/add_all_input.go"), "\n") - local cmd = " silent exe 'e " .. name .. "'" + cmd = " silent exe 'e " .. name .. "'" vim.cmd(cmd) local bufn = vim.fn.bufnr("") @@ -82,7 +83,7 @@ describe("should run gotags", function() -- ulog("tagged file: " .. fmt) vim.fn.assert_equal(fmt, expected) eq(expected, fmt) - local cmd = "bd! " .. name + cmd = "bd! " .. name vim.cmd(cmd) end) it("should run clear json tags by default", function() @@ -94,7 +95,7 @@ describe("should run gotags", function() local expected = vim.fn.join(vim.fn.readfile(cur_dir .. "/lua/tests/fixtures/tags/add_all_input.go"), "\n") - local cmd = " silent exe 'e " .. name .. "'" + cmd = " silent exe 'e " .. name .. "'" vim.cmd(cmd) local bufn = vim.fn.bufnr("") @@ -122,7 +123,7 @@ describe("should run gotags", function() -- ulog("tagged file: " .. fmt) vim.fn.assert_equal(fmt, expected) eq(expected, fmt) - local cmd = "bd! " .. name + cmd = "bd! " .. name vim.cmd(cmd) end) it("should clear all tags", function() @@ -135,7 +136,7 @@ describe("should run gotags", function() local expected = vim.fn.join(vim.fn.readfile(cur_dir .. "/lua/tests/fixtures/tags/add_all_input.go"), "\n") - local cmd = " silent exe 'e " .. name .. "'" + cmd = " silent exe 'e " .. name .. "'" vim.cmd(cmd) local bufn = vim.fn.bufnr("") @@ -163,7 +164,7 @@ describe("should run gotags", function() -- ulog("tagged file: " .. fmt) vim.fn.assert_equal(fmt, expected) eq(expected, fmt) - local cmd = "bd! " .. name + cmd = "bd! " .. name vim.cmd(cmd) end) end) diff --git a/lua/tests/go_test_spec.lua b/lua/tests/go_test_spec.lua index 53df981..9df0b98 100644 --- a/lua/tests/go_test_spec.lua +++ b/lua/tests/go_test_spec.lua @@ -5,7 +5,7 @@ local busted = require("plenary/busted") describe("should run func test", function() -- vim.fn.readfile('minimal.vim') -- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name) - status = require("plenary.reload").reload_module("go.nvim") + local status = require("plenary.reload").reload_module("go.nvim") it("should test function", function() -- -- go.nvim may not auto loaded diff --git a/lua/tests/go_ts_node_spec.lua b/lua/tests/go_ts_node_spec.lua index a33f848..4a8daf2 100644 --- a/lua/tests/go_ts_node_spec.lua +++ b/lua/tests/go_ts_node_spec.lua @@ -12,7 +12,7 @@ local input = { "}", "type z struct{}", } - +local status local default = { ["function"] = "func", ["method"] = "func", @@ -38,8 +38,9 @@ describe("should get nodes ", function() vim.fn.append(0, input) vim.cmd([[w]]) local bufn = vim.fn.bufnr("") - status = require("plenary.reload").reload_module("go.nvim") - status = require("plenary.reload").reload_module("nvim-treesitter/nvim-treesitter") + require("plenary.reload").reload_module("go.nvim") + require("plenary.reload").reload_module("nvim-treesitter/nvim-treesitter") + _GO_NVIM_CFG.verbose = true local cur_dir = vim.fn.expand("%:p:h") local nodes = require("go.ts.nodes") diff --git a/selene.toml b/selene.toml index 6540d6f..b90c897 100644 --- a/selene.toml +++ b/selene.toml @@ -1 +1,8 @@ -std="lua51+vim" +std="vim" + +[rules] +global_usage = "allow" +multiple_statements = "allow" +incorrect_standard_library_use = "allow" +unused_variable = "allow" +deprecated = "allow" diff --git a/stylua.toml b/stylua.toml index 0f90030..a14776f 100644 --- a/stylua.toml +++ b/stylua.toml @@ -1,3 +1,4 @@ indent_type = "Spaces" indent_width = 2 column_width = 120 +quote_style = "AutoPreferSingle" diff --git a/vim.toml b/vim.toml deleted file mode 100644 index 0fe5fcc..0000000 --- a/vim.toml +++ /dev/null @@ -1,57 +0,0 @@ -[selene] -base = "lua51" -name = "vim" - -[vim] -any = true - -[_G] -property = true -writable = "new-fields" - -[_GO_NVIM_CFG] -property = true -writable = "new-fields" - -[debug] -property = true - -[[describe.args]] -type = "string" -[[describe.args]] -type = "function" - -[[it.args]] -type = "string" -[[it.args]] -type = "function" - -[[before_each.args]] -type = "function" -[[after_each.args]] -type = "function" - -[assert.is_not] -any = true - -[[assert.equals.args]] -type = "any" -[[assert.equals.args]] -type = "any" -[[assert.equals.args]] -type = "any" -required = false - -[[assert.same.args]] -type = "any" -[[assert.same.args]] -type = "any" - -[[assert.truthy.args]] -type = "any" - -[[assert.spy.args]] -type = "any" - -[[assert.stub.args]] -type = "any" diff --git a/vim.yml b/vim.yml new file mode 100644 index 0000000..d03b233 --- /dev/null +++ b/vim.yml @@ -0,0 +1,65 @@ +--- +base: lua52 +name: vim +globals: + ListView: + any: true + ListViewCtrl: + any: true + Panel: + any: true + TextView: + any: true + TextViewCtrl: + any: true + View: + any: true + ViewCtrl: + any: true + packer_plugins: + any: true + _G: + property: new-fields + _GO_NVIM_CFG: + property: new-fields + after_each: + args: + - type: function + assert.are.same: + any: true + assert.equals: + args: + - type: any + - type: any + - required: false + type: any + assert.is_not: + any: true + assert.same: + args: + - type: any + - type: any + assert.spy: + args: + - type: any + assert.stub: + args: + - type: any + assert.truthy: + args: + - type: any + before_each: + args: + - type: function + debug: + property: read-only + describe: + args: + - type: string + - type: function + it: + args: + - type: string + - type: function + vim: + any: true