You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@yetus.apache.org by aw...@apache.org on 2018/12/10 06:59:55 UTC
[3/5] yetus git commit: YETUS-35. add support for jshint
YETUS-35. add support for jshint
Signed-off-by: Allen Wittenauer <aw...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/yetus/repo
Commit: http://git-wip-us.apache.org/repos/asf/yetus/commit/dcc2e5b3
Tree: http://git-wip-us.apache.org/repos/asf/yetus/tree/dcc2e5b3
Diff: http://git-wip-us.apache.org/repos/asf/yetus/diff/dcc2e5b3
Branch: refs/heads/master
Commit: dcc2e5b3251c04a39fe7bf7911cc5e0c98ca71fb
Parents: 8a502dc
Author: Allen Wittenauer <aw...@apache.org>
Authored: Sun Oct 7 10:43:19 2018 -0700
Committer: Allen Wittenauer <aw...@apache.org>
Committed: Sun Dec 9 22:26:00 2018 -0800
----------------------------------------------------------------------
.jshintignore | 17 ++
.../src/main/shell/test-patch-docker/Dockerfile | 12 ++
precommit/src/main/shell/test-patch.d/jshint.sh | 207 +++++++++++++++++++
3 files changed, 236 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/yetus/blob/dcc2e5b3/.jshintignore
----------------------------------------------------------------------
diff --git a/.jshintignore b/.jshintignore
new file mode 100644
index 0000000..1d524fc
--- /dev/null
+++ b/.jshintignore
@@ -0,0 +1,17 @@
+# 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.
+asf-site-src/source/assets/js/bootstrap.js
+asf-site-src/source/assets/js/bootstrap.min.js
+asf-site-src/source/assets/js/jquery-2.1.4.min.js
http://git-wip-us.apache.org/repos/asf/yetus/blob/dcc2e5b3/precommit/src/main/shell/test-patch-docker/Dockerfile
----------------------------------------------------------------------
diff --git a/precommit/src/main/shell/test-patch-docker/Dockerfile b/precommit/src/main/shell/test-patch-docker/Dockerfile
index 501e0c6..161c42d 100644
--- a/precommit/src/main/shell/test-patch-docker/Dockerfile
+++ b/precommit/src/main/shell/test-patch-docker/Dockerfile
@@ -167,6 +167,18 @@ RUN curl -L -s -S \
shasum -a 512 /bin/hadolint | \
awk '$1!="f42e69dddfd2e4ce69848cc67b0800be9ae7ac729360fb9aa7250ee84499e635dc524a470766570d7fa2bd57c58529c4dbbefea80f583e5640b651d4a3b10f63" {exit(1)}'
+###
+# Install npm and JSHint
+###
+# hadolint ignore=DL3008,DL3016
+RUN apt-get -q update \
+ && apt-get -q install --no-install-recommends -y nodejs npm \
+ && apt-get clean \
+ && rm -rf /var/lib/apt/lists/* && \
+ ln -s /usr/bin/nodejs /usr/bin/node && \
+ npm install -g npm@latest && \
+ npm install -g jshint
+
####
# YETUS CUT HERE
# Anthing after the above line is ignored by Yetus, so could
http://git-wip-us.apache.org/repos/asf/yetus/blob/dcc2e5b3/precommit/src/main/shell/test-patch.d/jshint.sh
----------------------------------------------------------------------
diff --git a/precommit/src/main/shell/test-patch.d/jshint.sh b/precommit/src/main/shell/test-patch.d/jshint.sh
new file mode 100755
index 0000000..0fcf0de
--- /dev/null
+++ b/precommit/src/main/shell/test-patch.d/jshint.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.
+
+# no public APIs here
+# SHELLDOC-IGNORE
+
+add_test_type jshint
+
+JSHINT_TIMER=0
+JSHINT=${JSHINT:-$(command -v jshint 2>/dev/null)}
+
+function jshint_usage
+{
+ yetus_add_option "--jshint-cmd=<cmd>" "The 'jshint' command to use (default: ${JSHINT})"
+}
+
+## @description parse maven build tool args
+## @replaceable yes
+## @audience public
+## @stability stable
+function jshint_parse_args
+{
+ declare i
+
+ for i in "$@"; do
+ case ${i} in
+ --jshint-cmd=*)
+ JSHINT=${i#*=}
+ ;;
+ esac
+ done
+}
+
+function jshint_filefilter
+{
+ declare filename=$1
+
+ if [[ ${filename} =~ \.js$ ]] ||
+ [[ ${filename} =~ .jshintignore ]] ||
+ [[ ${filename} =~ .jshintrc ]]; then
+ add_test jshint
+ fi
+}
+
+function jshint_precheck
+{
+ if ! verify_command "jshint" "${JSHINT}"; then
+ add_vote_table 0 jshint "jshint was not available."
+ delete_test jshint
+ fi
+
+ cat > "${PATCH_DIR}/jshintreporter.js" << EOF
+"use strict";
+
+module.exports = {
+ reporter: function (res) {
+ var len = res.length;
+ var str = "";
+
+ res.forEach(function (r) {
+ var file = r.file;
+ var err = r.error;
+
+ str += file + ":" +
+ err.line + ":" +
+ err.character + ":" +
+ err.code + ":" +
+ err.reason + "\\n";
+ });
+
+ if (str) {
+ process.stdout.write(str + "\\n" + len + " error" +
+ ((len === 1) ? "" : "s") + "\\n");
+ }
+ }
+};
+EOF
+}
+
+function jshint_logic
+{
+ declare repostatus=$1
+ declare -i count
+
+ pushd "${BASEDIR}" >/dev/null || return 1
+ "${JSHINT}" \
+ --extract=auto \
+ --reporter="${PATCH_DIR}/jshintreporter.js" \
+ . \
+ > "${PATCH_DIR}/${repostatus}-jshint-result.full.txt"
+
+ # strip the last two lines
+ #shellcheck disable=SC2016
+ count=$(wc -l "${PATCH_DIR}/${repostatus}-jshint-result.full.txt" | "${AWK}" '{print $1}')
+ ((count=count-2))
+ if [[ "${count}" -gt 0 ]]; then
+ head "-${count}" "${PATCH_DIR}/${repostatus}-jshint-result.full.txt"\
+ > "${PATCH_DIR}/${repostatus}-jshint-result.txt"
+ else
+ touch "${PATCH_DIR}/${repostatus}-jshint-result.txt"
+ fi
+ popd > /dev/null || return 1
+}
+
+function jshint_preapply
+{
+ if ! verify_needed_test jshint; then
+ return 0
+ fi
+
+ big_console_header "jshint plugin: ${PATCH_BRANCH}"
+
+ start_clock
+
+ jshint_logic branch
+
+ # keep track of how much as elapsed for us already
+ JSHINT_TIMER=$(stop_clock)
+ return 0
+}
+
+## filename:line:character:code:error msg
+function jshint_calcdiffs
+{
+ column_calcdiffs "$@"
+}
+
+function jshint_postapply
+{
+ declare i
+ declare numPrepatch
+ declare numPostpatch
+ declare diffPostpatch
+ declare fixedpatch
+ declare statstring
+
+ if ! verify_needed_test jshint; then
+ return 0
+ fi
+
+ big_console_header "jshint plugin: ${BUILDMODE}"
+
+ start_clock
+
+ # add our previous elapsed to our new timer
+ # by setting the clock back
+ offset_clock "${JSHINT_TIMER}"
+
+ jshint_logic patch
+
+ calcdiffs \
+ "${PATCH_DIR}/branch-jshint-result.txt" \
+ "${PATCH_DIR}/patch-jshint-result.txt" \
+ jshint \
+ > "${PATCH_DIR}/diff-patch-jshint.txt"
+
+ # shellcheck disable=SC2016
+ numPrepatch=$(wc -l "${PATCH_DIR}/branch-jshint-result.txt" | ${AWK} '{print $1}')
+
+ # shellcheck disable=SC2016
+ numPostpatch=$(wc -l "${PATCH_DIR}/patch-jshint-result.txt" | ${AWK} '{print $1}')
+
+ # shellcheck disable=SC2016
+ diffPostpatch=$(wc -l "${PATCH_DIR}/diff-patch-jshint.txt" | ${AWK} '{print $1}')
+
+
+ ((fixedpatch=numPrepatch-numPostpatch+diffPostpatch))
+
+ statstring=$(generic_calcdiff_status "${numPrepatch}" "${numPostpatch}" "${diffPostpatch}" )
+
+ if [[ ${diffPostpatch} -gt 0 ]] ; then
+ add_vote_table -1 jshint "${BUILDMODEMSG} ${statstring}"
+ add_footer_table jshint "@@BASE@@/diff-patch-jshint.txt"
+ bugsystem_linecomments "jshint" "${PATCH_DIR}/diff-patch-jshint.txt"
+ return 1
+ elif [[ ${fixedpatch} -gt 0 ]]; then
+ add_vote_table +1 jshint "${BUILDMODEMSG} ${statstring}"
+ return 0
+ fi
+
+ add_vote_table +1 jshint "There were no new jshint issues."
+ return 0
+}
+
+function jshint_precompile
+{
+ declare repostatus=$1
+
+ if [[ "${repostatus}" = branch ]]; then
+ jshint_preapply
+ else
+ jshint_postapply
+ fi
+}