diff --git a/README.md b/README.md index fd3713bd..3e4711dc 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ require("lint").linters_by_ft = { } ``` +To get the `filetype` of a buffer you can run `:= vim.bo.filetype`. + Then setup a autocmd to trigger linting. For example: ```vimL @@ -204,6 +206,7 @@ Other dedicated linters that are built-in are: | [Spectral][spectral] | `spectral` | | [sphinx-lint][sphinx-lint] | `sphinx-lint` | | [sqlfluff][sqlfluff] | `sqlfluff` | +| [sqruff][sqruff] | `sqruff` | | [standardjs][standardjs] | `standardjs` | | [StandardRB][27] | `standardrb` | | [statix check][33] | `statix` | @@ -216,6 +219,7 @@ Other dedicated linters that are built-in are: | [tfsec][tfsec] | `tfsec` | | [tlint][tlint] | `tlint` | | [trivy][trivy] | `trivy` | +| [ts-standard][ts-standard] | `ts-standard` | | [typos][typos] | `typos` | | [Vala][vala-lint] | `vala_lint` | | [Vale][8] | `vale` | @@ -546,6 +550,7 @@ busted tests/ [cue]: https://github.com/cue-lang/cue [curlylint]: https://www.curlylint.org/ [sqlfluff]: https://github.com/sqlfluff/sqlfluff +[sqruff]: https://github.com/quarylabs/sqruff [verilator]: https://verilator.org/guide/latest/ [actionlint]: https://github.com/rhysd/actionlint [buf_lint]: https://github.com/bufbuild/buf @@ -608,4 +613,5 @@ busted tests/ [svlint]: https://github.com/dalance/svlint [slang]: https://github.com/MikePopoloski/slang [zizmor]: https://github.com/woodruffw/zizmor +[ts-standard]: https://github.com/standard/ts-standard [pmd]: https://pmd.github.io/ diff --git a/lua/lint/linters/golangcilint.lua b/lua/lint/linters/golangcilint.lua index d4d87170..7156ac5f 100644 --- a/lua/lint/linters/golangcilint.lua +++ b/lua/lint/linters/golangcilint.lua @@ -12,6 +12,7 @@ return { 'run', '--out-format', 'json', + '--issues-exit-code=0', '--show-stats=false', '--print-issued-lines=false', '--print-linter-name=false', @@ -20,7 +21,6 @@ return { end }, stream = 'stdout', - ignore_exitcode = true, parser = function(output, bufnr, cwd) if output == '' then return {} @@ -34,7 +34,7 @@ return { for _, item in ipairs(decoded["Issues"]) do local curfile = vim.api.nvim_buf_get_name(bufnr) local lintedfile = cwd .. "/" .. item.Pos.Filename - if curfile == lintedfile then + if vim.fn.fnamemodify(curfile, ":p") == vim.fn.fnamemodify(lintedfile, ":p") then -- only publish if those are the current file diagnostics local sv = severities[item.Severity] or severities.warning table.insert(diagnostics, { diff --git a/lua/lint/linters/jq.lua b/lua/lint/linters/jq.lua index c92acd4f..c4580e8b 100644 --- a/lua/lint/linters/jq.lua +++ b/lua/lint/linters/jq.lua @@ -4,7 +4,7 @@ return { stream = "stderr", ignore_exitcode = true, parser = require("lint.parser").from_pattern( - "^(.+): (.+) at line (%d+), column (%d+)$", + "^(.+): (.+) at line (%d+), column (%d+)", { "code", "message", "lnum", "col" }, nil, nil, diff --git a/lua/lint/linters/mypy.lua b/lua/lint/linters/mypy.lua index bc79be65..38092459 100644 --- a/lua/lint/linters/mypy.lua +++ b/lua/lint/linters/mypy.lua @@ -10,6 +10,7 @@ local severities = { return { cmd = 'mypy', stdin = false, + stream = "both", ignore_exitcode = true, args = { '--show-column-numbers', diff --git a/lua/lint/linters/sqruff.lua b/lua/lint/linters/sqruff.lua new file mode 100644 index 00000000..833f2d9e --- /dev/null +++ b/lua/lint/linters/sqruff.lua @@ -0,0 +1,39 @@ +local severities = { + Error = vim.diagnostic.severity.ERROR, + Warning = vim.diagnostic.severity.WARN, +} + +return { + cmd = "sqruff", + stdin = true, + args = { + "lint", + "--format=json", + "-", + }, + ignore_exitcode = true, + parser = function(output, _) + if vim.trim(output) == "" or output == nil then + return {} + end + + local decoded = vim.json.decode(output) + local diagnostics = {} + local messages = decoded[""] + + for _, msg in ipairs(messages or {}) do + table.insert(diagnostics, { + lnum = msg.range.start.line - 1, + end_lnum = msg.range["end"].line - 1, + col = msg.range.start.character - 1, + end_col = msg.range["end"].character - 1, + message = msg.message, + code = msg.code, + source = msg.source, + severity = assert(severities[msg.severity], "missing mapping for severity " .. msg.severity), + }) + end + + return diagnostics + end, +} diff --git a/lua/lint/linters/ts-standard.lua b/lua/lint/linters/ts-standard.lua new file mode 100644 index 00000000..0210ca62 --- /dev/null +++ b/lua/lint/linters/ts-standard.lua @@ -0,0 +1,18 @@ +local binary_name = "ts-standard" +local pattern = "[^:]+:(%d+):(%d+):([^%.]+%.?)%s%(([%a-]+)%)%s?%(?(%a*)%)?" +local groups = { "lnum", "col", "message", "code", "severity" } +local severities = { + [""] = vim.diagnostic.severity.ERROR, + ["warning"] = vim.diagnostic.severity.WARN, +} + +return { + cmd = function() + local local_binary = vim.fn.fnamemodify("./node_modules/.bin/" .. binary_name, ":p") + return vim.loop.fs_stat(local_binary) and local_binary or binary_name + end, + stdin = true, + args = { "--stdin" }, + ignore_exitcode = true, + parser = require("lint.parser").from_pattern(pattern, groups, severities, { ["source"] = "ts-standard" }, {}), +}