-
Notifications
You must be signed in to change notification settings - Fork 12
/
eslint.lua
67 lines (62 loc) · 1.89 KB
/
eslint.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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 DIAGNOSTICS = methods.internal.DIAGNOSTICS
local handle_eslint_output = function(params)
params.messages = params.output and params.output[1] and params.output[1].messages or {}
if params.err then
table.insert(params.messages, { message = params.err })
end
local parser = h.diagnostics.from_json({
attributes = {
_fix = "fix",
severity = "severity",
},
severities = {
h.diagnostics.severities["warning"],
h.diagnostics.severities["error"],
},
adapters = {
{
user_data = function(entries)
return { fixable = not not entries._fix }
end,
},
},
})
return parser({ output = params.messages })
end
return h.make_builtin({
name = "eslint",
meta = {
url = "https://github.com/eslint/eslint",
description = "A linter for the JavaScript ecosystem.",
},
method = DIAGNOSTICS,
filetypes = {
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"svelte",
"astro",
},
generator_opts = {
command = "eslint",
args = { "-f", "json", "--stdin", "--stdin-filename", "$FILENAME" },
to_stdin = true,
format = "json_raw",
check_exit_code = function(code)
return code <= 1
end,
use_cache = true,
on_output = handle_eslint_output,
dynamic_command = cmd_resolver.from_node_modules(),
cwd = h.cache.by_bufnr(function(params)
return u.cosmiconfig("eslint", "eslintConfig")(params.bufname)
end),
},
factory = h.generator_factory,
})