From f9799d3cd48a033ee3cbb4a8cbf560bb2f887686 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 9 Oct 2020 14:24:03 +0800 Subject: [PATCH 1/2] Ensure that eslint is called relative to the moodleroot ESLint searches for plugins relative to the CWD, and is unable to find plugins when called from outside of the moodleroot, which the plugin supports. --- mustache_lint/js_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mustache_lint/js_helper.php b/mustache_lint/js_helper.php index 9ded6e14..64558f4a 100644 --- a/mustache_lint/js_helper.php +++ b/mustache_lint/js_helper.php @@ -64,7 +64,7 @@ public function run_eslint() { ]; $cmd = "$eslint --stdin --no-eslintrc --config {$this->moodleroot}/.eslintrc --format=json"; - $proc = proc_open($cmd, $pipesspec, $pipes); + $proc = proc_open($cmd, $pipesspec, $pipes, $this->moodleroot); // Send the JS to stdin. fwrite($pipes[0], $this->js); fclose($pipes[0]); From de3541d361a50fc4b22e2ddab262c3a97c17f594 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Tue, 13 Oct 2020 00:26:17 +0200 Subject: [PATCH 2/2] Add a new test to verify that eslint is always run ok No matter the CWD from where the check is invoked --- tests/1-mustache_lint.bats | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/1-mustache_lint.bats b/tests/1-mustache_lint.bats index d6ade39a..781227bf 100755 --- a/tests/1-mustache_lint.bats +++ b/tests/1-mustache_lint.bats @@ -179,3 +179,43 @@ setup () { assert_output --partial "lib/templates/js_test.mustache - WARNING: ESLint warning [camelcase]: Identifier 'my_message' is not in camel case" assert_output --partial "lib/templates/js_test.mustache - WARNING: ESLint warning [no-alert]: Unexpected alert. ( alert(my_message); )" } + +@test "mustache_lint: Test eslint runs ok when invoked from any directory" { + + # We need to use recent version here, the default 3.1.3 used for tests (that already had eslint) + # did not expose the problem (and it ran ok from any CWD directory). + # TODO: Some day, kill all old-version tests by moving them to 39_STABLE or later. + create_git_branch MOODLE_39_STABLE v3.9.2 + + # Calculate moodleroot and localciroot. + localciroot=$PWD + moodleroot=${LOCAL_CI_TESTS_GITDIR} + + # Install npm depends so we have eslint (sourced). + source ${localciroot}/prepare_npm_stuff/prepare_npm_stuff.sh + + # Run normally (from moodleroot). + cd ${moodleroot} + ci_run_php mustache_lint/mustache_lint.php --filename="${moodleroot}/lib/templates/inplace_editable.mustache" \ + --basename="${moodleroot}" --validator="${localciroot}/node_modules/vnu-jar/build/dist/vnu.jar" + assert_success + refute_output --partial "INFO: ESLint did not run" + refute_output --partial "was not found when loaded as a Node module" + + # Run also from another dir within moodleroot. + cd ${moodleroot}/mod/forum + ci_run_php mustache_lint/mustache_lint.php --filename="${moodleroot}/lib/templates/inplace_editable.mustache" \ + --basename="${moodleroot}" --validator="${localciroot}/node_modules/vnu-jar/build/dist/vnu.jar" + assert_success + refute_output --partial "INFO: ESLint did not run" + refute_output --partial "was not found when loaded as a Node module" + + # Let's switch to any other directory (out from moodleroot). + cd ${moodleroot}/.. + ci_run_php mustache_lint/mustache_lint.php --filename="${moodleroot}/lib/templates/inplace_editable.mustache" \ + --basename="${moodleroot}" --validator="${localciroot}/node_modules/vnu-jar/build/dist/vnu.jar" + assert_success + refute_output --partial "INFO: ESLint did not run" + refute_output --partial "was not found when loaded as a Node module" + refute_output --partial "${LOCAL_CI_TESTS_CACHEDIR}" +}