From a6d35fdd2abd63d23c7a9d093645f760691539a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 26 Jan 2024 00:56:35 +0100 Subject: [PATCH] ci: Check snippets in coding style To avoid having the coding style get out of sync with the actual coding style in the future, run eslint on the individual snippets when either the guide or the linter config change. Part-of: --- .gitlab-ci.yml | 15 +++++++++++ .gitlab-ci/eslint-coding-style.sh | 43 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100755 .gitlab-ci/eslint-coding-style.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8dadcf6aa..8d881ba7f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -149,6 +149,21 @@ eslint: junit: ${LINT_LOG} when: always +eslint-doc: + extends: + - .fdo.distribution-image@fedora + - .gnome-shell.fedora + stage: review + script: + - export NODE_PATH=$(npm root -g) + - ./.gitlab-ci/eslint-coding-style.sh + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + changes: + - HACKING.md + - .eslintrc.yml + - lint/* + potfile_c_check: extends: - .fdo.distribution-image@fedora diff --git a/.gitlab-ci/eslint-coding-style.sh b/.gitlab-ci/eslint-coding-style.sh new file mode 100755 index 000000000..783075bd8 --- /dev/null +++ b/.gitlab-ci/eslint-coding-style.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +SRCDIR=$(realpath $(dirname $0)/..) +OUTDIR=$(mktemp --directory --tmpdir=$SRCDIR) +trap "rm -rf $OUTDIR" EXIT + +# Turn ```javascript``` code snippets in the +# style guide into .js files in $OUTDIR +awk --assign dir=$OUTDIR -- ' + BEGIN { + do_print = 0; + cur = 0; + } + + # end of code snippet + /```$/ { + do_print = 0; + cur++; + } + + do_print { + # remove one level of indent + sub(" ","") + + # the following are class snippets, turn them + # into functions to not confuse eslint + sub("moveActor","function moveActor") + sub("desaturateActor","function desaturateActor") + + # finally, append to the currently generated .js file + print >> dir "/" cur ".js"; + } + + # start of code snippet + /```javascript$/ { + do_print = 1; + } +' HACKING.md + +eslint \ + --rule 'no-undef: off' \ + --rule 'no-unused-vars: off' \ + --rule 'no-invalid-this: off' $OUTDIR/*.js