pub const ERROR_CATEGORIES: &[&str] = &[
"build/c++11",
"build/c++17",
"build/deprecated",
"build/endif_comment",
"build/explicit_make_pair",
"build/forward_decl",
"build/header_guard",
"build/include",
"build/include_subdir",
"build/include_alpha",
"build/include_order",
"build/include_what_you_use",
"build/namespaces_headers",
"build/namespaces_literals",
"build/namespaces",
"build/printf_format",
"build/storage_class",
"legal/copyright",
"readability/alt_tokens",
"readability/braces",
"readability/casting",
"readability/check",
"readability/constructors",
"readability/fn_size",
"readability/inheritance",
"readability/multiline_comment",
"readability/multiline_string",
"readability/namespace",
"readability/nolint",
"readability/nul",
"readability/todo",
"readability/utf8",
"runtime/arrays",
"runtime/casting",
"runtime/explicit",
"runtime/int",
"runtime/init",
"runtime/invalid_increment",
"runtime/member_string_references",
"runtime/memset",
"runtime/operator",
"runtime/printf",
"runtime/printf_format",
"runtime/references",
"runtime/string",
"runtime/threadsafe_fn",
"runtime/vlog",
"whitespace/blank_line",
"whitespace/braces",
"whitespace/comma",
"whitespace/comments",
"whitespace/empty_conditional_body",
"whitespace/empty_if_body",
"whitespace/empty_loop_body",
"whitespace/end_of_line",
"whitespace/ending_newline",
"whitespace/forcolon",
"whitespace/indent",
"whitespace/indent_namespace",
"whitespace/line_length",
"whitespace/newline",
"whitespace/operators",
"whitespace/parens",
"whitespace/semicolon",
"whitespace/tab",
"whitespace/todo",
];
pub fn category(name: &str) -> Option<&'static str> {
ERROR_CATEGORIES.iter().copied().find(|c| *c == name)
}
pub const LEGACY_ERROR_CATEGORIES: &[&str] =
&["build/class", "readability/streams", "readability/function"];
pub const OTHER_NOLINT_CATEGORY_PREFIXES: &[&str] = &[
"clang-analyzer-",
"abseil-",
"altera-",
"android-",
"boost-",
"bugprone-",
"cert-",
"concurrency-",
"cppcoreguidelines-",
"darwin-",
"fuchsia-",
"google-",
"hicpp-",
"linuxkernel-",
"llvm-",
"llvmlibc-",
"misc-",
"modernize-",
"mpi-",
"objc-",
"openmp-",
"performance-",
"portability-",
"readability-",
"zircon-",
];
pub const DEFAULT_FILTERS: &[&str] = &[
"-build/include_alpha",
"-readability/fn_size",
"-runtime/references",
];
pub const DEFAULT_C_SUPPRESSED_CATEGORIES: &[&str] = &["readability/casting"];
pub const DEFAULT_KERNEL_SUPPRESSED_CATEGORIES: &[&str] = &["whitespace/tab"];
pub const CPP_HEADERS: &[&str] = &[
"algobase.h",
"algo.h",
"alloc.h",
"builtinbuf.h",
"bvector.h",
"defalloc.h",
"deque.h",
"editbuf.h",
"fstream.h",
"function.h",
"hash_map",
"hash_map.h",
"hash_set",
"hash_set.h",
"hashtable.h",
"heap.h",
"indstream.h",
"iomanip.h",
"iostream.h",
"istream.h",
"iterator.h",
"list.h",
"map.h",
"multimap.h",
"multiset.h",
"ostream.h",
"pair.h",
"parsestream.h",
"pfstream.h",
"procbuf.h",
"pthread_alloc",
"pthread_alloc.h",
"rope",
"rope.h",
"ropeimpl.h",
"set.h",
"slist",
"slist.h",
"stack.h",
"stdiostream.h",
"stl_alloc.h",
"stl_relops.h",
"streambuf.h",
"stream.h",
"strfile.h",
"strstream.h",
"tempbuf.h",
"tree.h",
"type_traits.h",
"vector.h",
"algorithm",
"array",
"atomic",
"bitset",
"chrono",
"codecvt",
"complex",
"condition_variable",
"deque",
"exception",
"forward_list",
"fstream",
"functional",
"future",
"initializer_list",
"iomanip",
"ios",
"iosfwd",
"iostream",
"istream",
"iterator",
"limits",
"list",
"locale",
"map",
"memory",
"mutex",
"new",
"numeric",
"ostream",
"queue",
"random",
"ratio",
"regex",
"scoped_allocator",
"set",
"sstream",
"stack",
"stdexcept",
"streambuf",
"string",
"strstream",
"system_error",
"thread",
"tuple",
"typeindex",
"typeinfo",
"type_traits",
"unordered_map",
"unordered_set",
"utility",
"valarray",
"vector",
"shared_mutex",
"any",
"charconv",
"execution",
"filesystem",
"memory_resource",
"optional",
"string_view",
"variant",
"barrier",
"bit",
"compare",
"concepts",
"coroutine",
"format",
"latch",
"numbers",
"ranges",
"semaphore",
"source_location",
"span",
"stop_token",
"syncstream",
"version",
"expected",
"flat_map",
"flat_set",
"generator",
"mdspan",
"print",
"spanstream",
"stacktrace",
"stdfloat",
"cassert",
"ccomplex",
"cctype",
"cerrno",
"cfenv",
"cfloat",
"cinttypes",
"ciso646",
"climits",
"clocale",
"cmath",
"csetjmp",
"csignal",
"cstdalign",
"cstdarg",
"cstdbool",
"cstddef",
"cstdint",
"cstdio",
"cstdlib",
"cstring",
"ctgmath",
"ctime",
"cuchar",
"cwchar",
"cwctype",
];
pub const C_HEADERS: &[&str] = &[
"assert.h",
"complex.h",
"ctype.h",
"errno.h",
"fenv.h",
"float.h",
"inttypes.h",
"iso646.h",
"limits.h",
"locale.h",
"math.h",
"setjmp.h",
"signal.h",
"stdalign.h",
"stdarg.h",
"stdatomic.h",
"stdbool.h",
"stddef.h",
"stdint.h",
"stdio.h",
"stdlib.h",
"stdnoreturn.h",
"string.h",
"tgmath.h",
"threads.h",
"time.h",
"uchar.h",
"wchar.h",
"wctype.h",
"stdbit.h",
"stdckdint.h",
"aio.h",
"arpa/inet.h",
"cpio.h",
"dirent.h",
"dlfcn.h",
"fcntl.h",
"fmtmsg.h",
"fnmatch.h",
"ftw.h",
"glob.h",
"grp.h",
"iconv.h",
"langinfo.h",
"libgen.h",
"monetary.h",
"mqueue.h",
"ndbm.h",
"net/if.h",
"netdb.h",
"netinet/in.h",
"netinet/tcp.h",
"nl_types.h",
"poll.h",
"pthread.h",
"pwd.h",
"regex.h",
"sched.h",
"search.h",
"semaphore.h",
"spawn.h",
"strings.h",
"stropts.h",
"syslog.h",
"tar.h",
"termios.h",
"trace.h",
"ulimit.h",
"unistd.h",
"utime.h",
"utmpx.h",
"wordexp.h",
"a.out.h",
"aliases.h",
"alloca.h",
"ar.h",
"argp.h",
"argz.h",
"byteswap.h",
"crypt.h",
"endian.h",
"envz.h",
"err.h",
"error.h",
"execinfo.h",
"fpu_control.h",
"fstab.h",
"fts.h",
"getopt.h",
"gshadow.h",
"ieee754.h",
"ifaddrs.h",
"libintl.h",
"mcheck.h",
"mntent.h",
"obstack.h",
"paths.h",
"printf.h",
"pty.h",
"resolv.h",
"shadow.h",
"sysexits.h",
"ttyent.h",
"elf.h",
"features.h",
"gconv.h",
"gnu-versions.h",
"lastlog.h",
"libio.h",
"link.h",
"malloc.h",
"memory.h",
"netash/ash.h",
"netatalk/at.h",
"netax25/ax25.h",
"neteconet/ec.h",
"netipx/ipx.h",
"netiucv/iucv.h",
"netpacket/packet.h",
"netrom/netrom.h",
"netrose/rose.h",
"nfs/nfs.h",
"nss.h",
"re_comp.h",
"regexp.h",
"sgtty.h",
"stab.h",
"stdc-predef.h",
"stdio_ext.h",
"syscall.h",
"termio.h",
"thread_db.h",
"ucontext.h",
"ustat.h",
"utmp.h",
"values.h",
"wait.h",
"xlocale.h",
"arm_neon.h",
"emmintrin.h",
"xmmintin.h",
];
pub const C_STANDARD_HEADER_FOLDERS_PATTERN: &str = r"(?:sys|arpa|asm-generic|bits|gnu|net|netinet|protocols|rpc|rpcsvc|scsi|drm|linux|misc|mtd|rdma|sound|video|xen)\/.*\.h";
pub const TYPES_PATTERN: &str = r"^(?:(char(16_t|32_t)?)|wchar_t|bool|short|int|long|signed|unsigned|float|double|(ptrdiff_t|size_t|max_align_t|nullptr_t)|(u?int(_fast|_least)?(8|16|32|64)_t)|(u?int(max|ptr)_t)|)$";
pub const THIRD_PARTY_HEADERS_PATTERN: &str =
r"^(?:[^/]*[A-Z][^/]*\.h|lua\.h|lauxlib\.h|lualib\.h)$";
pub const TEST_FILE_SUFFIX: &str = r"(_test|_regtest|_unittest)$";
pub const TEST_SUFFIXES: &[&str] = &["test", "regtest", "unittest"];
pub const CHECK_MACROS: &[&str] = &[
"DCHECK",
"CHECK",
"EXPECT_TRUE",
"ASSERT_TRUE",
"EXPECT_FALSE",
"ASSERT_FALSE",
];
pub fn check_replacement(macro_name: &str, op: &str) -> String {
let direct = match op {
"==" => "EQ",
"!=" => "NE",
">=" => "GE",
">" => "GT",
"<=" => "LE",
_ => "LT",
};
let inverted = match op {
"==" => "NE",
"!=" => "EQ",
">=" => "LT",
">" => "LE",
"<=" => "GT",
_ => "GE",
};
match macro_name {
"DCHECK" => format!("DCHECK_{direct}"),
"CHECK" => format!("CHECK_{direct}"),
"EXPECT_TRUE" => format!("EXPECT_{direct}"),
"ASSERT_TRUE" => format!("ASSERT_{direct}"),
"EXPECT_FALSE" => format!("EXPECT_{inverted}"),
_ => format!("ASSERT_{inverted}"),
}
}
pub fn alt_token_replacement(word: &str) -> &'static str {
match word {
"and" => "&&",
"bitor" => "|",
"or" => "||",
"xor" => "^",
"compl" => "~",
"bitand" => "&",
"and_eq" => "&=",
"or_eq" => "|=",
"xor_eq" => "^=",
"not" => "!",
_ => "!=",
}
}
pub const ALT_TOKEN_REPLACEMENT_PATTERN: &str =
r"([ =()])(and|bitor|or|xor|compl|bitand|and_eq|or_eq|xor_eq|not|not_eq)([ (]|$)";
pub const THREADING_LIST: &[(&str, &str, &str)] = &[
(
"asctime(",
"asctime_r(",
r"(?:[-+*/=%^&|(<]\s*|>\s+)asctime\([^)]+\)",
),
(
"ctime(",
"ctime_r(",
r"(?:[-+*/=%^&|(<]\s*|>\s+)ctime\([^)]+\)",
),
(
"getgrgid(",
"getgrgid_r(",
r"(?:[-+*/=%^&|(<]\s*|>\s+)getgrgid\([^)]+\)",
),
(
"getgrnam(",
"getgrnam_r(",
r"(?:[-+*/=%^&|(<]\s*|>\s+)getgrnam\([^)]+\)",
),
(
"getlogin(",
"getlogin_r(",
r"(?:[-+*/=%^&|(<]\s*|>\s+)getlogin\(\)",
),
(
"getpwnam(",
"getpwnam_r(",
r"(?:[-+*/=%^&|(<]\s*|>\s+)getpwnam\([^)]+\)",
),
(
"getpwuid(",
"getpwuid_r(",
r"(?:[-+*/=%^&|(<]\s*|>\s+)getpwuid\([^)]+\)",
),
(
"gmtime(",
"gmtime_r(",
r"(?:[-+*/=%^&|(<]\s*|>\s+)gmtime\([^)]+\)",
),
(
"localtime(",
"localtime_r(",
r"(?:[-+*/=%^&|(<]\s*|>\s+)localtime\([^)]+\)",
),
("rand(", "rand_r(", r"(?:[-+*/=%^&|(<]\s*|>\s+)rand\(\)"),
(
"strtok(",
"strtok_r(",
r"(?:[-+*/=%^&|(<]\s*|>\s+)strtok\([^)]+\)",
),
(
"ttyname(",
"ttyname_r(",
r"(?:[-+*/=%^&|(<]\s*|>\s+)ttyname\([^)]+\)",
),
];
pub const HEADERS_CONTAINING_TEMPLATES: &[(&str, &[&str])] = &[
("<deque>", &["deque"]),
(
"<functional>",
&[
"unary_function",
"binary_function",
"plus",
"minus",
"multiplies",
"divides",
"modulus",
"negate",
"equal_to",
"not_equal_to",
"greater",
"less",
"greater_equal",
"less_equal",
"logical_and",
"logical_or",
"logical_not",
"unary_negate",
"not1",
"binary_negate",
"not2",
"bind1st",
"bind2nd",
"pointer_to_unary_function",
"pointer_to_binary_function",
"ptr_fun",
"mem_fun_t",
"mem_fun",
"mem_fun1_t",
"mem_fun1_ref_t",
"mem_fun_ref_t",
"const_mem_fun_t",
"const_mem_fun1_t",
"const_mem_fun_ref_t",
"const_mem_fun1_ref_t",
"mem_fun_ref",
],
),
("<limits>", &["numeric_limits"]),
("<list>", &["list"]),
("<map>", &["multimap"]),
(
"<memory>",
&[
"allocator",
"make_shared",
"make_unique",
"shared_ptr",
"unique_ptr",
"weak_ptr",
],
),
("<queue>", &["queue", "priority_queue"]),
("<set>", &["set", "multiset"]),
("<stack>", &["stack"]),
("<string>", &["char_traits", "basic_string"]),
("<tuple>", &["tuple"]),
("<unordered_map>", &["unordered_map", "unordered_multimap"]),
("<unordered_set>", &["unordered_set", "unordered_multiset"]),
("<utility>", &["pair"]),
("<vector>", &["vector"]),
("<hash_map>", &["hash_map", "hash_multimap"]),
("<hash_set>", &["hash_set", "hash_multiset"]),
("<slist>", &["slist"]),
];
pub const HEADERS_MAYBE_TEMPLATES: &[(&str, &[&str])] = &[
(
"<algorithm>",
&["copy", "max", "min", "min_element", "sort", "transform"],
),
("<utility>", &["forward", "make_pair", "move", "swap"]),
];
pub const HEADERS_TYPES_OR_OBJS: &[(&str, &[&str])] = &[
("<string>", &["string"]),
(
"<iostream>",
&[
"cin", "cout", "cerr", "clog", "wcin", "wcout", "wcerr", "wclog",
],
),
("<cstdio>", &["FILE", "fpos_t"]),
];
pub const HEADERS_FUNCTIONS: &[(&str, &[&str])] = &[(
"<cstdio>",
&[
"fopen",
"freopen",
"fclose",
"fflush",
"setbuf",
"setvbuf",
"fread",
"fwrite",
"fgetc",
"getc",
"fgets",
"fputc",
"putc",
"fputs",
"getchar",
"gets",
"putchar",
"puts",
"ungetc",
"scanf",
"fscanf",
"sscanf",
"vscanf",
"vfscanf",
"vsscanf",
"printf",
"fprintf",
"sprintf",
"snprintf",
"vprintf",
"vfprintf",
"vsprintf",
"vsnprintf",
"ftell",
"fgetpos",
"fseek",
"fsetpos",
"clearerr",
"feof",
"ferror",
"perror",
"tmpfile",
"tmpnam",
],
)];
pub const MATCH_ASM: &str = r"^\s*(?:asm|_asm|__asm|__asm__)(?:\s+(volatile|__volatile__))?\s*[{(]";
pub const SEARCH_C_FILE: &str = r"\b(?:LINT_C_FILE|vim?:\s*.*(\s*|:)filetype=c(\s*|:|$))";
pub const SEARCH_KERNEL_FILE: &str = r"\b(?:LINT_KERNEL_FILE)";
pub const DEFAULT_HEADER_EXTENSIONS: &[&str] = &["h", "hh", "hpp", "hxx", "h++", "cuh"];
pub const DEFAULT_SOURCE_EXTENSIONS: &[&str] = &["c", "cc", "cpp", "cxx", "c++", "cu"];