Skip to content

Improve clang-format check target by showing files which are not correctly formatted #91

@dariusarnold

Description

@dariusarnold

Hello, nice work creating/collecting all the examples.

I used your project to integrate clang-format into CMake. Doing that I adapted it slightly and want to suggest this as a possible improvement.
I found that the check target would just error if code was not formatted. In clang-format you can use the --dry--run and --Werror flags to get output of what was not formatted and also getting a sensible return code without grep.
My code for the custom target looks like this:

add_custom_target(clang-format-check
        COMMENT "Checking clang-format changes"
        COMMAND ${ClangFormat_EXECUTABLE}
        --style=file
        --dry-run
        --Werror
        ${ALL_SOURCE_FILES}
        )

The output when run:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions