From c9aa44ff09aeb8b06ba7ab1e58faab7c318f191b Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Sat, 18 Jan 2025 17:10:37 +0100 Subject: [PATCH 1/8] mypy: set stream to "both" mypy outputs the errors to `stdout` by default but the following configuration options can change the behavior to output them on `stderr`: install_types = "True" non_interactive = "True" `stream = "both"` should handle both cases. Closes https://github.com/mfussenegger/nvim-lint/issues/700 --- lua/lint/linters/mypy.lua | 1 + 1 file changed, 1 insertion(+) 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', From 1fd5abde5265b265ea2666a8fe8b7e028a395ef6 Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Sat, 18 Jan 2025 17:31:52 +0100 Subject: [PATCH 2/8] jq: Allow trailing whitespace Closes https://github.com/mfussenegger/nvim-lint/issues/651 --- lua/lint/linters/jq.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From 6742c6e6a9f316af84c8a51f31bea0f24504eed3 Mon Sep 17 00:00:00 2001 From: Joey Buiteweg Date: Sat, 18 Jan 2025 10:59:41 -0600 Subject: [PATCH 3/8] Mention how to display filetype in readme (#722) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 11e75e8a..72fb20c3 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 From 9195dd0fa532f6657ff3bbc4bf7c5afa8a55ca43 Mon Sep 17 00:00:00 2001 From: Abel Anaya <71462682+AbelAnaya@users.noreply.github.com> Date: Sat, 18 Jan 2025 18:25:00 +0100 Subject: [PATCH 4/8] Add ts-standard linter (#702) Co-authored-by: Mathias Fussenegger --- README.md | 2 ++ lua/lint/linters/ts-standard.lua | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 lua/lint/linters/ts-standard.lua diff --git a/README.md b/README.md index 72fb20c3..939bbb86 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,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` | @@ -590,3 +591,4 @@ 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 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" }, {}), +} From ec9fda13a5254783a80b37563ed5eb97b75c28b7 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Sun, 19 Jan 2025 12:42:34 +0100 Subject: [PATCH 5/8] Add sqruff (#728) --- README.md | 2 ++ lua/lint/linters/sqruff.lua | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lua/lint/linters/sqruff.lua diff --git a/README.md b/README.md index 939bbb86..4d61807a 100644 --- a/README.md +++ b/README.md @@ -206,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` | @@ -529,6 +530,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 diff --git a/lua/lint/linters/sqruff.lua b/lua/lint/linters/sqruff.lua new file mode 100644 index 00000000..a33ff247 --- /dev/null +++ b/lua/lint/linters/sqruff.lua @@ -0,0 +1,40 @@ +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 not provided: https://github.com/quarylabs/sqruff/issues/1219 + source = msg.source, + severity = assert(severities[msg.severity], "missing mapping for severity " .. msg.severity), + }) + end + + return diagnostics + end, +} From ba3a77b016afe2abeaf216b4c1960e9e5128747e Mon Sep 17 00:00:00 2001 From: plockc Date: Tue, 21 Jan 2025 11:26:03 -0800 Subject: [PATCH 6/8] golangci-lint: handle relative paths while parsing (#731) Compare absolute paths when determining filename to buffer matching Closes #730 --- lua/lint/linters/golangcilint.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lint/linters/golangcilint.lua b/lua/lint/linters/golangcilint.lua index d4d87170..14451e6f 100644 --- a/lua/lint/linters/golangcilint.lua +++ b/lua/lint/linters/golangcilint.lua @@ -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, { From 3d5190d318e802de3a503b74844aa87c2cd97ef0 Mon Sep 17 00:00:00 2001 From: plockc Date: Tue, 21 Jan 2025 11:30:47 -0800 Subject: [PATCH 7/8] golangci-lint: set --issues-exit-code=0 (#732) This allows the error exit code to indicate failure to run the linter itself --- lua/lint/linters/golangcilint.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lint/linters/golangcilint.lua b/lua/lint/linters/golangcilint.lua index 14451e6f..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 {} From 789b7ada1b4f00e08d026dffde410dcfa6a0ba87 Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Tue, 21 Jan 2025 20:31:56 +0100 Subject: [PATCH 8/8] sqruff: include error code in diagnostic (#729) --- lua/lint/linters/sqruff.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/lint/linters/sqruff.lua b/lua/lint/linters/sqruff.lua index a33ff247..833f2d9e 100644 --- a/lua/lint/linters/sqruff.lua +++ b/lua/lint/linters/sqruff.lua @@ -17,7 +17,6 @@ return { return {} end - local decoded = vim.json.decode(output) local diagnostics = {} local messages = decoded[""] @@ -29,7 +28,7 @@ return { col = msg.range.start.character - 1, end_col = msg.range["end"].character - 1, message = msg.message, - -- code not provided: https://github.com/quarylabs/sqruff/issues/1219 + code = msg.code, source = msg.source, severity = assert(severities[msg.severity], "missing mapping for severity " .. msg.severity), })