Skip to content

Commit 77dcec3

Browse files
authored
feat(linter): add typos (#57)
1 parent f4fb957 commit 77dcec3

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
- [ ] [shellcheck](https://github.com/koalaman/shellcheck)
7979
- [ ] [stylelint](https://stylelint.io/)
8080
- [x] [ruff](https://github.com/astral-sh/ruff)
81+
- [ ] [typos](https://github.com/crate-ci/typos)
8182
- [ ] [mypy](https://mypy.readthedocs.io/en/stable/index.html)
8283
- [ ] [mypyc](https://mypyc.readthedocs.io/en/latest/index.html)
8384
- [ ] [dmypy](https://mypy.readthedocs.io/en/stable/mypy_daemon.html)

lua/guard-collection/linter/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ return {
1717
shellcheck = require('guard-collection.linter.shellcheck'),
1818
stylelint = require('guard-collection.linter.stylelint'),
1919
ruff = require('guard-collection.linter.ruff'),
20+
typos = require('guard-collection.linter.typos'),
2021
mypy = require('guard-collection.linter.mypy').mypy,
2122
mypyc = require('guard-collection.linter.mypy').mypyc,
2223
dmypy = require('guard-collection.linter.mypy').dmypy,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
local lint = require('guard.lint')
2+
return {
3+
cmd = 'typos',
4+
stdin = false,
5+
fname = true,
6+
args = { '--format=json', '--force-exclude' },
7+
parse = function(result, bufnr)
8+
if result == '' then
9+
return {}
10+
end
11+
12+
local diagnostics = {}
13+
14+
for json in string.gmatch(result, '[%S]+') do
15+
local item = vim.json.decode(json)
16+
17+
if item ~= nil and item.line_num ~= nil then
18+
local line_num = item.line_num - 1
19+
local corrections = table.concat(item.corrections, ' / ')
20+
21+
table.insert(
22+
diagnostics,
23+
lint.diag_fmt(
24+
bufnr,
25+
line_num,
26+
item.byte_offset,
27+
string.format('`%s` should be `%s`', item.typo, corrections),
28+
vim.diagnostic.severity.WARN,
29+
'[typos] ' .. item.type,
30+
line_num,
31+
item.byte_offset + item.type:len()
32+
)
33+
)
34+
end
35+
end
36+
37+
return diagnostics
38+
end,
39+
}

0 commit comments

Comments
 (0)