apply-clang-tidy.sh revision 1.1.1.1.2.2 1 #! /usr/bin/env bash
2 # __ __ _
3 # ___\ \/ /_ __ __ _| |_
4 # / _ \\ /| '_ \ / _` | __|
5 # | __// \| |_) | (_| | |_
6 # \___/_/\_\ .__/ \__,_|\__|
7 # |_| XML parser
8 #
9 # Copyright (c) 2024-2026 Sebastian Pipping <sebastian (at] pipping.org>
10 # Licensed under the MIT license:
11 #
12 # Permission is hereby granted, free of charge, to any person obtaining
13 # a copy of this software and associated documentation files (the
14 # "Software"), to deal in the Software without restriction, including
15 # without limitation the rights to use, copy, modify, merge, publish,
16 # distribute, sublicense, and/or sell copies of the Software, and to permit
17 # persons to whom the Software is furnished to do so, subject to the
18 # following conditions:
19 #
20 # The above copyright notice and this permission notice shall be included
21 # in all copies or substantial portions of the Software.
22 #
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
26 # NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27 # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
29 # USE OR OTHER DEALINGS IN THE SOFTWARE.
30
31 set -e -u -o pipefail
32
33 cd "$(dirname "$(type -P "$0")")"
34
35 checks_to_enable=(
36 bugprone-narrowing-conversions
37 bugprone-suspicious-string-compare
38 misc-no-recursion
39 readability-avoid-const-params-in-decls
40 readability-named-parameter
41 )
42 checks_to_enable_flat="${checks_to_enable[*]}" # i.e. flat string separated by spaces
43
44 checks_to_disable=(
45 # Would need a closer look before any adjustments
46 clang-analyzer-optin.performance.Padding
47
48 # Used only in xmlwf, manually checked to be good enough for now
49 clang-analyzer-security.insecureAPI.strcpy
50 )
51 checks_to_disable_flat="${checks_to_disable[*]}" # i.e. flat string separated by spaces
52
53 checks="${checks_to_enable_flat// /,},-${checks_to_disable_flat// /,-}"
54
55 args=(
56 --checks="${checks}"
57 --header-filter='.*' # .. to display errors from all non-system headers
58 --warnings-as-errors=\*
59 )
60
61 flags=(
62 -std=c99
63
64 -Ilib/
65
66 -DENCODING_FOR_FUZZING=UTF-8
67 -DXML_ATTR_INFO
68 -DXML_CLANG_TIDY
69 -DXML_DTD
70 -DXML_GE
71 -DXML_NS
72 -DXML_TESTING
73 )
74
75 if [[ $# -gt 0 ]]; then
76 files=( "$@" )
77 else
78 # For the list of excluded files please note:
79 # https://github.com/libexpat/libexpat/issues/119
80 files=( $(
81 git ls-files -- \*.c | grep -v \
82 -e '^lib/xcsinc\.c$' \
83 -e '^xmlwf/ct\.c$' \
84 -e '^xmlwf/xmlmime\.c$' \
85 -e '^xmlwf/win32filemap\.c$' \
86 ) )
87 fi
88
89 set -x
90
91 type -P clang-tidy
92
93 clang-tidy --version
94
95 clang-tidy --checks="${checks}" --verify-config
96
97 clang-tidy --checks="${checks}" --list-checks
98
99 # These are the checks clang-tidy has *more* that so far we are missing out on,
100 # for good and for bad
101 clang-tidy --checks=\* --list-checks \
102 | grep -v -f <(clang-tidy --checks="${checks}" --list-checks | xargs -n1) \
103 | sed 's,\(\s*\)\([^-]\+\)-[^ ]\+,\1\2-*,' \
104 | sort -u \
105 | sed 's/^$/Disabled checks (simplified):/'
106
107 pwd
108
109 exec clang-tidy "${args[@]}" "${files[@]}" -- "${flags[@]}"
110