#!/usr/bin/env nvim -l
---@diagnostic disable: no-unknown
-- Lints C files in the Neovim source tree.
-- Based on Google "cpplint", modified for Neovim.
--
-- Test coverage: `test/functional/script/clint_spec.lua`
--
-- This can get very confused by /* and // inside strings! We do a small hack,
-- which is to ignore //'s with "'s after them on the same line, but it is far
-- from perfect (in either direction).
local vim = vim
-- Error categories used for filtering
local ERROR_CATEGORIES = {
'build/endif_comment',
'build/header_guard',
'build/include_defs',
'build/defs_header',
'build/printf_format',
'build/storage_class',
'build/init_macro',
'readability/bool',
'readability/multiline_comment',
-- Dropped 'readability/multiline_string' detection because it is too buggy, and uncommon.
-- 'readability/multiline_string',
'readability/nul',
'readability/utf8',
'readability/increment',
'runtime/arrays',
'runtime/int',
'runtime/memset',
'runtime/printf',
'runtime/printf_format',
'runtime/threadsafe_fn',
'runtime/deprecated',
'whitespace/indent',
'whitespace/operators',
'whitespace/cast',
}
-- Default filters (empty by default)
local DEFAULT_FILTERS = {}
-- Assembly state constants
local NO_ASM = 0 -- Outside of inline assembly block
local INSIDE_ASM = 1 -- Inside inline assembly block
local END_ASM = 2 -- Last line of inline assembly block
local BLOCK_ASM = 3 -- The whole block is an inline assembly block
-- Regex compilation cache
local regexp_compile_cache = {}
-- Error suppression state
local error_suppressions = {}
local error_suppressions_2 = {}
-- Configuration
local valid_extensions = { c = true, h = true }
-- Precompiled regex patterns (only the ones still used)
local RE_SUPPRESSION = vim.regex([[\<NOLINT\>]])
local RE_COMMENTLINE = vim.regex([[^\s*//]])
local RE_PATTERN_INCLUDE = vim.regex([[^\s*#\s*include\s*\([<"]\)\([^>"]*\)[>"].*$]])
-- Assembly block matching (using Lua pattern instead of vim.regex for simplicity)
local function match_asm(line)
return line
|