nvim-lint
nvim-lint copied to clipboard
nvim-lint with gcc
Has somebody successfully used this with gcc for linting? I've experimenting with the settings for adding a new linter using the cppcheck as e template together with some of the info on gccdiag at null-ls.nvim and ALE, but with no success. Here's what I've tried:
local pattern = [[^([^:]+):(%d+):(%d+):%s+([^:]+):%s+(.*)$]]
local groups = { 'file', 'lnum', 'col', 'code', 'severity', 'message' }
local severity_map = {
['error'] = vim.diagnostic.severity.ERROR,
['warning'] = vim.diagnostic.severity.WARN,
['performance'] = vim.diagnostic.severity.WARN,
['style'] = vim.diagnostic.severity.INFO,
['information'] = vim.diagnostic.severity.INFO,
}
require('lint').linters.gcc = {
cmd = 'cc',
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 = false, -- Automatically append the file name to `args` if `stdin = false` (default: true)
args = {'-std=c89', '-Wall'}, -- 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 = false, -- 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 = require('lint.parser').from_pattern(pattern, groups, severity_map, { ['source'] = 'gcc' }),
}
Problem is, that I don't really know lua and don't know what I'm doing really. I just want to be able to use gcc together with the other linters to lint my code, just as i did with ALE. "cc" exists with code 1 according to neovim, but I don't know where I can get any more information? nvim-lint doesn't have any logs on what commands it runs (as LSP does?).
Try this: https://github.com/mfussenegger/nvim-lint/issues/492#issuecomment-1872975515
require('lint').linters_by_ft = {
c = {'gcc'}
}
local pattern = [[^([^:]+):(%d+):(%d+):%s+([^:]+):%s+(.*)$]]
local groups = { 'file', 'lnum', 'col', 'severity', 'message' }
local severity_map = {
['error'] = vim.diagnostic.severity.ERROR,
['warning'] = vim.diagnostic.severity.WARN,
['performance'] = vim.diagnostic.severity.WARN,
['style'] = vim.diagnostic.severity.INFO,
['information'] = vim.diagnostic.severity.INFO,
}
require('lint').linters.gcc = {
cmd = 'gcc',
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 = {'-Wall', '-std=c99'}, -- list of arguments. Can contain functions with zero arguments that will be evaluated once the linter is used.
stream = 'stderr', -- ('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 = require('lint.parser').from_pattern(pattern, groups, severity_map, { ['source'] = 'gcc' }),
}
modify the line:
local groups = { 'file', 'lnum', 'col', 'severity', 'message' }
and:
ignore_exitcode = true,