Skip to content

Commit

Permalink
Merge branch 'master' into feature/add-pmd-linter
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoschcau committed Jan 25, 2025
2 parents d5e1e5b + 789b7ad commit 543b2b5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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` |
Expand All @@ -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` |
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/
4 changes: 2 additions & 2 deletions lua/lint/linters/golangcilint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ return {
'run',
'--out-format',
'json',
'--issues-exit-code=0',
'--show-stats=false',
'--print-issued-lines=false',
'--print-linter-name=false',
Expand All @@ -20,7 +21,6 @@ return {
end
},
stream = 'stdout',
ignore_exitcode = true,
parser = function(output, bufnr, cwd)
if output == '' then
return {}
Expand All @@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion lua/lint/linters/jq.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lua/lint/linters/mypy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local severities = {
return {
cmd = 'mypy',
stdin = false,
stream = "both",
ignore_exitcode = true,
args = {
'--show-column-numbers',
Expand Down
39 changes: 39 additions & 0 deletions lua/lint/linters/sqruff.lua
Original file line number Diff line number Diff line change
@@ -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["<string>"]

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,
}
18 changes: 18 additions & 0 deletions lua/lint/linters/ts-standard.lua
Original file line number Diff line number Diff line change
@@ -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" }, {}),
}

0 comments on commit 543b2b5

Please sign in to comment.