Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-07-13 15:19:31 +0300
committerJoyee Cheung <joyeec9h3@gmail.com>2018-08-03 14:40:23 +0300
commit0da144f4d48d7a423b8f61cd178bb41346083107 (patch)
tree0bdf31c067fc7991fea2ebef0831930b55b0069c /Makefile
parent049c0464ce40cef17e8476b3e6b909bb10de469b (diff)
tools: add `make format-cpp` to run clang-format on C++ diffs
This patch adds a `make format-cpp` shortcut to the Makefile that runs clang-format on the C++ diffs, and a `make format-cpp-build` to install clang-format from npm. To format staged changes: ``` $ make format-cpp ``` To format HEAD~1...HEAD (latest commit): ``` $ CLANG_FORMAT_START=`git rev-parse HEAD~1` make format-cpp ``` To format diff between master and current branch head (master...HEAD): ``` $ CLANG_FORMAT_START=master make format-cpp ``` Most of the .clang-format file comes from running ``` $ clang-format --dump-config --style=Google ``` with clang-format built with llvm/trunk 328768 (npm version 1.2.3) The clang-format version is fixed because different version of clang-format may format the files differently. PR-URL: https://github.com/nodejs/node/pull/21997 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile27
1 files changed, 27 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index b228cbbf7a0..fc4a094656a 100644
--- a/Makefile
+++ b/Makefile
@@ -1169,6 +1169,33 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
# and the actual filename is generated so it won't match header guards
ADDON_DOC_LINT_FLAGS=-whitespace/ending_newline,-build/header_guard
+format-cpp-build:
+ cd tools/clang-format && $(call available-node,$(run-npm-install))
+
+format-cpp-clean:
+ $(RM) -r tools/clang-format/node_modules
+
+CLANG_FORMAT_START ?= HEAD
+.PHONY: format-cpp
+# To format staged changes:
+# $ make format-cpp
+# To format HEAD~1...HEAD (latest commit):
+# $ CLANG_FORMAT_START=`git rev-parse HEAD~1` make format-cpp
+# To format diff between master and current branch head (master...HEAD):
+# $ CLANG_FORMAT_START=master make format-cpp
+format-cpp: ## Format C++ diff from $CLANG_FORMAT_START to current changes
+ifneq ("","$(wildcard tools/clang-format/node_modules/)")
+ @echo "Formatting C++ diff from $(CLANG_FORMAT_START).."
+ @$(PYTHON) tools/clang-format/node_modules/.bin/git-clang-format \
+ --binary=tools/clang-format/node_modules/.bin/clang-format \
+ --style=file \
+ $(CLANG_FORMAT_START) -- \
+ $(LINT_CPP_FILES)
+else
+ @echo "clang-format is not installed."
+ @echo "To install (requires internet access) run: $ make format-cpp-build"
+endif
+
.PHONY: lint-cpp
# Lints the C++ code with cpplint.py and check-imports.py.
lint-cpp: tools/.cpplintstamp