You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@yetus.apache.org by aw...@apache.org on 2022/04/29 16:23:00 UTC

[yetus] branch main updated: YETUS-1166. Add jsonlint support (#262)

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 f7563b60 YETUS-1166. Add jsonlint support (#262)
f7563b60 is described below

commit f7563b60ab9e7c9fc0e6d5d1cfec6481222aead7
Author: Allen Wittenauer <aw...@apache.org>
AuthorDate: Fri Apr 29 09:22:57 2022 -0700

    YETUS-1166. Add jsonlint support (#262)
---
 .../in-progress/precommit/plugins/jsonlint.md      |  48 +++++++
 precommit/src/main/shell/plugins.d/jsonlint.sh     | 150 +++++++++++++++++++++
 .../src/main/shell/test-patch-docker/Dockerfile    |   2 +
 3 files changed, 200 insertions(+)

diff --git a/asf-site-src/source/documentation/in-progress/precommit/plugins/jsonlint.md b/asf-site-src/source/documentation/in-progress/precommit/plugins/jsonlint.md
new file mode 100644
index 00000000..78b6b883
--- /dev/null
+++ b/asf-site-src/source/documentation/in-progress/precommit/plugins/jsonlint.md
@@ -0,0 +1,48 @@
+<!---
+  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.
+-->
+
+# Name
+
+jsonlint
+
+# Category
+
+Test
+
+# Description
+
+[jsonlint](https://github.com/zaach/jsonlint) lints JSON.
+
+# Environment Variables
+
+None
+
+# Options
+
+| Option | Notes |
+|:---------|:------|
+| `--jsonlint=<file>` | Location of the `jsonlint` binary if it is not on the path |
+
+# Docker Notes
+
+None
+
+# Developer Notes
+
+None
diff --git a/precommit/src/main/shell/plugins.d/jsonlint.sh b/precommit/src/main/shell/plugins.d/jsonlint.sh
new file mode 100755
index 00000000..f69bb61b
--- /dev/null
+++ b/precommit/src/main/shell/plugins.d/jsonlint.sh
@@ -0,0 +1,150 @@
+#!/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
+
+add_test_type jsonlint
+
+JSONLINT_TIMER=0
+
+JSONLINT=${JSONLINT:-$(command -v jsonlint 2>/dev/null)}
+
+function jsonlint_usage
+{
+  yetus_add_option "--jsonlint=<file>" "path to jsonlint executable"
+}
+
+function jsonlint_parse_args
+{
+  declare i
+
+  for i in "$@"; do
+    case ${i} in
+      --jsonlint=*)
+        JSONLINT=${i#*=}
+        delete_parameter "${i}"
+      ;;
+    esac
+  done
+}
+
+function jsonlint_filefilter
+{
+  declare filename=$1
+
+  if [[ ${filename} =~ \.json$ ]]; then
+    add_test jsonlint
+  fi
+}
+
+function jsonlint_precheck
+{
+  if ! verify_command jsonlint "${JSONLINT}"; then
+    add_vote_table_v2 0 jsonlint "" "jsonlint was not available."
+    delete_test jsonlint
+    return 0
+  fi
+}
+
+function jsonlint_exec
+{
+  declare i
+  declare repostatus=$1
+
+  echo "Running jsonlint against identified json files."
+  pushd "${BASEDIR}" >/dev/null || return 1
+
+  for i in "${CHANGED_FILES[@]}"; do
+    if [[ ${i} =~ \.json$ && -f ${i} ]]; then
+      "${JSONLINT}" --quiet --compact "${i}"  2>&1 \
+        | "${SED}" -e 's# line ##g' \
+                   -e 's#, col #:#g' \
+                   -e 's#, found: #:#g' \
+      >> "${PATCH_DIR}/${repostatus}-jsonlint-result.txt" 2>&1
+    fi
+  done
+
+  popd >/dev/null || return 1
+  return 0
+}
+
+function jsonlint_preapply
+{
+  declare i
+
+  if ! verify_needed_test jsonlint; then
+    return 0
+  fi
+
+  big_console_header "jsonlint plugin: ${PATCH_BRANCH}"
+
+  start_clock
+
+  jsonlint_exec branch
+
+  JSONLINT_TIMER=$(stop_clock)
+  return 0
+}
+
+## @description  Wrapper to call column_calcdiffs
+## @audience     private
+## @stability    evolving
+## @replaceable  no
+## @param        branchlog
+## @param        patchlog
+## @return       differences
+function jsonlint_calcdiffs
+{
+  column_calcdiffs "$@"
+}
+
+function jsonlint_postapply
+{
+  if ! verify_needed_test jsonlint; then
+    return 0
+  fi
+
+  big_console_header "jsonlint plugin: ${BUILDMODE}"
+
+  start_clock
+
+  # add our previous elapsed to our new timer
+  # by setting the clock back
+  offset_clock "${JSONLINT_TIMER}"
+
+  jsonlint_exec patch
+
+  root_postlog_compare \
+    jsonlint \
+    "${PATCH_DIR}/branch-jsonlint-result.txt" \
+    "${PATCH_DIR}/patch-jsonlint-result.txt"
+
+
+  # shellcheck disable=SC2016
+  JSONLINT_VERSION=$("${JSONLINT}" --version | "${AWK}" '{print $NF}')
+  add_version_data jsonlint "${JSONLINT_VERSION}"
+}
+
+function jsonlint_postcompile
+{
+  declare repostatus=$1
+
+  if [[ "${repostatus}" = branch ]]; then
+    jsonlint_preapply
+  else
+    jsonlint_postapply
+  fi
+}
diff --git a/precommit/src/main/shell/test-patch-docker/Dockerfile b/precommit/src/main/shell/test-patch-docker/Dockerfile
index 159b894c..3dbf1013 100644
--- a/precommit/src/main/shell/test-patch-docker/Dockerfile
+++ b/precommit/src/main/shell/test-patch-docker/Dockerfile
@@ -383,6 +383,7 @@ ENV BUNDLE_PATH /var/tmp/.bundler-gems
 ###
 ARG JSHINT_VERSION=2.13.4
 ARG MARKDOWNLINTCLI_VERSION=0.31.1
+ARG JSONLINT_VERSION=1.6.0
 # hadolint ignore=DL3008
 RUN curl -sSL https://deb.nodesource.com/setup_14.x | bash - \
     && apt-get -q install --no-install-recommends -y nodejs \
@@ -390,6 +391,7 @@ RUN curl -sSL https://deb.nodesource.com/setup_14.x | bash - \
     && rm -rf /var/lib/apt/lists/* \
     && npm install -g \
         jshint@$JSHINT_VERSION \
+        jsonlint@$JSONLINT_VERSION \
         markdownlint-cli@0$MARKDOWNLINTCLI_VERSION \
     && rm -rf /root/.npm