Skip to content

Commit

Permalink
Replace none-ls with conform and nvim-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
djensenius committed Sep 9, 2024
1 parent bb106c3 commit a2b173d
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 65 deletions.
56 changes: 56 additions & 0 deletions nvim/lua/plugins/conform.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
return {
"stevearc/conform.nvim",
event = { "BufWritePre" },
cmd = { "ConformInfo" },
keys = {
{
-- Customize or remove this keymap to your liking
"<leader>fmt",
function()
require("conform").format({ async = true })
end,
mode = "",
desc = "Format buffer",
},
},
-- This will provide type hinting with LuaLS
---@module "conform"
---@type conform.setupOpts
opts = {
-- Define your formatters
formatters_by_ft = {
lua = { "stylua" },
python = { "isort", "black" },
rust = { "rustfmt", lsp_format = "fallback" },
javascript = { "eslint_d", "prettierd", "prettier", stop_after_first = true },
typescript = { "eslint_d", "prettier", stop_after_first = true },
javascriptreact = { "eslint_d", "prettier", stop_after_first = true },
typescriptreact = { "eslint_d", "prettier", stop_after_first = true },
svelte = { "prettier" },
css = { "prettier" },
html = { "prettier" },
json = { "prettier" },
yaml = { "prettier" },
markdown = { "prettier" },
graphql = { "prettier" },
go = { "goimports", "gofmt" },
ruby = { "rubocop" },
},
-- Set default options
default_format_opts = {
lsp_format = "fallback",
},
-- Set up format-on-save
-- format_on_save = { timeout_ms = 500 },
-- Customize formatters
formatters = {
shfmt = {
prepend_args = { "-i", "2" },
},
},
},
init = function()
-- If you want the formatexpr, here is the place to set it
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
}
63 changes: 34 additions & 29 deletions nvim/lua/plugins/mason.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,41 @@ return {
dependencies = {
{
"williamboman/mason.nvim",
dependencies = {
"WhoIsSethDaniel/mason-tool-installer.nvim",
},
config = function()
require("mason").setup()
local tools = {
"eslint-lsp",
"eslint_d",
"luacheck",
"lua-language-server",
"prettierd",
"shellcheck",
"stylelint-lsp",
"stylua",
"tailwindcss-language-server",
"typescript-language-server",
"yaml-language-server",
"ruby-lsp",
"jq-lsp",
"json-lsp",
"gopls",
"delve",
}
local function check()
local mr = require("mason-registry")
for _, tool in ipairs(tools) do
local p = mr.get_package(tool)
if not p:is_installed() then
p:install()
end
end
end
check()
local mason_tool_installer = require("mason-tool-installer")
mason_tool_installer.setup({
ensure_installed = {
"black",
"delve",
"eslint-lsp",
"eslint_d",
"goimports",
"golangci-lint",
"gopls",
"isort",
"jq-lsp",
"jsonlint",
"json-lsp",
"luacheck",
"lua-language-server",
"prettierd",
"prettier",
"pylint",
"rubocop",
"ruby-lsp",
"rustfmt",
"shellcheck",
"stylelint-lsp",
"stylua",
"tailwindcss-language-server",
"typescript-language-server",
"yaml-language-server",
},
})
end,
},
"neovim/nvim-lspconfig",
Expand Down Expand Up @@ -105,7 +110,7 @@ return {
config = function()
require("mason-lspconfig").setup({
ensure_installed = {
"tsserver",
"ts_ls",
"lua_ls",
"gopls",
},
Expand Down
36 changes: 0 additions & 36 deletions nvim/lua/plugins/none-ls.lua

This file was deleted.

36 changes: 36 additions & 0 deletions nvim/lua/plugins/nvim-lint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
return {
"mfussenegger/nvim-lint",
event = {
"BufReadPre",
"BufNewFile",
},
config = function()
local lint = require("lint")

lint.linters_by_ft = {
javascript = { "eslint_d" },
typescript = { "eslint_d" },
javascriptreact = { "eslint_d" },
typescriptreact = { "eslint_d" },
svelte = { "eslint_d" },
python = { "pylint" },
ruby = { "rubocop" },
go = { "golangcilint" },
fish = { "fish" },
jsonlint = { "jsonlint" },
}

local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })

vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
group = lint_augroup,
callback = function()
lint.try_lint()
end,
})

vim.keymap.set("n", "<leader><space>l", function()
lint.try_lint()
end, { desc = "Trigger linting for current file" })
end,
}

0 comments on commit a2b173d

Please sign in to comment.