tools icon indicating copy to clipboard operation
tools copied to clipboard

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

Open soerlemans opened this issue 1 year ago • 0 comments

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.

soerlemans avatar Jul 23 '24 11:07 soerlemans