Skip to content

Commit

Permalink
Merge branch 'master' into feat/snyk
Browse files Browse the repository at this point in the history
  • Loading branch information
pbnj authored Oct 13, 2023
2 parents 6dd1228 + 0f54481 commit d8e4f67
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down Expand Up @@ -398,4 +399,5 @@ 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
[snyk]: https://github.com/snyk/cli
79 changes: 79 additions & 0 deletions lua/lint/linters/biomejs.lua
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 19 additions & 1 deletion lua/lint/linters/languagetool.lua
Original file line number Diff line number Diff line change
@@ -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')
Expand Down

0 comments on commit d8e4f67

Please sign in to comment.