Repository: yetus Updated Branches: refs/heads/master 938504b64 -> 9740b6401
YETUS-461. Allow specifying exclusions for whitespace report Signed-off-by: Sean Busbey <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/yetus/repo Commit: http://git-wip-us.apache.org/repos/asf/yetus/commit/9740b640 Tree: http://git-wip-us.apache.org/repos/asf/yetus/tree/9740b640 Diff: http://git-wip-us.apache.org/repos/asf/yetus/diff/9740b640 Branch: refs/heads/master Commit: 9740b6401945ef56ad568a73e650267a422838c3 Parents: 938504b Author: Kengo Seki <[email protected]> Authored: Thu Sep 22 23:49:51 2016 +0900 Committer: Sean Busbey <[email protected]> Committed: Fri Oct 28 21:07:14 2016 -0500 ---------------------------------------------------------------------- precommit/test-patch.d/whitespace.sh | 50 ++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/yetus/blob/9740b640/precommit/test-patch.d/whitespace.sh ---------------------------------------------------------------------- diff --git a/precommit/test-patch.d/whitespace.sh b/precommit/test-patch.d/whitespace.sh index b7ac27a..390f15f 100755 --- a/precommit/test-patch.d/whitespace.sh +++ b/precommit/test-patch.d/whitespace.sh @@ -14,8 +14,41 @@ # See the License for the specific language governing permissions and # limitations under the License. +WHITESPACE_EOL_IGNORE_LIST= +WHITESPACE_TABS_IGNORE_LIST=Makefile + add_test_type whitespace +## @description whitespace usage hook +## @audience private +## @stability evolving +## @replaceable no +function whitespace_usage +{ + yetus_add_option "--whitespace-eol-ignore-list=<list>" "comma-separated regex list of filenames to ignore on checking whitespaces at EOL (default '${WHITESPACE_EOL_IGNORE_LIST}')" + yetus_add_option "--whitespace-tabs-ignore-list=<list>" "comma-separated regex list of filenames to ignore on checking tabs in a file (default '${WHITESPACE_TABS_IGNORE_LIST}')" +} + +## @description whitespace parse args hook +## @audience private +## @stability evolving +## @replaceable no +function whitespace_parse_args +{ + declare i + + for i in "$@"; do + case ${i} in + --whitespace-eol-ignore-list=*) + yetus_comma_to_array WHITESPACE_EOL_IGNORE_LIST "${i#*=}" + ;; + --whitespace-tabs-ignore-list=*) + yetus_comma_to_array WHITESPACE_TABS_IGNORE_LIST "${i#*=}" + ;; + esac + done +} + function whitespace_linecomment_reporter { declare file=$1 @@ -40,6 +73,8 @@ function whitespace_postcompile declare repostatus=$1 declare count declare result=0 + declare eolignore + declare tabsignore if [[ "${repostatus}" = branch ]]; then return 0 @@ -50,22 +85,29 @@ function whitespace_postcompile pushd "${BASEDIR}" >/dev/null + eolignore=$(printf -- "-e ^%s: " "${WHITESPACE_EOL_IGNORE_LIST[@]}") + tabsignore=$(printf -- "-e ^%s: " "${WHITESPACE_TABS_IGNORE_LIST[@]}") + case "${BUILDMODE}" in patch) - # shellcheck disable=SC2016 + # shellcheck disable=SC2016,SC2086 ${AWK} '/\t/ {print $0}' \ "${GITDIFFCONTENT}" \ - | ${GREP} -v Makefile: >> "${PATCH_DIR}/whitespace-tabs.txt" + | ${GREP} -v ${tabsignore} >> "${PATCH_DIR}/whitespace-tabs.txt" + # shellcheck disable=SC2086 ${GREP} -E '[[:blank:]]$' \ "${GITDIFFCONTENT}" \ - >> "${PATCH_DIR}/whitespace-eol.txt" + | ${GREP} -v ${eolignore} >> "${PATCH_DIR}/whitespace-eol.txt" ;; full) + # shellcheck disable=SC2086 ${GIT} grep -n -I --extended-regexp '[[:blank:]]$' \ + | "${GREP}" -v ${eolignore} \ >> "${PATCH_DIR}/whitespace-eol.txt" + # shellcheck disable=SC2086 ${GIT} grep -n -I $'\t' \ - | "${GREP}" -v Makefile \ + | "${GREP}" -v ${tabsignore} \ >> "${PATCH_DIR}/whitespace-tabs.txt" ;; esac
