efm-general-ls.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_yaml = {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 = {
  31. formatCommand = 'shfmt -ci -s -bn',
  32. formatStdin = true
  33. }
  34. require"lspconfig".efm.setup {
  35. -- init_options = {initializationOptions},
  36. init_options = {documentFormatting = true, codeAction = false},
  37. filetypes = {"lua", "python", "javascriptreact", "javascript", "sh", "html", "css", "json", "yaml"},
  38. settings = {
  39. rootMarkers = {".git/"},
  40. languages = {
  41. lua = {luaFormat},
  42. python = {isort, yapf},
  43. javascriptreact = {prettier, eslint},
  44. javascript = {prettier, eslint},
  45. sh = {shellcheck, shfmt},
  46. html = {prettier},
  47. css = {prettier},
  48. json = {prettier},
  49. yaml = {prettier_yaml},
  50. }
  51. }
  52. }
  53. -- TODO turn these eslint and prettier examples into something good
  54. -- TODO also shellcheck and shell formatting
  55. -- Also find way to toggle format on save
  56. -- maybe this will help: https://superuser.com/questions/439078/how-to-disable-autocmd-or-augroup-in-vim