Created
November 14, 2024 20:46
-
-
Save JustLinuxUser/07793f092d504adf4e3ce520f06740ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return { | |
"mfussenegger/nvim-lint", | |
cmd = function() | |
BANNED_BUFFS = {}; | |
require("lint").linters_by_ft = { | |
c = { "norminette" }, | |
} | |
-- Error: VAR_DECL_START_FUNC (line: 171, col: 1): Variable declaration not at start of function | |
local pattern = '(Error):%s+([%u_]+)%s+%(line:%s+(%d+),%scol:%s+(%d+)%):%s+(.*)'; | |
local groups = { 'severity', 'code', 'lnum', 'col', 'message' }; | |
local default_severity = {['Error'] = vim.diagnostic.severity.WARN}; | |
local parser = require('lint.parser').from_pattern(pattern, groups, default_severity, {}, {}); | |
require('lint').linters.norminette = { | |
name = "norminette", | |
cmd = 'norminette', | |
stdin = false, -- or false if it doesn't support content input via stdin. In that case the filename is automatically added to the arguments. | |
append_fname = true, -- Automatically append the file name to `args` if `stdin = false` (default: true) | |
args = {}, -- list of arguments. Can contain functions with zero arguments that will be evaluated once the linter is used. | |
stream = "both", -- ('stdout' | 'stderr' | 'both') configure the stream to which the linter outputs the linting result. | |
ignore_exitcode = true, -- set this to true if the linter exits with a code != 0 and that's considered normal. | |
env = nil, -- custom environment table to use with the external process. Note that this replaces the *entire* environment, it is not additive. | |
parser = parser | |
} | |
vim.api.nvim_create_autocmd({ "BufWritePost" }, { | |
callback = function() | |
-- try_lint without arguments runs the linters defined in `linters_by_ft` | |
-- for the current filetype | |
local buf = vim.api.nvim_get_current_buf(); | |
local allowed = true; | |
for _, b in pairs(BANNED_BUFFS) do | |
if b == buf then | |
allowed = false; | |
end | |
end | |
if vim.fn.filereadable("NONORM") == 1 then | |
allowed = false; | |
end | |
if allowed then | |
require("lint").try_lint() | |
end | |
end, | |
}) | |
vim.api.nvim_create_user_command('ClNorm',function() | |
local ns = require("lint").get_namespace("norminette"); | |
vim.diagnostic.reset(ns, vim.api.nvim_get_current_buf()); | |
end,{}) | |
vim.api.nvim_create_user_command('NoNorm',function() | |
local ns = require("lint").get_namespace("norminette"); | |
vim.diagnostic.reset(ns, vim.api.nvim_get_current_buf()); | |
table.insert(BANNED_BUFFS, vim.api.nvim_get_current_buf()); | |
end,{}) | |
end, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment