[gnome-shell-extensions/wip/fmuellner/lint-ci: 18/18] ci: Allow gradual switch to new style



commit 47beeb1a8e9afba410dc7587cb40f7fb00f5e3a7
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Jan 28 06:48:27 2019 +0100

    ci: Allow gradual switch to new style
    
    It doesn't make too much sense to declare parts of the existing style
    "legacy", but then enforce it via CI. To allow for a gradual switch,
    generate a report with all issues that eslint considers errors in both
    configurations.
    
    https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/50

 .gitlab-ci.yml          |  2 +-
 lint/generate-report.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index af30aee..af003a1 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -9,7 +9,7 @@ eslint:
   image: registry.gitlab.gnome.org/gnome/gjs:fedora.static-analysis
   stage: source_check
   script:
-    - eslint -o $LINT_LOG -c lint/eslintrc-legacy.json --no-color . || { cat $LINT_LOG; false; }
+    - sh lint/generate-report.sh -o $LINT_LOG || { cat $LINT_LOG; false; }
   artifacts:
     paths:
       - ${LINT_LOG}
diff --git a/lint/generate-report.sh b/lint/generate-report.sh
new file mode 100644
index 0000000..1d34401
--- /dev/null
+++ b/lint/generate-report.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+SEP=`printf '\t'`
+OUTPUT=/dev/stderr
+CWD=`pwd`
+SRCDIR=`dirname $0`
+
+run_lint() {
+  eslint -f unix "$@" .
+}
+
+parse_opts() {
+  tmp=`getopt -l output: o: "$@"`
+  [ $? -ne 0 ] && exit 1
+
+  eval set -- $tmp
+  while true
+  do
+    case $1 in
+      --output|-o)
+        OUTPUT=`realpath $2`; shift 2; continue ;;
+      --)
+        shift; break ;;
+    esac
+  done
+}
+
+# delete lines that don't start with '/',
+# replace the first space with tab, sort
+process_for_join() {
+  sed -E "/\//!d; s|(\S+)\s|\1$SEP|" | sort -k 1b,1
+}
+
+# re-replace tab with space
+process_post_join() {
+  sed -E "s|$SEP| |"
+}
+
+create_report() {
+  tmp1=`mktemp --tmpdir lint-XXXX`
+  run_lint | process_for_join > $tmp1
+
+  tmp2=`mktemp --tmpdir lint-XXXX`
+  run_lint -c lint/eslintrc-legacy.json | process_for_join > $tmp2
+
+  join -t"$SEP" -o '0,1.2' $tmp1 $tmp2 | process_post_join
+  rm $tmp1 $tmp2
+}
+
+
+parse_opts "$@"
+
+cd $SRCDIR/..
+
+create_report | tee $OUTPUT | grep -q .
+rv=$(( $? == 0 ))
+
+cd $CWD
+
+[ $rv -eq 0 -a -f $OUTPUT ] && rm $OUTPUT
+
+exit $rv


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]