5 # "script-and-regex.regex": "/^(?P<severity>.*?)\n(?P<message>.*?)\n(?P<line>\\d),(?P<char>\\d)(\n(?P<original>.*?)>>>>\n(?P<replacement>.*?)<<<<?)$/s",
7 # Arcanist linter that invokes clang-format.
8 # stdout from this script is parsed into a regex and used by Arcanist.
9 # https://secure.phabricator.com/book/phabricator/article/arcanist_lint_script_and_regex/
11 # To skip running all linters when creating/updating a diff, use `arc diff --nolint`.
13 if ! hash git-clang-format >/dev/null; then
14 # advice severity level is completely non-disruptive.
15 # switch to warning or error if you want to prompt the user.
17 echo "git-clang-format not found in user's PATH; not linting file."
23 original_file="$(mktemp)"
24 formatted_file="$(mktemp)"
26 readonly original_file
27 readonly formatted_file
28 cp -p "${src_file}" "${original_file}"
29 cp -p "${src_file}" "${formatted_file}"
33 rm "${formatted_file}" "${original_file}"
36 trap 'cleanup' INT HUP QUIT TERM EXIT
38 # Arcanist can filter out lint messages for unchanged lines, but for that, we
39 # need to generate line by line lint messages. Instead, we generate one lint
40 # message on line 1, char 1 with file content edited using git-clang-format.
41 if git rev-parse --git-dir >/dev/null; then
42 arc_base_commit=$(arc which --show-base)
43 # An alternative is to use git-clang-format.
44 >&2 git-clang-format --quiet --force --style file "${arc_base_commit}"
46 >&2 echo "repo is expected to be a git directory"
49 cp -p "${src_file}" "${formatted_file}"
50 cp -p "${original_file}" "${src_file}"
51 if ! diff -q "${src_file}" "${formatted_file}" > /dev/null ; then
53 echo "clang-format suggested style edits found:"
54 echo "1,1" # line,char of start of replacement.
57 cat "${formatted_file}"