From fd646f49e9a2c0836035e1ce7a3ec25ce148bae8 Mon Sep 17 00:00:00 2001 From: Christoffer Klang Date: Thu, 12 Oct 2023 10:09:31 +0200 Subject: [PATCH 1/2] languagetool: Fix parsing error when output contains 'Err:...' (#396) --- lua/lint/linters/languagetool.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lua/lint/linters/languagetool.lua b/lua/lint/linters/languagetool.lua index d530da98..781c3526 100644 --- a/lua/lint/linters/languagetool.lua +++ b/lua/lint/linters/languagetool.lua @@ -1,9 +1,27 @@ +-- LanguageTool might give output like "Err: 'yada yada'\n{ ... json here ... }' +local function parse_err_json(str) + local json_start = str:find('{', 1, true) + local err = nil + local json = str + + if json_start and json_start > 1 then + err = str:sub(1, json_start - 1):gsub("^%s*(.-)%s*$", "%1") -- trim spaces + json = str:sub(json_start) + end + + return err, json +end + return { cmd = 'languagetool', args = {'--autoDetect', '--json'}, stream = 'stdout', parser = function(output, bufnr) - local decoded = vim.json.decode(output) + local err, json = parse_err_json(output) + if err then + vim.notify_once(err, vim.log.levels.INFO) + end + local decoded = vim.json.decode(json) local diagnostics = {} local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true) local content = table.concat(lines, '\n') From 0f54481d7537a6872f7bb021575366657e123474 Mon Sep 17 00:00:00 2001 From: Jorge Date: Thu, 12 Oct 2023 05:10:24 -0300 Subject: [PATCH 2/2] Add biomejs (#403) --- README.md | 2 + lua/lint/linters/biomejs.lua | 79 ++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 lua/lint/linters/biomejs.lua diff --git a/README.md b/README.md index 9bdc72dd..726de6ff 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ Other dedicated linters that are built-in are: | [ansible-lint][ansible-lint] | `ansible_lint` | | [bandit][bandit] | `bandit` | | [bean-check][bean-check] | `bean_check` | +| [biomejs][biomejs] | `biomejs` | | [buf_lint][buf_lint] | `buf_lint` | | [buildifier][buildifier] | `buildifier` | | [cfn-lint][cfn-lint] | `cfn_lint` | @@ -397,3 +398,4 @@ busted tests/ [ec]: https://github.com/editorconfig-checker/editorconfig-checker [deno]: https://github.com/denoland/deno [standardjs]: https://standardjs.com/ +[biomejs]: https://github.com/biomejs/biome diff --git a/lua/lint/linters/biomejs.lua b/lua/lint/linters/biomejs.lua new file mode 100644 index 00000000..eec6a210 --- /dev/null +++ b/lua/lint/linters/biomejs.lua @@ -0,0 +1,79 @@ +-- Sample biome lint output: +-- +-- index.js:6:13 lint/suspicious/noDoubleEquals FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +-- +-- ✖ Use === instead of == +-- +-- 4 │ count += 1; +-- 5 │ var f = function (opt) { +-- > 6 │ if (opt == true) { +-- │ ^^ +-- 7 │ return "true"; +-- 8 │ } +-- +-- ℹ == is only allowed when comparing against null +-- +-- 4 │ count += 1; +-- 5 │ var f = function (opt) { +-- > 6 │ if (opt == true) { +-- │ ^^ +-- 7 │ return "true"; +-- 8 │ } +-- +-- ℹ Using === may be unsafe if you are relying on type coercion +-- +-- ℹ Suggested fix: Use === +-- +-- 6 │ ····if·(opt·===·true)·{ +-- │ + +return { + cmd = "biome", + args = { "lint" }, + stdin = false, + ignore_exitcode = true, + stream = "both", + parser = function(output) + local diagnostics = {} + + + -- The diagnostic details we need are spread in the first 3 lines of + -- each error report. These variables are declared out of the FOR + -- loop because we need to carry their values to parse multiple lines. + local fetch_message = false + local lnum, col, code, message + + -- When a lnum:col:code line is detected fetch_message is set to true. + -- While fetch_message is true we will search for the error message. + -- When a error message is detected, we will create the diagnostic and + -- set fetch_message to false to restart the process and get the next + -- diagnostic. + for _, line in ipairs(vim.fn.split(output, "\n")) do + if fetch_message then + _, _, message = string.find(line, "%s×(.+)") + + if message then + message = (message):gsub("^%s+×%s*", "") + + table.insert(diagnostics, { + source = "biomejs", + lnum = tonumber(lnum) - 1, + col = tonumber(col), + message = message, + code = code + }) + + fetch_message = false + end + else + _, _, lnum, col, code = string.find(line, "[^:]+:(%d+):(%d+)%s([%a%/]+)") + + if lnum then + fetch_message = true + end + end + end + + return diagnostics + end +}