MAKE - Format Trailing Whitespace

Add `make format-trailing-ws`.  This recipe finds all _files_ (not
links) known to Git and uses `sed` to remove trailing whitespace.

Signed-off-by: Jake Mercer <jake.mercer@civica.co.uk>
This commit is contained in:
Jake Mercer 2019-10-24 21:51:47 +01:00
parent 08e0cd701d
commit c05b4b0406
39 changed files with 272 additions and 248 deletions

View File

@ -58,7 +58,7 @@ test-cpp:
# Auto formatting of code.
# ------------------------
FORMAT_EXCLUDE = $(foreach x,$(ALL_EXCLUDE),-and -not -path './$(x)/*')
FORMAT_EXCLUDE = $(foreach x,$(ALL_EXCLUDE),-and -not -path './$(x)/*') -and -not -name *.bit
CLANG_FORMAT ?= clang-format-5.0
format-cpp:
@ -76,10 +76,34 @@ TCL_FORMAT ?= utils//tcl-reformat.sh
format-tcl:
find . -name \*.tcl $(FORMAT_EXCLUDE) -print0 | xargs -0 -P $$(nproc) -n 1 $(TCL_FORMAT)
format: format-cpp format-docs format-py format-tcl
# Command to find and replace trailing whitespace in-place using `sed` (This is
# placed inside quotes later so need to escape the "'")
WS_CMD = sed -i '\''s@\s\+$$@@g'\''
# File filter for files to fix trailing whitespace in, this is just a couple of
# chained bash conditionals ensuring that the file (indicated by {}, provided by
# xargs later) is a file, and not a directory or link. Also filters out .bit
# files as these are the only binary files currently tracked by Git and we don't
# want to inadvertently change these at all.
WS_FILTER = [ -f {} -a ! -L {} ] && [[ {} != *.bit ]]
# For every file piped to $(WS_FORMAT) apply the filter and perform the command,
# if a file does not match the filter, just returns true.
WS_FORMAT = xargs -P $$(nproc) -n 1 -I{} bash -c '$(WS_FILTER) && $(WS_CMD) {} || true'
format-trailing-ws:
# Use `git ls-files` to give us a complete list of tracked files to fix
# whitespace in; there is no point spending time processing anything that is
# not known to Git.
git ls-files | $(WS_FORMAT)
# Additionally fix untracked (but not ignored) files.
git ls-files -o --exclude-standard | $(WS_FORMAT)
format: format-cpp format-docs format-py format-tcl format-trailing-ws
@true
.PHONY: format format-cpp format-py format-tcl
.PHONY: format format-cpp format-py format-tcl format-trailing-ws
# Targets related to Project X-Ray databases
# ------------------------

View File

@ -23,7 +23,7 @@ SegbitsFileReader::iterator SegbitsFileReader::end() {
}
SegbitsFileReader::value_type::value_type(const absl::string_view& view) {
size_t separator_start = view.find_first_of(" \t");
size_t separator_start = view.find_first_of(" \t\n");
if (separator_start == absl::string_view::npos) {
tag_ = view;
bit_ = absl::string_view();