efm-general-ls.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. local markdownlint = {
  35. -- TODO default to global lintrc
  36. -- lintcommand = 'markdownlint -s -c ./markdownlintrc',
  37. lintCommand = 'markdownlint -s',
  38. lintStdin = true,
  39. lintFormats = { '%f:%l %m', '%f:%l:%c %m', '%f: %l: %m' }
  40. }
  41. local markdownPandocFormat = {
  42. formatCommand = 'pandoc -f markdown -t gfm -sp --tab-stop=2',
  43. formatStdin = true
  44. }
  45. require"lspconfig".efm.setup {
  46. -- init_options = {initializationOptions},
  47. init_options = {documentFormatting = true, codeAction = false},
  48. filetypes = {"lua", "python", "javascriptreact", "javascript", "sh", "html", "css", "json", "yaml", "markdown"},
  49. settings = {
  50. rootMarkers = {".git/"},
  51. languages = {
  52. lua = {luaFormat},
  53. python = {isort, yapf},
  54. javascriptreact = {prettier, eslint},
  55. javascript = {prettier, eslint},
  56. sh = {shellcheck, shfmt},
  57. html = {prettier},
  58. css = {prettier},
  59. json = {prettier},
  60. yaml = {prettier_yaml},
  61. -- markdown = {markdownPandocFormat, markdownlint},
  62. markdown = {markdownPandocFormat},
  63. }
  64. }
  65. }
  66. -- Also find way to toggle format on save
  67. -- maybe this will help: https://superuser.com/questions/439078/how-to-disable-autocmd-or-augroup-in-vim