sean-parent / tools

A place for scripts and tooling I find useful
32 stars 4 forks source link

Applescript implementation deviates from clang-format rules, due to `line_count_without-trailing_empty_lines`. #6

Open soerlemans opened 3 months ago

soerlemans commented 3 months ago

The following function will ignore trailing empty lines.

on line_count_without_trailing_empty_lines(_source)
    set _lines to (length of _source)
    if _lines = 0 then return 0

    repeat with _index from _lines to 1 by -1
        if item _index of _source � "" then
            return _index
        end if
    end repeat

    return 1
end line_count_without_trailing_empty_lines

https://github.com/sean-parent/tools/blob/be6d4a78404473935dea0d37bbed4509a19a548a/xcode-clang-format.applescript#L78

But when the following setting is set in .clang-format:

MaxEmptyLinesToKeep: 2

Then clang-format will fail to trim empty trailing lines. This means that using clang-foramt --dry-run -Werror to validate if a source file was properly formatted then it will fail. And then using the xcode-clang-format.applescript to format the file wont fix this.