Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ESLint linter expects different output #415

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions lua/lint/linters/eslint.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local severities = {
nil,
vim.diagnostic.severity.ERROR,
vim.diagnostic.severity.WARN,
vim.diagnostic.severity.ERROR,
}

return require('lint.util').inject_cmd_exe({
Expand All @@ -23,22 +22,29 @@ return require('lint.util').inject_cmd_exe({
stdin = true,
stream = 'stdout',
ignore_exitcode = true,
parser = function(output)
local success, decodedData = pcall(vim.json.decode, output)
parser = function(output, buffer)
local success, data = pcall(vim.json.decode, output)
local diagnostics = {}

if success and decodedData ~= nil then
for _, diagnostic in ipairs(decodedData.messages or {}) do
table.insert(diagnostics, {
source = "eslint",
lnum = diagnostic.line - 1,
col = diagnostic.column - 1,
end_lnum = diagnostic.endLine - 1,
end_col = diagnostic.endColumn - 1,
severity = severities[diagnostic.severity],
message = diagnostic.message,
code = diagnostic.ruleId
})
if success and data ~= nil then
for _, item in ipairs(data) do
local current_file = vim.api.nvim_buf_get_name(buffer)
local linted_file = item.filePath

if current_file == linted_file then
for _, diagnostic in ipairs(item.messages or {}) do
table.insert(diagnostics, {
source = "eslint",
lnum = diagnostic.line - 1,
col = diagnostic.column - 1,
end_lnum = diagnostic.endLine - 1,
end_col = diagnostic.endColumn - 1,
severity = severities[diagnostic.severity],
message = diagnostic.message,
code = diagnostic.ruleId
})
end
end
end
end

Expand Down
Loading