Skip to content

Commit

Permalink
Revert broken eslint changes (#419)
Browse files Browse the repository at this point in the history
* Revert "Fix parsing regression in eslint(d) (#416)"

This reverts commit 7ac6307.

* Revert "Add end_col to results of eslint/eslintd (#409)"

This reverts commit 001eb1e.
  • Loading branch information
mfussenegger authored Oct 17, 2023
1 parent 7ac6307 commit 749e895
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 97 deletions.
39 changes: 7 additions & 32 deletions lua/lint/linters/eslint.lua
Original file line number Diff line number Diff line change
@@ -1,52 +1,27 @@
local severities = {
vim.diagnostic.severity.WARN,
vim.diagnostic.severity.ERROR,
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({
cmd = function()
local local_eslint = vim.fn.fnamemodify('./node_modules/.bin/eslint', ':p')
local stat = vim.loop.fs_stat(local_eslint)

if stat then
return local_eslint
end

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,
{ luanil = { object = true, array = true } }
)
local messages = decodedData and decodedData[1] and decodedData[1].messages or {}

local diagnostics = {}
if success and #messages > 0 then
for _, diagnostic in ipairs(messages or {}) do
table.insert(diagnostics, {
source = "eslint",
lnum = diagnostic.line - 1,
col = diagnostic.column - 1,
end_lnum = (diagnostic.endLine or diagnostic.line) - 1,
end_col = (diagnostic.endColumn or diagnostic.column) - 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' }),
})
45 changes: 10 additions & 35 deletions lua/lint/linters/eslint_d.lua
Original file line number Diff line number Diff line change
@@ -1,52 +1,27 @@
local severities = {
vim.diagnostic.severity.WARN,
vim.diagnostic.severity.ERROR,
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({
cmd = function()
local local_eslint_d = vim.fn.fnamemodify('./node_modules/.bin/eslint_d', ':p')
local stat = vim.loop.fs_stat(local_eslint_d)

local local_eslintd = vim.fn.fnamemodify('./node_modules/.bin/eslint_d', ':p')
local stat = vim.loop.fs_stat(local_eslintd)
if stat then
return local_eslint_d
return local_eslintd
end

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,
{ luanil = { object = true, array = true } }
)
local messages = decodedData and decodedData[1] and decodedData[1].messages or {}

local diagnostics = {}
if success and #messages > 0 then
for _, diagnostic in ipairs(messages or {}) do
table.insert(diagnostics, {
source = "eslint_d",
lnum = diagnostic.line - 1,
col = diagnostic.column - 1,
end_lnum = (diagnostic.endLine or diagnostic.line) - 1,
end_col = (diagnostic.endColumn or diagnostic.column) - 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' }),
})
52 changes: 22 additions & 30 deletions tests/eslint_d_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +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 749e895

Please sign in to comment.