Skip to content

Commit

Permalink
refactor: split up in files
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Sep 21, 2023
1 parent 77a10c0 commit 54241c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
29 changes: 29 additions & 0 deletions lua/rule-breaker/ignoreRuleData.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---@class ruleIgnoreConfig
---@field comment string|string[] with %s for the rule id
---@field type "sameLine"|"nextLine"|"enclose"

---@type table<string, ruleIgnoreConfig>
local data = {
shellcheck = {
comment = "# shellcheck disable=%s",
type = "nextLine",
},
selene = {
comment = "-- selene: allow(%s)",
type = "nextLine",
},
vale = {
comment = { "<!-- vale %s = NO -->", "<!-- vale %s = YES -->" },
type = "enclose",
},
yamllint = {
comment = "# yamllint disable-line rule:%s",
type = "nextLine",
},
stylelint = {
comment = "/* stylelint-disable-next-line %s */",
type = "nextLine",
},
}

return data
31 changes: 2 additions & 29 deletions lua/rule-breaker.lua → lua/rule-breaker/init.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,7 @@
local M = {}
local fn = vim.fn
--------------------------------------------------------------------------------

---@class ruleIgnoreConfig
---@field comment string|string[] with %s for the rule id
---@field type "sameLine"|"nextLine"|"enclose"

---@type table<string, ruleIgnoreConfig>
local ignoreRuleData = {
shellcheck = {
comment = "# shellcheck disable=%s",
type = "nextLine",
},
selene = {
comment = "-- selene: allow(%s)",
type = "nextLine",
},
vale = {
comment = { "<!-- vale %s = NO -->", "<!-- vale %s = YES -->" },
type = "enclose",
},
yamllint = {
comment = "# yamllint disable-line rule:%s",
type = "nextLine",
},
stylelint = {
comment = "/* stylelint-disable-next-line %s */",
type = "nextLine",
},
}
local ignoreRuleData = require("rule-breaker.ignoreRuleData")

--------------------------------------------------------------------------------

Expand Down Expand Up @@ -117,7 +90,7 @@ local function addIgnoreComment(diag)
return
end

-- insert rule id and indentation into comment
-- add rule id and indentation into comment
local currentIndent = vim.api.nvim_get_current_line():match("^%s*")
local ignoreComment = ignoreRuleData[diag.source].comment
if type(ignoreComment) == "string" then ignoreComment = { ignoreComment } end
Expand Down

0 comments on commit 54241c5

Please sign in to comment.