From 22d20cc76e670ec521c191519a2ee117dde15784 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Tue, 6 Sep 2022 03:22:18 +0100 Subject: [PATCH] ci: lint .jison files for any console.log() Converts the *.jison files into .js, then lints them using just the `no-console` rule. To keep things simple, I've just made this run only on CI. If we want to do more complex linting on `*.jison` files, it might be worth making an `eslint-plugin-jison`, so that we can directly parse jison in ESLint. --- .github/workflows/lint.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 050667a8f..e538372ad 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -37,3 +37,17 @@ jobs: - name: Run Linting run: yarn lint + - name: Check no `console.log()` in .jison files + # ESLint can't parse .jison files directly + # In the future, it might be worth making a `eslint-plugin-jison`, so + # that this will be built into the `yarn lint` command. + run: | + shopt -s globstar + mkdir -p tmp/ + for jison_file in src/**/*.jison; do + outfile="tmp/$(basename -- "$jison_file" .jison)-jison.js" + echo "Converting $jison_file to $outfile" + # default module-type (CJS) always adds a console.log() + yarn jison "$jison_file" --outfile "$outfile" --module-type "amd" + done + yarn eslint --no-eslintrc --rule no-console:error --parser "@babel/eslint-parser" "./tmp/*-jison.js"