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