BlankSpruce / gersemi

A formatter to make your CMake code the real treasure
Mozilla Public License 2.0
156 stars 8 forks source link

Changing the tab size back and forth does produce a different formatting than doing nothing. #28

Closed adamryczkowski closed 6 months ago

adamryczkowski commented 6 months ago

I did play with the crazy tab indent of size 15 and noticed one thing:

After formatting this piece of code:

    checkgitversion("${CheckGitSetup_REPOSITORY_PATH}"  "${CheckGitSetup_TEMPLATE_FILE}"  "${CheckGitSetup_OUTPUT_FILE}"  "${CheckGitSetup_INCLUDE_HEADER}")

with the indent 15 and then back to 4 again, I arrived with a different string:

    checkgitversion("${CheckGitSetup_REPOSITORY_PATH}"             "${CheckGitSetup_TEMPLATE_FILE}"             "${CheckGitSetup_OUTPUT_FILE}"             "${CheckGitSetup_INCLUDE_HEADER}")
BlankSpruce commented 6 months ago

More data needed:

function log() { echo "[reproduction]" $@ }

function show-diff() { git diff $1 $2 && log "-- Files are identical" }

log "Create CMake file" cat < /tmp/gersemi-28-repro.cmake checkgitversion("\${CheckGitSetup_REPOSITORY_PATH}" "\${CheckGitSetup_TEMPLATE_FILE}" "\${CheckGitSetup_OUTPUT_FILE}" "\${CheckGitSetup_INCLUDE_HEADER}") EOF

log "Run gersemi first time with indent=15" gersemi --indent 15 /tmp/gersemi-28-repro.cmake > /tmp/gersemi-28-repro-after-first-time.cmake

log "Run gersemi second time with indent=4" gersemi --indent 4 /tmp/gersemi-28-repro-after-first-time.cmake > /tmp/gersemi-28-repro-after-second-time.cmake

log "Show diff between original and first reformatting" show-diff /tmp/gersemi-28-repro.cmake /tmp/gersemi-28-repro-after-first-time.cmake

log "Show diff between original and second reformatting" show-diff /tmp/gersemi-28-repro.cmake /tmp/gersemi-28-repro-after-second-time.cmake

log "Show diff between first and second reformatting" show-diff /tmp/gersemi-28-repro-after-first-time.cmake /tmp/gersemi-28-repro-after-second-time.cmake



![image](https://github.com/BlankSpruce/gersemi/assets/32396809/364c30f2-b0a5-4fda-8b23-63bb5c782b59)
BlankSpruce commented 6 months ago

I think I got it. Your example omitted if()/endif() or anything similar that introduces a block. A proper example is:

if(TRUE)
    checkgitversion("${CheckGitSetup_REPOSITORY_PATH}"  "${CheckGitSetup_TEMPLATE_FILE}"  "${CheckGitSetup_OUTPUT_FILE}"  "${CheckGitSetup_INCLUDE_HEADER}")
endif()

I'll fix that in 0.13.1.