From 9bbe68013bfa5bfcccfd030b3e40ff4ed50ea52c Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Wed, 15 Sep 2021 18:13:17 -0700 Subject: [PATCH] Run some linting on nvim lua --- neovim/lua/_bindings.lua | 15 +++++++++------ neovim/lua/_colors.lua | 12 +++++++----- neovim/lua/_settings.lua | 2 -- neovim/lua/init.lua | 2 +- neovim/lua/plugins.lua | 16 +++++++--------- neovim/lua/plugins/airline.lua | 32 +++++++++++++++---------------- neovim/lua/plugins/ale.lua | 24 +++++++++++------------ neovim/lua/plugins/lsp.lua | 2 ++ neovim/lua/plugins/startify.lua | 8 ++++---- neovim/lua/plugins/telescope.lua | 2 +- neovim/lua/plugins/treesitter.lua | 6 +++--- neovim/lua/utils.lua | 6 +++--- 12 files changed, 65 insertions(+), 62 deletions(-) diff --git a/neovim/lua/_bindings.lua b/neovim/lua/_bindings.lua index 3fb8d67..747a1a2 100644 --- a/neovim/lua/_bindings.lua +++ b/neovim/lua/_bindings.lua @@ -1,7 +1,10 @@ +-- luacheck: globals packer_plugins +local utils = require("utils") + local map = vim.api.nvim_set_keymap -local opt_silent = {silent=true} -local opt_default = {silent=true, noremap=true} +local opt_silent = {silent = true} +local opt_default = {silent = true, noremap = true} map("n", "", ":set wrap!", opt_silent) map("n", "lw", ":set wrap!", opt_silent) map("n", "", ":set invnumber", opt_silent) @@ -42,15 +45,15 @@ map("i", "``", "", opt_default) map("v", "``", "", opt_default) -- C-Space completion -_G.complete_space = function() +function _G.complete_space() if vim.fn.pumvisible() == 1 then - return utils.t"" + return utils.t("") elseif packer_plugins["completion-nvim"] and packer_plugins["completion-nvim"].loaded then - return utils.t"(completion_trigger)" + return utils.t("(completion_trigger)") elseif packer_plugins["nvim-compe"] and packer_plugins["nvim-compe"].loaded then return vim.fn["compe#complete"]() else - return utils.t"" + return utils.t("") end end map("i", "", "v:lua.complete_space()", {expr = true}) diff --git a/neovim/lua/_colors.lua b/neovim/lua/_colors.lua index eca65e0..ce3439e 100644 --- a/neovim/lua/_colors.lua +++ b/neovim/lua/_colors.lua @@ -1,7 +1,8 @@ -utils = require("utils") +-- luacheck: globals packer_plugins +local utils = require("utils") -- TODO: Determine if I want to keep this or remove it in favor of dark-notify -_G.update_colors = function() +function _G.update_colors() local function maybe_set(scope, name, val) if vim[scope][name] ~= val then vim[scope][name] = val @@ -39,7 +40,8 @@ _G.update_colors = function() -- Update status line theme if change and vim.fn.exists(":AirlineRefresh") == 1 then vim.cmd(":AirlineRefresh") - elseif change and _G["packer_plugins"] ~= nil and packer_plugins["lualine"] and packer_plugins["lualine"].loaded then + elseif (change and _G["packer_plugins"] + and packer_plugins["lualine"] and packer_plugins["lualine"].loaded) then local lualine_theme = vim.g.colors_name if lualine_theme == "solarized" then lualine_theme = lualine_theme .. "_" .. mode @@ -47,10 +49,10 @@ _G.update_colors = function() require("plugins.lualine").config_lualine(lualine_theme) end - return changed and "Changed color to " .. env_color .. " with mode " .. mode or "No change" + return change and "Changed color to " .. env_color .. " with mode " .. mode or "No change" end -- utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()") -- Initial set of colors -- TODO: if update_colors() is removed, use the env color fetching and set the colorscheme here -update_colors() +_G.update_colors() diff --git a/neovim/lua/_settings.lua b/neovim/lua/_settings.lua index c8a0cf3..34086fb 100644 --- a/neovim/lua/_settings.lua +++ b/neovim/lua/_settings.lua @@ -1,6 +1,4 @@ -local wo = vim.wo local o = vim.o -local bo = vim.bo local g = vim.g -- Set leader to space diff --git a/neovim/lua/init.lua b/neovim/lua/init.lua index ce8cb54..528442f 100644 --- a/neovim/lua/init.lua +++ b/neovim/lua/init.lua @@ -1,4 +1,4 @@ -local o, wo, bo = vim.o, vim.wo, vim.bo +local o = vim.o -- Helpers require "_settings" diff --git a/neovim/lua/plugins.lua b/neovim/lua/plugins.lua index e9ea566..ed80c31 100644 --- a/neovim/lua/plugins.lua +++ b/neovim/lua/plugins.lua @@ -1,6 +1,4 @@ -- Do all Packer stuff -utils = require("utils") - local install_path = vim.fn.stdpath("data").."/site/pack/packer/start/packer.nvim" if vim.fn.empty(vim.fn.glob(install_path)) > 0 then @@ -31,6 +29,7 @@ local function config_dark_notify() end return require('packer').startup(function() + -- luacheck: push globals use use "wbthomason/packer.nvim" -- Quality of life @@ -109,9 +108,9 @@ return require('packer').startup(function() use { "cormacrelf/dark-notify", -- Download latest release on install - run = "curl -s https://api.github.com/repos/cormacrelf/dark-notify/releases/latest | jq '.assets[].browser_download_url' | xargs curl -Ls | tar xz -C ~/.local/bin/", + run = "curl -s https://api.github.com/repos/cormacrelf/dark-notify/releases/latest | jq '.assets[].browser_download_url' | xargs curl -Ls | tar xz -C ~/.local/bin/", -- luacheck: no max line length config = config_dark_notify, - requires = { "hoob3rt/lualine.nvim" }, + requires = "hoob3rt/lualine.nvim", } use { 'mhinz/vim-startify', @@ -125,7 +124,7 @@ return require('packer').startup(function() } use { "glepnir/lspsaga.nvim", - requires = { "neovim/nvim-lspconfig" }, + requires = "neovim/nvim-lspconfig", } --[[ use { @@ -167,9 +166,7 @@ return require('packer').startup(function() -- Fuzzy Finder use { "nvim-telescope/telescope.nvim", - requires = { - "nvim-lua/plenary.nvim", - }, + requires = "nvim-lua/plenary.nvim", config = function() require("plugins.telescope") end, } --[[ @@ -187,7 +184,7 @@ return require('packer').startup(function() -- Override key commands -- vim.g.fzf_action = { ['ctrl-t'] = 'tab split', ['ctrl-s'] = 'split', ['ctrl-v'] = 'vsplit', } -- Override git log to show authors - vim.g.fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h %an: %s%d %C(black)%C(bold)%cr"' + vim.g.fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h %an: %s%d %C(black)%C(bold)%cr"' -- luacheck: no max line length vim.g.fzf_preview_window = {"right:50%", "ctrl-/"} @@ -246,4 +243,5 @@ return require('packer').startup(function() cmd = { "StartupTime" }, } + -- luacheck: pop end) diff --git a/neovim/lua/plugins/airline.lua b/neovim/lua/plugins/airline.lua index da51dfc..76c6a30 100644 --- a/neovim/lua/plugins/airline.lua +++ b/neovim/lua/plugins/airline.lua @@ -1,28 +1,28 @@ local function config_airline() -- Use short-form mode text vim.g.airline_mode_map = { - ['__'] = '-', - ['n'] = 'N', - ['i'] = 'I', - ['R'] = 'R', - ['c'] = 'C', - ['v'] = 'V', - ['V'] = 'V', - [''] = 'V', - ['s'] = 'S', - ['S'] = 'S', - [''] = 'S', - ['t'] = 'T', + ["__"] = "-", + ["n"] = "N", + ["i"] = "I", + ["R"] = "R", + ["c"] = "C", + ["v"] = "V", + ["V"] = "V", + [""] = "V", + ["s"] = "S", + ["S"] = "S", + [""] = "S", + ["t"] = "T", } -- abbreviate trailing whitespace and mixed indent vim.g["airline#extensions#whitespace#trailing_format"] = "tw[%s]" vim.g["airline#extensions#whitespace#mixed_indent_format"] = "i[%s]" -- Vertical separators for all - vim.g.airline_left_sep='' - vim.g.airline_left_alt_sep='' - vim.g.airline_right_sep='' - vim.g.airline_right_alt_sep='' + vim.g.airline_left_sep="" + vim.g.airline_left_alt_sep="" + vim.g.airline_right_sep="" + vim.g.airline_right_alt_sep="" vim.g["airline#extensions#tabline#enabled"] = 1 vim.g["airline#extensions#tabline#left_sep"] = " " vim.g["airline#extensions#tabline#left_alt_sep"] = "|" diff --git a/neovim/lua/plugins/ale.lua b/neovim/lua/plugins/ale.lua index 900f7ae..c5f5c2d 100644 --- a/neovim/lua/plugins/ale.lua +++ b/neovim/lua/plugins/ale.lua @@ -1,16 +1,16 @@ vim.g["airline#extensions#ale#enabled"] = 1 vim.g.ale_lint_on_enter = 0 vim.g.ale_linters = { - -- go = { 'gopls', 'golint', 'golangci-lint' }, - go = { "golangci-lint" }, - -- rust = { 'rls', 'cargo' }, - rust = { "cargo" }, - -- sh = { 'language_server', 'shell', 'shellcheck' }, - sh = { "shell", "shellcheck" }, - text = { "proselint", "alex" }, + -- go = {'gopls', 'golint', 'golangci-lint'}, + go = {"golangci-lint"}, + -- rust = {'rls', 'cargo'}, + rust = {"cargo"}, + -- sh = {'language_server', 'shell', 'shellcheck'}, + sh = {"shell", "shellcheck"}, + text = {"proselint", "alex"}, } vim.g.ale_linter_aliases = { - markdown = { "text" }, + markdown = {"text"}, } local pretty_trim_fixer = { "prettier", @@ -18,10 +18,10 @@ local pretty_trim_fixer = { "remove_trailing_lines" } vim.g.ale_fixers = { - ["*"] = { "trim_whitespace", "remove_trailing_lines" }, - -- go = { "gofmt", "goimports" }, + ["*"] = {"trim_whitespace", "remove_trailing_lines"}, + -- go = {"gofmt", "goimports"}, json = pretty_trim_fixer, - -- rust = { "rustfmt" }, + -- rust = {"rustfmt"}, --[[ python = { "black", @@ -32,7 +32,7 @@ vim.g.ale_fixers = { }, --]] markdown = pretty_trim_fixer, - yaml = { "prettier", "remove_trailing_lines" }, + yaml = {"prettier", "remove_trailing_lines"}, css = pretty_trim_fixer, javascript = pretty_trim_fixer, } diff --git a/neovim/lua/plugins/lsp.lua b/neovim/lua/plugins/lsp.lua index ec24ef1..5dcb529 100644 --- a/neovim/lua/plugins/lsp.lua +++ b/neovim/lua/plugins/lsp.lua @@ -1,3 +1,4 @@ +-- luacheck: globals packer_plugins local function default_attach(client, bufnr) require('completion').on_attach() @@ -7,6 +8,7 @@ local function default_attach(client, bufnr) buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') -- Mappings + -- TODO: Maybe prefix all of these for easier discovery local opts = { noremap=true, silent=true } buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) diff --git a/neovim/lua/plugins/startify.lua b/neovim/lua/plugins/startify.lua index 9cfe7dc..06f6b93 100644 --- a/neovim/lua/plugins/startify.lua +++ b/neovim/lua/plugins/startify.lua @@ -1,6 +1,6 @@ vim.g.startify_list_order = { - { ' My Bookmarks'}, 'bookmarks', - { ' Most recently used files in the current directory' }, 'dir', - { ' Most recently used files' }, 'files', - { ' My Sessions' }, 'sessions' + {' My Bookmarks'}, 'bookmarks', + {' Most recently used files in the current directory'}, 'dir', + {' Most recently used files'}, 'files', + {' My Sessions'}, 'sessions' } diff --git a/neovim/lua/plugins/telescope.lua b/neovim/lua/plugins/telescope.lua index 4901b43..c192531 100644 --- a/neovim/lua/plugins/telescope.lua +++ b/neovim/lua/plugins/telescope.lua @@ -21,7 +21,7 @@ local function config_telescope() layout_strategy = "flex", } } - opts = {silent=true, noremap=true} + local opts = {silent=true, noremap=true} vim.api.nvim_set_keymap("n", "", "Telescope find_files", opts) vim.api.nvim_set_keymap("n", "ff", "Telescope find_files", opts) vim.api.nvim_set_keymap("n", "fh", "Telescope help_tags", opts) diff --git a/neovim/lua/plugins/treesitter.lua b/neovim/lua/plugins/treesitter.lua index db8a231..5f3b9bc 100644 --- a/neovim/lua/plugins/treesitter.lua +++ b/neovim/lua/plugins/treesitter.lua @@ -1,9 +1,9 @@ -- Configures nvim-treesitter require'nvim-treesitter.configs'.setup{ - incremental_selection = { enable = true }, + incremental_selection = {enable = true}, -- Indent appears to be broken right now - indent = { enable = false }, - textobjects = { enable = true }, + indent = {enable = false}, + textobjects = {enable = true}, highlight = { enable = true, disable = {}, diff --git a/neovim/lua/utils.lua b/neovim/lua/utils.lua index 396fb51..6ea19b5 100644 --- a/neovim/lua/utils.lua +++ b/neovim/lua/utils.lua @@ -44,7 +44,7 @@ end -- Get env value or use default, if not present function M.env_default(name, def) - val = vim.env[name] + local val = vim.env[name] return val == nil and def or val end @@ -80,8 +80,8 @@ function M.require_with_local(name) -- In that case, the local file would probably start with a `require` for the -- non-local version. This would allow more control but at the cost of a bit -- of boiler plate - rmod = require(name) - lmod = M.maybe_require(name .. "_local") + local rmod = require(name) + local lmod = M.maybe_require(name .. "_local") if lmod ~= nil then return lmod end