首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置午餐会使用更漂亮的-eslint

设置午餐会使用更漂亮的-eslint
EN

Stack Overflow用户
提问于 2022-07-07 07:10:36
回答 1查看 1.3K关注 0票数 0

我要从Atom迁移到鲁纳维,我需要配置Lunarvim,以便对Javascript文件使用更漂亮

读“月刊”的文档,但不知道该怎么做。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-30 09:09:28

用这个定制的LUA Config解决

代码语言:javascript
复制
-- optional: set your prefered indent with size
vim.opt.shiftwidth = 4
vim.opt.tabstop = 4

-- load required null-ls references
local h = require("null-ls.helpers")
local cmd_resolver = require("null-ls.helpers.command_resolver")
local methods = require("null-ls.methods")
local u = require("null-ls.utils")
local FORMATTING = methods.internal.FORMATTING

-- Define the new javascript formatter
local pe = h.make_builtin({
  name = "prettier_eslint",
  meta = {
    url = "https://github.com/prettier/prettier-eslint-cli",
    description = "Eslint + Prettier",
  },
  method = FORMATTING,
  filetypes = {
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact",
    "vue",
    "jsx"
  },
  factory = h.formatter_factory,
  generator_opts = {
    command = "prettier-eslint",
    args = { "--stdin", "--parser", "babel", "--resolve-plugins-relative-to", "~/.nvm/versions/node/v16.16.0/lib" },
    to_stdin = true,
  },
})

-- optional: Define a second formatter for JSON
local pejson = h.make_builtin({
  name = "prettier_eslint_json",
  meta = {
    url = "https://github.com/prettier/prettier-eslint-cli",
    description = "Eslint + Prettier",
  },
  method = FORMATTING,
  filetypes = {
    "json",
    "cjson",
  },
  factory = h.formatter_factory,
  generator_opts = {
    command = "prettier-eslint",
    args = { "--stdin", "--parser", "json" },
    to_stdin = true,
  },
})

-- Enable the the defined formatters
-- if you are using vanilla NeoVim + null-ls please
-- read how to install/enable on
-- https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/CONFIG.md 
local nls = require("null-ls")
nls.setup {
  on_attach = require("lvim.lsp").common_on_attach,
  sources = {
    pe,
    pejson
  }
}

-- optional: LunarVim related step. Here we enable eslint as linter for Javascript.
local linters = require "lvim.lsp.null-ls.linters"
linters.setup {
  {
    command = "eslint",
    filetypes = { "javascript" }
  }
}

全教程这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72893615

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档