diff --git a/lua/lint/linters/eslint.lua b/lua/lint/linters/eslint.lua index 4c796dcf..37c04adc 100644 --- a/lua/lint/linters/eslint.lua +++ b/lua/lint/linters/eslint.lua @@ -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({ @@ -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