nvim/lua/plugins/null-ls.lua

70 lines
2.1 KiB
Lua
Raw Normal View History

2022-12-31 17:43:31 +01:00
local M = {
'jose-elias-alvarez/null-ls.nvim',
}
function M.config()
local null_ls = require 'null-ls'
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting
local formatting = null_ls.builtins.formatting
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
local diagnostics = null_ls.builtins.diagnostics
null_ls.setup {
debug = false,
on_init = function(new_client, _)
new_client.offset_encoding = 'utf-16'
end,
sources = {
formatting.prettier.with { extra_args = { '--no-semi', '--single-quote', '--jsx-single-quote' } },
formatting.black.with { extra_args = { '--fast' } },
formatting.stylua.with { extra_args = { '--quote-style=AutoPreferSingle', '--call-parentheses=None' } },
formatting.clang_format.with {
filetypes = { 'c' },
extra_args = {
'--style',
'{AccessModifierOffset : -2, AllowShortIfStatementsOnASingleLine : Never, AlignConsecutiveMacros : true, AllowShortLoopsOnASingleLine : false, AlwaysBreakTemplateDeclarations : true, Standard : c++20, NamespaceIndentation : All, IndentWidth : 4, TabWidth : 4, BreakBeforeBraces : Linux, AllowShortFunctionsOnASingleLine : Empty, AllowShortBlocksOnASingleLine : Never, FixNamespaceComments : true, PointerAlignment : Right, ColumnLimit : 120, ContinuationIndentWidth : 2, UseTab : Always }',
},
},
formatting.clang_format.with {
filetypes = { 'cpp' },
extra_args = {
'--style',
'google',
},
},
formatting.beautysh,
formatting.google_java_format,
formatting.goimports,
formatting.gofumpt,
formatting.sql_formatter,
diagnostics.golangci_lint.with {
extra_args = {
'-E',
'revive',
'-E',
'errcheck',
'-E',
'gosec',
'-E',
'nilerr',
'-E',
'nlreturn',
},
},
formatting.asmfmt.with {
filetypes = { 'asm', 's' },
},
-- diagnostics.flake8
},
}
end
function M.has_formatter(ft)
local sources = require 'null-ls.sources'
local available = sources.get_available(ft, 'NULL_LS_FORMATTING')
return #available > 0
end
return M