Skip to content

Commit 11b4921

Browse files
committed
refactor: make linters without codes easier to configure
1 parent 2ffa33d commit 11b4921

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lua/rulebook/data/add-ignore-comment.lua

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
---@field comment string|string[]|function if string, "%s" will be replaced with the rule id
33
---@field location "prevLine"|"sameLine"|"encloseLine" "encloseLine" is a list with two strings, one to be inserted before and one after
44
---@field docs string used for auto-generated docs
5+
---@field doesNotUseCodes? boolean the linter does not use codes/rule-ids
56

67
---INFO the key must be named *exactly* like diagnostic.source (case-sensitive!)
78
--------------------------------------------------------------------------------
@@ -77,12 +78,14 @@ M = {
7778
comment = function(_) return vim.bo.commentstring:format("editorconfig-checker-disable-line") end,
7879
location = "sameLine",
7980
docs = "https://github.com/editorconfig-checker/editorconfig-checker#excluding-lines",
81+
doesNotUseCodes = true,
8082
},
8183
codespell = {
8284
comment = function(_) return vim.bo.commentstring:format("codespell-ignore") end,
8385
location = "sameLine",
8486
-- HACK uses workaround via `codespell --ignore-regex`
8587
docs = "https://github.com/codespell-project/codespell/issues/1212#issuecomment-1721152455",
88+
doesNotUseCodes = true,
8689
},
8790
["clang-tidy"] = {
8891
comment = "// NOLINT(%s)",
@@ -106,6 +109,7 @@ M = {
106109
comment = function(_) return vim.bo.commentstring:format("spellwarn:disable-line") end,
107110
location = "sameLine",
108111
docs = "https://github.com/ravibrock/spellwarn.nvim#usage",
112+
doesNotUseCodes = true,
109113
},
110114
}
111115

lua/rulebook/init.lua

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ end
6161
---@return boolean whether rule is valid
6262
---@nodiscard
6363
local function validDiagObj(diag)
64-
local sourcesWithNoCodes = { "editorconfig-checker", "codespell", "spellwarn" }
64+
local sourcesWithNoCodes = vim.iter(config.ignoreComments)
65+
:filter(function(_, conf) return conf.doesNotUseCodes end)
66+
:map(function(linter, _) return linter end)
67+
:totable()
6568
if vim.tbl_contains(sourcesWithNoCodes, diag.source) then return true end
6669

6770
local issuePlea = "\nPlease open an issue at the diagnostic source or the diagnostic provider."
@@ -134,7 +137,7 @@ end
134137
---@param diag vim.Diagnostic
135138
local function yankDiagCode(diag)
136139
if not validDiagObj(diag) then return end
137-
140+
138141
local reg = config.yankDiagnosticCodeToSystemClipboard and "+" or '"'
139142
vim.fn.setreg(reg, diag.code)
140143
notify(("Diagnostic code copied: \n%s"):format(diag.code), "info")

0 commit comments

Comments
 (0)