This is an automated email from the ASF dual-hosted git repository.

aw pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/yetus.git


The following commit(s) were added to refs/heads/main by this push:
     new 832d8d2  YETUS-1019. Replace whitespace with blanks (#149)
832d8d2 is described below

commit 832d8d2fc26571068e308abe7210aebf1c4baa2a
Author: Allen Wittenauer <[email protected]>
AuthorDate: Thu Oct 8 14:47:33 2020 -0700

    YETUS-1019. Replace whitespace with blanks (#149)
---
 .yetus/blanks-eol.txt                              |  16 ++
 .yetus/blanks-tabs.txt                             |  16 ++
 .../in-progress/precommit/index.html.md            |   2 +-
 .../plugins/{whitespace.html.md => blanks.html.md} |  10 +-
 precommit/src/main/shell/test-patch.d/blanks.sh    | 207 +++++++++++++++++++++
 .../src/main/shell/test-patch.d/whitespace.sh      | 183 ------------------
 precommit/src/test/resources/blanks.txt            |  18 ++
 7 files changed, 264 insertions(+), 188 deletions(-)

diff --git a/.yetus/blanks-eol.txt b/.yetus/blanks-eol.txt
new file mode 100644
index 0000000..18a90de
--- /dev/null
+++ b/.yetus/blanks-eol.txt
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+precommit/src/test/resources/blanks.txt
diff --git a/.yetus/blanks-tabs.txt b/.yetus/blanks-tabs.txt
new file mode 100644
index 0000000..18a90de
--- /dev/null
+++ b/.yetus/blanks-tabs.txt
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+precommit/src/test/resources/blanks.txt
diff --git 
a/asf-site-src/source/documentation/in-progress/precommit/index.html.md 
b/asf-site-src/source/documentation/in-progress/precommit/index.html.md
index 3d31512..1f40028 100644
--- a/asf-site-src/source/documentation/in-progress/precommit/index.html.md
+++ b/asf-site-src/source/documentation/in-progress/precommit/index.html.md
@@ -77,6 +77,7 @@ Features are plug-in based and enabled either individually or 
collectively on th
 These plug-ins are native to Apace Yetus and are (usually!) always available:
 
 * [author](plugins/author)
+* [blanks](plugins/blanks)
 * [briefreport](plugins/briefreport)
 * [dupname](plugins/dupname)
 * [htmlout](plugins/htmlout)
@@ -84,7 +85,6 @@ These plug-ins are native to Apace Yetus and are (usually!) 
always available:
 * [pathlen](plugins/pathlen)
 * [slack](plugins/slack)
 * [unitveto](plugins/unitveto)
-* [whitespace](plugins/whitespace)
 * [xml](plugins/xml)
 
 ### Optional Plug-ins
diff --git 
a/asf-site-src/source/documentation/in-progress/precommit/plugins/whitespace.html.md
 
b/asf-site-src/source/documentation/in-progress/precommit/plugins/blanks.html.md
similarity index 68%
rename from 
asf-site-src/source/documentation/in-progress/precommit/plugins/whitespace.html.md
rename to 
asf-site-src/source/documentation/in-progress/precommit/plugins/blanks.html.md
index d8949c8..5d078a3 100644
--- 
a/asf-site-src/source/documentation/in-progress/precommit/plugins/whitespace.html.md
+++ 
b/asf-site-src/source/documentation/in-progress/precommit/plugins/blanks.html.md
@@ -19,7 +19,7 @@
 
 # Name
 
-whitespace
+blanks
 
 # Category
 
@@ -30,7 +30,9 @@ Test
 Provides a test to do two things:
 
 * Fail patches that use tabs instead of spaces (where appropriate)
-* End of line whitespace
+* End of line blank space
+
+By default, blanks will automatically ignore tabs in Makefiles and Go-related 
files.  However, if a file is provided, that file must also include the 
appropriate regexs for Makefiles and Go.
 
 # Environment Variables
 
@@ -40,8 +42,8 @@ None
 
 | Option | Notes |
 |:---------|:------|
-| `--whitespace-eol-ignore-list=<list>` | Comma-separated regex list of 
filenames |
-| `--whitespace-tabs-ignore-list=<list>` | Comma-separated regex list of 
filenames |
+| `--blanks-eol-ignore-file=<file>` | File containing regexs of files/dirs to 
ignore EOL blanks. Defaults to `.yetus/blanks-eol.txt` |
+| `--blanks-tabs-ignore-file=<file>` | File containing regexs of files/dirs to 
ignore tabs. Defaults to `.yetus/blanks-eol.txt` |
 
 # Docker Notes
 
diff --git a/precommit/src/main/shell/test-patch.d/blanks.sh 
b/precommit/src/main/shell/test-patch.d/blanks.sh
new file mode 100755
index 0000000..ad9f728
--- /dev/null
+++ b/precommit/src/main/shell/test-patch.d/blanks.sh
@@ -0,0 +1,207 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# SHELLDOC-IGNORE
+
+BLANKS_EOL_IGNORE_LIST=
+BLANKS_TABS_IGNORE_LIST='.*Makefile.*','.*\.go','.*go\.mod'
+BLANKS_EOL_IGNORE_FILE='.yetus/blanks-eol.txt'
+BLANKS_TABS_IGNORE_FILE='.yetus/blanks-tabs.txt'
+
+add_test_type blanks
+
+## @description  blanks usage hook
+## @audience     private
+## @stability    evolving
+## @replaceable  no
+function blanks_usage
+{
+  yetus_add_option "--blanks-eol-ignore-file=<file>" "file of regexes to 
ignore for EOLs (default '${BLANKS_EOL_IGNORE_FILE}')"
+  yetus_add_option "--blanks-tabs-ignore-file=<file>" "file of regexs to 
ignore tabs (default '${BLANKS_TABS_IGNORE_FILE}')"
+  #yetus_add_option "--whitespace-eol-ignore-list=<list>" "comma-separated 
regex list of filenames (default '${BLANKS_EOL_IGNORE_LIST}')"
+  #yetus_add_option "--whitespace-tabs-ignore-list=<list>" "comma-separated 
regex list of filenames (default '${BLANKS_TABS_IGNORE_LIST}')"
+}
+
+## @description  blanks parse args hook
+## @audience     private
+## @stability    evolving
+## @replaceable  no
+function blanks_parse_args
+{
+  declare i
+
+  for i in "$@"; do
+    case ${i} in
+      --blanks-eol-ignore-file=*)
+        delete_parameter "${i}"
+        BLANKS_EOL_IGNORE_FILE="${i#*=}"
+      ;;
+      --blanks-tabs-ignore-file=*)
+        delete_parameter "${i}"
+        BLANKS_TABS_IGNORE_FILE="${i#*=}"
+      ;;
+      # next two are for backward compatibility. We will remove them in the 
future
+      --whitespace-eol-ignore-list=*)
+        delete_parameter "${i}"
+        BLANKS_EOL_IGNORE_LIST="${i#*=}"
+      ;;
+      --whitespace-tabs-ignore-list=*)
+        delete_parameter "${i}"
+        BLANKS_TABS_IGNORE_LIST="${i#*=}"
+      ;;
+    esac
+  done
+}
+
+function blanks_linecomment_reporter
+{
+  declare file=$1
+  shift
+  declare comment=$*
+  declare tmpfile="${PATCH_DIR}/wlr.$$.${RANDOM}"
+
+  #shellcheck disable=SC2016
+  "${AWK}" -F: -v msg="${comment}" \
+    '{print $1":"$2":"msg}' \
+    "${file}" \
+    > "${tmpfile}"
+
+  bugsystem_linecomments_queue "blanks" "${tmpfile}"
+  rm "${tmpfile}"
+}
+
+function blanks_postcompile
+{
+  declare repostatus=$1
+  declare count
+  declare result=0
+  declare -a eolignore
+  declare -a tabsignore
+  declare -a globalignore
+  declare temp1
+  declare temp2
+  declare tmpfile1="${PATCH_DIR}/bl1.$$.${RANDOM}"
+  declare tmpfile2="${PATCH_DIR}/bl2.$$.${RANDOM}"
+
+
+  if [[ "${repostatus}" = branch ]]; then
+    return 0
+  fi
+
+  big_console_header "Checking for blanks issues."
+  start_clock
+
+  pushd "${BASEDIR}" >/dev/null || return 1
+
+  if [[ -f "${BLANKS_EOL_IGNORE_FILE}" ]]; then
+    "${GREP}" -E -v -e '^(#|$|[[:blank:]])' "${BLANKS_EOL_IGNORE_FILE}" > 
"${tmpfile1}"
+    eolignore=("${GREP}" "-v" "-E" "-f" "${tmpfile1}")
+  elif [[ -n "${BLANKS_EOL_IGNORE_LIST}" ]]; then
+    eolignore=("${GREP}" "-v")
+    yetus_comma_to_array temp1 "${BLANKS_EOL_IGNORE_LIST}" ""
+    for temp2 in "${temp1[@]}"; do
+      eolignore+=("-e" "^$temp2:")
+    done
+  else
+    eolignore=("cat")
+  fi
+
+  if [[ -f "${BLANKS_TABS_IGNORE_FILE}" ]]; then
+    "${GREP}" -E -v -e '^(#|$|[[:blank:]])' "${BLANKS_TABS_IGNORE_FILE}" > 
"${tmpfile2}"
+    tabsignore=("${GREP}" "-v" "-E" "-f" "${tmpfile2}")
+  elif [[ -n "${BLANKS_TABS_IGNORE_LIST}" ]]; then
+    tabsignore=("${GREP}" "-v")
+    yetus_comma_to_array temp1 "${BLANKS_TABS_IGNORE_LIST}"
+    for temp2 in "${temp1[@]}"; do
+      tabsignore+=("-e" "^$temp2:")
+    done
+  else
+    tabsignore=("cat")
+  fi
+
+  if [[ -n "${EXCLUDE_PATHS_FILE}" ]]; then
+    globalignore=("${GREP}" "-v" "-E" "-f" "${EXCLUDE_PATHS_FILE}")
+  else
+    globalignore=("cat")
+  fi
+
+  case "${BUILDMODE}" in
+    patch)
+       "${GREP}" -E '[[:blank:]]$' \
+         "${GITDIFFCONTENT}" \
+        | "${globalignore[@]}" \
+        | "${eolignore[@]}" > "${PATCH_DIR}/blanks-eol.txt"
+      # shellcheck disable=SC2016,SC2086
+      "${AWK}" '/\t/ {print $0}' \
+          "${GITDIFFCONTENT}" \
+        | "${globalignore[@]}" \
+        | "${tabsignore[@]}" > "${PATCH_DIR}/blanks-tabs.txt"
+    ;;
+    full)
+      "${GIT}" grep -n -I --extended-regexp '[[:blank:]]$' \
+        | "${globalignore[@]}" \
+        | "${eolignore[@]}" > "${PATCH_DIR}/blanks-eol.txt"
+      # shellcheck disable=SC2086
+      "${GIT}" grep -n -I $'\t' \
+        | "${globalignore[@]}" \
+        | "${tabsignore[@]}" > "${PATCH_DIR}/blanks-tabs.txt"
+    ;;
+  esac
+
+  rm "${tmpfile2}" "${tmpfile2}" 2>/dev/null
+
+  temp1=$(wc -l "${PATCH_DIR}/blanks-eol.txt")
+  count=${temp1%% *}
+
+  if [[ ${count} -gt 0 ]]; then
+    if [[ "${BUILDMODE}" = full ]]; then
+      add_vote_table_v2 -1 blanks \
+        "@@BASE@@/blanks-eol.txt" \
+        "${BUILDMODEMSG} has ${count} line(s) that end in blanks."
+    else
+      add_vote_table_v2 -1 blanks \
+        "@@BASE@@/blanks-eol.txt" \
+        "${BUILDMODEMSG} has ${count} line(s) that end in blanks. Use git 
apply --blanks=fix <<patch_file>>. Refer https://git-scm.com/docs/git-apply";
+    fi
+
+    if [[ -n "${BUGLINECOMMENTS}" ]]; then
+      blanks_linecomment_reporter "${PATCH_DIR}/blanks-eol.txt" "end of line"
+    fi
+    ((result=result+1))
+  fi
+
+  temp1=$(wc -l "${PATCH_DIR}/blanks-tabs.txt")
+  count=${temp1%% *}
+
+  if [[ ${count} -gt 0 ]]; then
+    add_vote_table_v2 -1 blanks \
+      "@@BASE@@/blanks-tabs.txt" \
+      "${BUILDMODEMSG} ${count} line(s) with tabs."
+    if [[ -n "${BUGLINECOMMENTS}" ]]; then
+      blanks_linecomment_reporter "${PATCH_DIR}/blanks-tabs.txt" "tabs in line"
+    fi
+    ((result=result+1))
+  fi
+
+  popd >/dev/null || return 1
+
+  if [[ ${result} -gt 0 ]]; then
+    return 1
+  fi
+
+  add_vote_table_v2 +1 blanks "" "${BUILDMODEMSG} has no blanks issues."
+  return 0
+}
diff --git a/precommit/src/main/shell/test-patch.d/whitespace.sh 
b/precommit/src/main/shell/test-patch.d/whitespace.sh
deleted file mode 100755
index 4eaef7b..0000000
--- a/precommit/src/main/shell/test-patch.d/whitespace.sh
+++ /dev/null
@@ -1,183 +0,0 @@
-#!/usr/bin/env bash
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# SHELLDOC-IGNORE
-
-WHITESPACE_EOL_IGNORE_LIST=
-WHITESPACE_TABS_IGNORE_LIST='.*Makefile.*','.*\.go','.*go\.mod'
-
-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 (default '${WHITESPACE_EOL_IGNORE_LIST}')"
-  yetus_add_option "--whitespace-tabs-ignore-list=<list>" "comma-separated 
regex list of filenames (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=*)
-        delete_parameter "${i}"
-        WHITESPACE_EOL_IGNORE_LIST="${i#*=}"
-      ;;
-      --whitespace-tabs-ignore-list=*)
-        delete_parameter "${i}"
-        WHITESPACE_TABS_IGNORE_LIST="${i#*=}"
-      ;;
-    esac
-  done
-}
-
-function whitespace_linecomment_reporter
-{
-  declare file=$1
-  shift
-  declare comment=$*
-  declare tmpfile="${PATCH_DIR}/wlr.$$.${RANDOM}"
-
-  #shellcheck disable=SC2016
-  "${AWK}" -F: -v msg="${comment}" \
-    '{print $1":"$2":"msg}' \
-    "${file}" \
-    > "${tmpfile}"
-
-  bugsystem_linecomments_queue "whitespace" "${tmpfile}"
-  rm "${tmpfile}"
-}
-
-function whitespace_postcompile
-{
-  declare repostatus=$1
-  declare count
-  declare result=0
-  declare -a eolignore
-  declare -a tabsignore
-  declare -a globalignore
-  declare temp1
-  declare temp2
-
-  if [[ "${repostatus}" = branch ]]; then
-    return 0
-  fi
-
-  big_console_header "Checking for whitespace issues."
-  start_clock
-
-  pushd "${BASEDIR}" >/dev/null || return 1
-
-  if [[ -n "${WHITESPACE_EOL_IGNORE_LIST}" ]]; then
-    eolignore=("${GREP}" "-v")
-    yetus_comma_to_array temp1 "${WHITESPACE_EOL_IGNORE_LIST}" ""
-    for temp2 in "${temp1[@]}"; do
-      eolignore+=("-e" "^$temp2:")
-    done
-  else
-    eolignore=("cat")
-  fi
-
-  if [[ -n "${WHITESPACE_TABS_IGNORE_LIST}" ]]; then
-    tabsignore=("${GREP}" "-v")
-    yetus_comma_to_array temp1 "${WHITESPACE_TABS_IGNORE_LIST}"
-    for temp2 in "${temp1[@]}"; do
-      tabsignore+=("-e" "^$temp2:")
-    done
-  else
-    tabsignore=("cat")
-  fi
-
-  if [[ -n "${EXCLUDE_PATHS_FILE}" ]]; then
-    globalignore=("${GREP}" "-v" "-E" "-f" "${EXCLUDE_PATHS_FILE}")
-  else
-    globalignore=("cat")
-  fi
-
-  case "${BUILDMODE}" in
-    patch)
-       "${GREP}" -E '[[:blank:]]$' \
-         "${GITDIFFCONTENT}" \
-        | "${globalignore[@]}" \
-        | "${eolignore[@]}" > "${PATCH_DIR}/whitespace-eol.txt"
-      # shellcheck disable=SC2016,SC2086
-      "${AWK}" '/\t/ {print $0}' \
-          "${GITDIFFCONTENT}" \
-        | "${globalignore[@]}" \
-        | "${tabsignore[@]}" > "${PATCH_DIR}/whitespace-tabs.txt"
-    ;;
-    full)
-      "${GIT}" grep -n -I --extended-regexp '[[:blank:]]$' \
-        | "${globalignore[@]}" \
-        | "${eolignore[@]}" > "${PATCH_DIR}/whitespace-eol.txt"
-      # shellcheck disable=SC2086
-      "${GIT}" grep -n -I $'\t' \
-        | "${globalignore[@]}" \
-        | "${tabsignore[@]}" > "${PATCH_DIR}/whitespace-tabs.txt"
-    ;;
-  esac
-
-  temp1=$(wc -l "${PATCH_DIR}/whitespace-eol.txt")
-  count=${temp1%% *}
-
-  if [[ ${count} -gt 0 ]]; then
-    if [[ "${BUILDMODE}" = full ]]; then
-      add_vote_table_v2 -1 whitespace \
-        "@@BASE@@/whitespace-eol.txt" \
-        "${BUILDMODEMSG} has ${count} line(s) that end in whitespace."
-    else
-      add_vote_table_v2 -1 whitespace \
-        "@@BASE@@/whitespace-eol.txt" \
-        "${BUILDMODEMSG} has ${count} line(s) that end in whitespace. Use git 
apply --whitespace=fix <<patch_file>>. Refer https://git-scm.com/docs/git-apply";
-    fi
-
-    if [[ -n "${BUGLINECOMMENTS}" ]]; then
-      whitespace_linecomment_reporter "${PATCH_DIR}/whitespace-eol.txt" "end 
of line"
-    fi
-    ((result=result+1))
-  fi
-
-  temp1=$(wc -l "${PATCH_DIR}/whitespace-tabs.txt")
-  count=${temp1%% *}
-
-  if [[ ${count} -gt 0 ]]; then
-    add_vote_table_v2 -1 whitespace \
-      "@@BASE@@/whitespace-tabs.txt" \
-      "${BUILDMODEMSG} ${count} line(s) with tabs."
-    if [[ -n "${BUGLINECOMMENTS}" ]]; then
-      whitespace_linecomment_reporter "${PATCH_DIR}/whitespace-tabs.txt" "tabs 
in line"
-    fi
-    ((result=result+1))
-  fi
-
-  popd >/dev/null || return 1
-
-  if [[ ${result} -gt 0 ]]; then
-    return 1
-  fi
-
-  add_vote_table_v2 +1 whitespace "" "${BUILDMODEMSG} has no whitespace 
issues."
-  return 0
-}
diff --git a/precommit/src/test/resources/blanks.txt 
b/precommit/src/test/resources/blanks.txt
new file mode 100644
index 0000000..e52aac8
--- /dev/null
+++ b/precommit/src/test/resources/blanks.txt
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+end of line 
+       tabs
+

Reply via email to