efm-general-ls.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. -- Example configuations here: https://github.com/mattn/efm-langserver
  2. -- python
  3. local flake8 = {
  4. LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -",
  5. lintStdin = true,
  6. lintFormats = {"%f:%l:%c: %m"}
  7. }
  8. local isort = {formatCommand = "isort --quiet -", formatStdin = true}
  9. local yapf = {formatCommand = "yapf --quiet", formatStdin = true}
  10. -- lua
  11. local luaFormat = {
  12. formatCommand = "lua-format -i --no-keep-simple-function-one-line --column-limit=120",
  13. formatStdin = true
  14. }
  15. -- JavaScript/React/TypeScript
  16. local prettier = {formatCommand = "./node_modules/.bin/prettier --stdin-filepath ${INPUT}", formatStdin = true}
  17. local prettier_global = {formatCommand = "prettier --stdin-filepath ${INPUT}", formatStdin = true}
  18. local eslint = {
  19. lintCommand = "./node_modules/.bin/eslint -f unix --stdin --stdin-filename ${INPUT}",
  20. lintIgnoreExitCode = true,
  21. lintStdin = true,
  22. lintFormats = {"%f:%l:%c: %m"},
  23. formatCommand = "./node_modules/.bin/eslint --fix-to-stdout --stdin --stdin-filename=${INPUT}",
  24. formatStdin = true
  25. }
  26. local shellcheck = {
  27. LintCommand = 'shellcheck -f gcc -x',
  28. lintFormats = {'%f:%l:%c: %trror: %m', '%f:%l:%c: %tarning: %m', '%f:%l:%c: %tote: %m'}
  29. }
  30. local shfmt = {formatCommand = 'shfmt -ci -s -bn', formatStdin = true}
  31. local markdownlint = {
  32. -- TODO default to global lintrc
  33. -- lintcommand = 'markdownlint -s -c ./markdownlintrc',
  34. lintCommand = 'markdownlint -s',
  35. lintStdin = true,
  36. lintFormats = {'%f:%l %m', '%f:%l:%c %m', '%f: %l: %m'}
  37. }
  38. local markdownPandocFormat = {formatCommand = 'pandoc -f markdown -t gfm -sp --tab-stop=2', formatStdin = true}
  39. require"lspconfig".efm.setup {
  40. -- init_options = {initializationOptions},
  41. init_options = {documentFormatting = true, codeAction = false},
  42. filetypes = {"lua", "python", "javascriptreact", "javascript", "sh", "html", "css", "json", "yaml", "markdown"},
  43. settings = {
  44. rootMarkers = {".git/"},
  45. languages = {
  46. lua = {luaFormat},
  47. python = {isort, yapf},
  48. -- javascriptreact = {prettier, eslint},
  49. -- javascript = {prettier, eslint},
  50. javascriptreact = {prettier},
  51. javascript = {prettier_global},
  52. sh = {shellcheck, shfmt},
  53. html = {prettier_global},
  54. css = {prettier_global},
  55. json = {prettier_global},
  56. yaml = {prettier_global},
  57. -- markdown = {markdownPandocFormat, markdownlint},
  58. markdown = {markdownPandocFormat}
  59. }
  60. }
  61. }
  62. -- Also find way to toggle format on save
  63. -- maybe this will help: https://superuser.com/questions/439078/how-to-disable-autocmd-or-augroup-in-vim