cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
941 stars 103 forks source link

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

Open berthin opened 9 months ago

berthin commented 9 months ago

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 commented 9 months ago

The workaround I use is

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

but this is kind of ugly to be honest