From 6b5a1145d4ed4f7a7bb17d85dfcf2444b4a63449 Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Thu, 7 Mar 2024 15:20:33 +0000 Subject: [PATCH] Limit stylelint tasks to plugin directory --- docs/CHANGELOG.md | 3 +++ src/Command/GruntCommand.php | 9 +++++---- tests/Command/GruntCommandTest.php | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0986e359..9c96b566 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -9,6 +9,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). The format of this change log follows the advice given at [Keep a CHANGELOG](http://keepachangelog.com). ## [Unreleased] +### Fixed +- Fixed a problem with the `grunt` command running the `stylelint` tasks against the whole Moodle directory (including both core and other optional plugins installed). Now only the plugin being checked is effectively analysed. + ## [4.5.0] - 2024-06-03 ### Changed - Updated project dependencies to current [moodle-cs v3.4.7](https://github.com/moodlehq/moodle-cs) and [moodle-local_ci v1.0.30](https://github.com/moodlehq/moodle-local_ci) releases. diff --git a/src/Command/GruntCommand.php b/src/Command/GruntCommand.php index f2415aef..8999389e 100644 --- a/src/Command/GruntCommand.php +++ b/src/Command/GruntCommand.php @@ -169,7 +169,8 @@ public function toGruntTask(string $task): ?GruntTaskModel if (is_file($this->plugin->directory . '/Gruntfile.js')) { $workingDirectory = $this->plugin->directory; } - $defaultTask = new GruntTaskModel($task, $workingDirectory); + $defaultTask = new GruntTaskModel($task, $workingDirectory); + $defaultTaskPluginDir = new GruntTaskModel($task, $this->plugin->directory); switch ($task) { case 'amd': @@ -194,11 +195,11 @@ public function toGruntTask(string $task): ?GruntTaskModel return new GruntTaskModel($task, $this->moodle->directory); case 'stylelint:css': - return $this->plugin->hasFilesWithName('*.css') ? $defaultTask : null; + return $this->plugin->hasFilesWithName('*.css') ? $defaultTaskPluginDir : null; case 'stylelint:less': - return $this->plugin->hasFilesWithName('*.less') ? $defaultTask : null; + return $this->plugin->hasFilesWithName('*.less') ? $defaultTaskPluginDir : null; case 'stylelint:scss': - return $this->plugin->hasFilesWithName('*.scss') ? $defaultTask : null; + return $this->plugin->hasFilesWithName('*.scss') ? $defaultTaskPluginDir : null; default: return $defaultTask; } diff --git a/tests/Command/GruntCommandTest.php b/tests/Command/GruntCommandTest.php index 669524ed..f7c3a592 100644 --- a/tests/Command/GruntCommandTest.php +++ b/tests/Command/GruntCommandTest.php @@ -140,7 +140,7 @@ public function testToGruntTaskWithStyles() $this->assertInstanceOf(GruntTaskModel::class, $task); $this->assertSame('stylelint:css', $task->taskName); $this->assertSame('', $task->buildDirectory); - $this->assertSame($this->moodleDir, $task->workingDirectory); + $this->assertSame($this->pluginDir, $task->workingDirectory); $this->fs->remove($this->pluginDir . '/styles.css');