Development/ClangTidy

    From The Document Foundation Wiki

    Clang-tidy's main documentation lives here: clang-tidy-docs


    In order to use clang-tidy in LibreOffice:

    make vim-ide-integration

    to generate the necessary compilation database that clang-tidy will use

    • create a .clang-tidy file in the root folder of the LibreOffice source tree. This is a JSON-formatted file, which contains stuff like
    {
        Checks: '-*,modernize-use-auto'
    }
    

    This file is interpreted as a comma-separated list of clang-tidy checks to turn on and off. The first part '-*' disables all of the default checks. And the second part 'modern-use-auto', will enable the check that converts code to use auto.

    • To run clang-tidy over the source, I use a shell script like:

    #!/bin/bash
    for i in $( make -s showmodules ); do
       # check if directory exists
       if [ -d $i ]
       then
           find $i -name '*.cxx' | sort -u | xargs --max-procs=8 --max-args=1 clang-tidy -fix
       fi
    done

    • the -fix parameter will (if the check supports it) attempt to automatically fix the code instead of just warning about it.

    Note that this fixing process is not 100% reliable and might need some hand editing.

    • A useful command to see all of the checks that your version of clang-tidy supports is:
    ~clang-tidy -list-checks -checks=*