Skip to content

Commit

Permalink
Revert "Add end_col to results of eslint/eslintd (#409)"
Browse files Browse the repository at this point in the history
This reverts commit 001eb1e.
  • Loading branch information
mfussenegger committed Oct 17, 2023
1 parent 47cb540 commit 22b235f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 83 deletions.
34 changes: 7 additions & 27 deletions lua/lint/linters/eslint.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
local severities = {
nil,
vim.diagnostic.severity.ERROR,
vim.diagnostic.severity.WARN,
local pattern = [[%s*(%d+):(%d+)%s+(%w+)%s+(.+%S)%s+(%S+)]]
local groups = { 'lnum', 'col', 'severity', 'message', 'code' }
local severity_map = {
['error'] = vim.diagnostic.severity.ERROR,
['warn'] = vim.diagnostic.severity.WARN,
['warning'] = vim.diagnostic.severity.WARN,
}

return require('lint.util').inject_cmd_exe({
Expand All @@ -14,34 +16,12 @@ return require('lint.util').inject_cmd_exe({
return 'eslint'
end,
args = {
'--format',
'json',
'--stdin',
'--stdin-filename',
function() return vim.api.nvim_buf_get_name(0) end,
},
stdin = true,
stream = 'stdout',
ignore_exitcode = true,
parser = function(output)
local success, decodedData = 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
})
end
end

return diagnostics
end
parser = require('lint.parser').from_pattern(pattern, groups, severity_map, { ['source'] = 'eslint' }),
})
34 changes: 7 additions & 27 deletions lua/lint/linters/eslint_d.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
local severities = {
nil,
vim.diagnostic.severity.ERROR,
vim.diagnostic.severity.WARN,
local pattern = [[%s*(%d+):(%d+)%s+(%w+)%s+(.+%S)%s+(%S+)]]
local groups = { 'lnum', 'col', 'severity', 'message', 'code' }
local severity_map = {
['error'] = vim.diagnostic.severity.ERROR,
['warn'] = vim.diagnostic.severity.WARN,
['warning'] = vim.diagnostic.severity.WARN,
}

return require('lint.util').inject_cmd_exe({
Expand All @@ -14,34 +16,12 @@ return require('lint.util').inject_cmd_exe({
return 'eslint_d'
end,
args = {
'--format',
'json',
'--stdin',
'--stdin-filename',
function() return vim.api.nvim_buf_get_name(0) end,
},
stdin = true,
stream = 'stdout',
ignore_exitcode = true,
parser = function(output)
local success, decodedData = 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_d",
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

return diagnostics
end
parser = require('lint.parser').from_pattern(pattern, groups, severity_map, { ['source'] = 'eslint_d' }),
})
51 changes: 22 additions & 29 deletions tests/eslint_d_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,48 @@ describe("linter.eslint_d", function()

it("can parse output", function()
local parser = require("lint.linters.eslint_d").parser
local result = parser(
[[
/directory/file.js
1:10 error 'testFunc' is defined but never used no-unused-vars
4:16 error This branch can never execute. Its condition is a duplicate or covered by previous conditions in the if-else-if chain no-dupe-else-if
local result = parser([[
{
"messages": [
{
"column": 10,
"endColumn": 18,
"endLine": 1,
"line": 1,
"message": "'testFunc' is defined but never used",
"ruleId": "no-unused-vars",
"severity": 2
},
{
"column": 16,
"endColumn": 22,
"endLine": 4,
"line": 4,
"message": "This branch can never execute. Its condition is a duplicate or covered by previous conditions in the if-else-if chain",
"ruleId": "no-dupe-else-if",
"severity": 2
}
]
}]])

✖ 2 problems (2 errors, 0 warnings)
]],
vim.api.nvim_get_current_buf()
)
assert.are.same(2, #result)

local expected_1 = {
code = "no-unused-vars",
col = 9,
end_col = 17,
end_col = 9,
end_lnum = 0,
lnum = 0,
message = "'testFunc' is defined but never used",
severity = 1,
source = "eslint_d",
user_data = {
lsp = {
code = "no-unused-vars",
},
},
}
assert.are.same(expected_1, result[1])

local expected_2 = {
code = "no-dupe-else-if",
col = 15,
end_col = 21,
end_col = 15,
end_lnum = 3,
lnum = 3,
message =
"This branch can never execute. Its condition is a duplicate or covered by previous conditions in the if-else-if chain",
message = "This branch can never execute. Its condition is a duplicate or covered by previous conditions in the if-else-if chain",
severity = 1,
source = "eslint_d",
user_data = {
lsp = {
code = "no-dupe-else-if",
},
},
}
assert.are.same(expected_2, result[2])
end)
Expand Down

0 comments on commit 22b235f

Please sign in to comment.