cmake_format icon indicating copy to clipboard operation
cmake_format copied to clipboard

cmake-format merges two comment lines and breaks cmake-lint disable comment

Open berthin opened this issue 1 year ago • 1 comments

Hi,

I am running cmake-format and cmake-lint as part of my pre-commit check with the following snippet:

    # Loop through submodules
    # cmake-lint: disable=E1120      
    foreach(IDX RANGE ${_SUBMODULES_COUNT})

cmake-lint is happy about that, but cmake-format sees that it can merge the two lines because they are comments, doesn't recognize that one is actual an internal cmake-* instruction, and joins them into

    # Loop through submodules cmake-lint: disable=E1120      
    foreach(IDX RANGE ${_SUBMODULES_COUNT})

and now cmake-lint complains about E1120 because that rule is not disabled anymore.

Anyway to workaround this issue? I looked at the cmake-format options but didn't find an "ignore_comment_regex" or similar option that I can use to tell cmake-format to ignore the formatting if it finds a comment that matches a regex.

I also think this is a bug. "cmake-lint" is an internal instruction from the same family tools as cmake-format, why would it not understand that?

berthin avatar Oct 04 '23 10:10 berthin

The workaround I use is

    # cmake-format: off
    # cmake-lint: disable=E1120
    # cmake-format: on

but this is kind of ugly to be honest

berthin avatar Oct 04 '23 10:10 berthin