efm-langserver
efm-langserver copied to clipboard
Unable to get flake8 and mypy to lint simultaneously for python
Hello!
Thank you for the great plugin! Unfortunately I have some issues getting my python linting working correctly. When I try to configure both flake8 and mypy for python, only flake8 works. When I remove flake8 then mypy shows linting output. I tried changing the order or adding options as a seperate variable. But nothing seems to do the trick. Am I missing something in this configuration?
local flake8 = {
lintCommand = 'flake8 --max-line-length 100 --stdin-display-name ${INPUT} -',
lintStdin = true,
lintFormats = '%f:%l:%c: %m',
lintIgnoreExitCode = true,
lintSource = 'flake8'
}
local mypy = {
lintCommand = 'mypy --show-column-numbers --follow-imports silent',
lintFormats = {
'%f:%l:%c: %trror: %m',
'%f:%l:%c: %tarning: %m',
'%f:%l:%c: %tote: %m'
},
lintIgnoreExitCode = true,
lintSource = 'mypy'
}
local black = {
formatCommand = 'black --line-length 100 -',
formatStdin = true
}
local isort = {
formatCommand = "isort --profile black -",
formatStdin = true,
}
require('lspconfig').efm.setup{
on_attach = custom_lsp_attach,
capabilities = capabilities,
init_options = {documentFormatting = true},
settings = {
rootMarkers = {".git/"},
log_level = 1,
log_file = '/tmp/efm.log',
languages = {
['='] = {
{
lintCommand = 'cspell}',
lintStdin = true
},
{
lintCommand = 'misspell',
lintIgnoreExitCode = true,
lintStdin = true,
lintFormats = {'%f:%l:%c: %m'}
}
},
python = { flake8, mypy, black, isort },
sh = {
{
lintCommand = 'shellcheck -f gcc -x',
lintSource = 'shellcheck',
lintFormats = { "%f:%l:%c: %trror: %m", "%f:%l:%c: %tarning: %m", "%f:%l:%c: %tote: %m" }
}
},
lua = {
{
lintCommand = 'luacheck ${input}',
formatCommand = 'luacheck ${input}',
formatStdin = true
}
},
go = {
{
lintCommand = "golint",
lintIgnoreExitCode = true,
lintFormats = {"%f:%l:%c: %m"}
}
},
yaml = {
{
lintCommand = 'cfn-lint',
lintStdin = true
}
}
}
}
}
I ran into the same kind of issue and eventually ended up with a very different config that does have both working. I have just
require "lspconfig".efm.setup {
filetypes = { "python" },
on_attach = on_attach,
init_options = {documentFormatting = true},
settings = {
rootMarkers = {".git/"},
}
}
in my vim configuration and I think I could probably get rid of the rootMarker too. The other configuration happens in my ~/.config/efm-langserver/config.yaml. E.g.
...
languages:
python:
- <<: *python-flake8
- <<: *python-mypy
- <<: *python-black
- <<: *python-isort
you can update the python-flake8 definition in the yaml file to make any updates (or throw all of those updates into a config file)
After quite some effort I managed to get them both working in a venv along with pyright in the same buffer. Here's the config.settings
I used for both. Removing the lint formats somehow did the trick.
local get_venv_path = function()
local path = vim.fn.getcwd() .. "/"
if vim.fn.has("unix") == 1 then
path = path .. ".venv/bin/"
else
path = path .. ".venv/Scripts/"
end
return path
end
...
python = {
python = {
pythonPath = get_venv_path() .. "python",
analysis = {
autoSearchPaths = true,
diagnosticMode = "workspace",
useLibraryCodeForTypes = true,
},
},
},
efm = {
rootMarkers = { vim.fn.getcwd() },
languages = {
python = {
{
lintCommand = get_venv_path() .. "flake8 --stdin-display-name ${INPUT} -",
lintStdin = true,
lintIgnoreExitCode = true,
lintSource = "flake8",
},
{
lintCommand = get_venv_path() .. "mypy --show-column-numbers",
lintIgnoreExitCode = true,
lintSource = "mypy",
},
{
formatCommand = get_venv_path() .. "black --quiet -",
formatStdin = true,
},
},
lua = { { formatCommand = "stylua -", formatStdin = true } },
},
},