diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c6da5e8..73541b4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,18 +13,6 @@ repos: (?x)^( vim/colors/.*\.vim )$ - - repo: https://github.com/johnnymorganz/stylua - rev: v0.17.1 - hooks: - - id: stylua-github - - repo: https://github.com/lunarmodules/luacheck - rev: v1.1.0 - hooks: - - id: luacheck - args: - - --globals - - vim - - -- - repo: local hooks: - id: sort-json @@ -33,3 +21,13 @@ repos: entry: ./scripts/sort-json.sh files: "(\\.json$|^neovim/packer_snapshots/)" types: [text] + - id: selene + name: An opinionated Lua code linter + entry: selene + language: system + types: [lua] + - id: stylua + name: An opinionated Lua code formatter + entry: selene + language: system + types: [lua] diff --git a/install-helpers.py b/install-helpers.py index 15aff1b..e404101 100755 --- a/install-helpers.py +++ b/install-helpers.py @@ -175,6 +175,16 @@ def install_linters(langs: set[Language]): if not maybe_run("lua", "-e", "require('lfs')"): maybe_run("luarocks", "--local", "install", "luafilesystem") maybe_run("luarocks", "--local", "install", "luacheck", "1.1.0") + maybe_run( + "release-gitter", + "--git-url", + "https://github.com/Kampfkarren/selene", + "--exec", + os.path.expanduser("chmod +x ~/bin/selene"), + "--extract-files", "selene", + "selene-{version}-{system}.zip", + os.path.expanduser("~/bin"), + ) if Language.DOCKER in langs: hadolint_arm64 = "arm64" if sys.platform == "darwin": diff --git a/neovim/lua/colors.lua b/neovim/lua/colors.lua index 844c6ee..79a09fa 100644 --- a/neovim/lua/colors.lua +++ b/neovim/lua/colors.lua @@ -1,5 +1,7 @@ -- Update colors based on environment variables -function _G.update_colors() +local M = {} + +function M.update_colors() local function maybe_set(scope, name, val, force) force = force or false local changed = vim[scope][name] ~= val @@ -63,10 +65,14 @@ local utils = require("utils") if not utils.is_plugin_loaded("dark-notify") then vim.api.nvim_create_autocmd({ "FocusGained" }, { pattern = "*", - callback = _G.update_colors, + callback = M.update_colors, group = vim.api.nvim_create_augroup("auto_colors", { clear = true }), }) end -- Initial setting of colors -_G.update_colors() +function M.init() + M.update_colors() +end + +return M diff --git a/neovim/lua/init.lua b/neovim/lua/init.lua index eac02a7..43be100 100644 --- a/neovim/lua/init.lua +++ b/neovim/lua/init.lua @@ -28,4 +28,4 @@ vim.g.polyglot_disabled = { "go", "rust" } require("lazy_init") -- Load colors after plugins -require("colors") +require("colors").init() diff --git a/neovim/lua/lazy_plugins.lua b/neovim/lua/lazy_plugins.lua index 1dbb5a3..f32af7b 100644 --- a/neovim/lua/lazy_plugins.lua +++ b/neovim/lua/lazy_plugins.lua @@ -1,3 +1,4 @@ +-- #selene: allow(mixed_table) local utils = require("utils") return { { @@ -377,9 +378,7 @@ return { -- Generic linter/formatters in diagnostics API { - -- TODO: null-ls is archived and no longer maintained. It is replaced by none-ls - -- Replace with https://github.com/nvimtools/none-ls.nvim - "https://github.com/jose-elias-alvarez/null-ls.nvim", + "https://github.com/nvimtools/none-ls.nvim", -- This is lazy and configured after lsps loaded in plugins/lsp.lua lazy = true, branch = utils.map_version_rule({ @@ -393,6 +392,7 @@ return { [">=0.6.0"] = "4b403d2d724f48150ded41189ae4866492a8158b", }), dependencies = { + { "https://github.com/nvimtools/none-ls-extras.nvim" }, { "https://github.com/nvim-lua/plenary.nvim" }, { "https://github.com/neovim/nvim-lspconfig" }, }, diff --git a/neovim/lua/plugins/darknotify.lua b/neovim/lua/plugins/darknotify.lua index 6d224c3..332ebd4 100644 --- a/neovim/lua/plugins/darknotify.lua +++ b/neovim/lua/plugins/darknotify.lua @@ -1,6 +1,5 @@ require("dark_notify").run({ onchange = function(_) - -- Defined in _colors - _G.update_colors() + require("colors").update_colors() end, }) diff --git a/neovim/lua/plugins/lsp.lua b/neovim/lua/plugins/lsp.lua index ac5f39c..68ab37b 100644 --- a/neovim/lua/plugins/lsp.lua +++ b/neovim/lua/plugins/lsp.lua @@ -243,7 +243,7 @@ function M.config_lsp() -- Setup each server with default config vim.tbl_map(function(server) if server == "lua_ls" then - -- Disable formatting with lua_ls because I use luacheck + -- Disable formatting with lua_ls because I use stylua local config = vim.tbl_extend("force", default_setup, { settings = { Lua = { diff --git a/neovim/lua/plugins/lualine.lua b/neovim/lua/plugins/lualine.lua index e61150e..f92ba49 100644 --- a/neovim/lua/plugins/lualine.lua +++ b/neovim/lua/plugins/lualine.lua @@ -1,3 +1,4 @@ +-- #selene: allow(mixed_table) local M = {} local utils = require("utils") @@ -50,9 +51,7 @@ function M.config_lualine(theme_name) -- Theme name transformations if theme_name == nil then theme_name = "auto" - elseif theme_name:find("wombat") then - theme_name = "wombat" - elseif theme_name == "wombuddy" then + elseif theme_name:find("wombat") or theme_name == "wombuddy" then theme_name = "wombat" end diff --git a/neovim/lua/plugins/null-ls/init.lua b/neovim/lua/plugins/null-ls/init.lua index 18156b9..de281d5 100644 --- a/neovim/lua/plugins/null-ls/init.lua +++ b/neovim/lua/plugins/null-ls/init.lua @@ -41,14 +41,15 @@ function M.configure(options) local sources = { -- Generic null_ls.builtins.formatting.prettier, - null_ls.builtins.formatting.trim_whitespace, - null_ls.builtins.formatting.trim_newlines, + -- From extras + require("none-ls.formatting.trim_whitespace"), + require("none-ls.formatting.trim_newlines"), -- Ansible null_ls.builtins.diagnostics.ansiblelint.with({ filetypes = { "yaml.ansible" } }), -- Fish null_ls.builtins.formatting.fish_indent, -- Python - null_ls.builtins.formatting.reorder_python_imports, + -- null_ls.builtins.formatting.reorder_python_imports, null_ls.builtins.formatting.isort, null_ls.builtins.formatting.black, null_ls.builtins.diagnostics.mypy, @@ -65,9 +66,9 @@ function M.configure(options) end, }), -- Shell - null_ls.builtins.diagnostics.shellcheck, + -- null_ls.builtins.diagnostics.shellcheck, -- Lua - null_ls.builtins.diagnostics.luacheck, + null_ls.builtins.diagnostics.selene, null_ls.builtins.formatting.stylua, -- Docker null_ls.builtins.diagnostics.hadolint, diff --git a/neovim/lua/utils.lua b/neovim/lua/utils.lua index 2f5f0ff..72d2749 100644 --- a/neovim/lua/utils.lua +++ b/neovim/lua/utils.lua @@ -1,4 +1,3 @@ --- luacheck: globals packer_plugins local M = {} function M.get_color(synID, what, mode)