From f09b894a34a6c034685cf51da9a9e0a96a71bcb7 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Tue, 10 Sep 2024 17:06:03 +0100 Subject: [PATCH] Use general stylelint task in grunt command. So that core grunt task will decide whether css or scss linter needs to be run (or both). Fixes #314 --- docs/CHANGELOG.md | 7 +++++++ src/Command/GruntCommand.php | 5 ++++- tests/Command/GruntCommandTest.php | 32 +++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 7d5fc8fe..0e65f7df 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -9,6 +9,13 @@ This project adheres to [Semantic Versioning](https://semver.org/). The format of this change log follows the advice given at [Keep a CHANGELOG](https://keepachangelog.com). ## [Unreleased] +### Fixed +- Fixed stylelinting error in non-theme plugins containing scss. + +### Removed +- Stylelint less component task (`grunt stylelint:less`) has been deprecated in + Moodle 3.7. + ## [4.5.4] - 2024-08-23 ### Changed - Fixed nvm loading issue caused by upstream regression. diff --git a/src/Command/GruntCommand.php b/src/Command/GruntCommand.php index 74f9a5a8..2d19079a 100644 --- a/src/Command/GruntCommand.php +++ b/src/Command/GruntCommand.php @@ -33,7 +33,7 @@ protected function configure(): void { parent::configure(); - $tasks = ['amd', 'yui', 'gherkinlint', 'stylelint:css', 'stylelint:scss']; + $tasks = ['amd', 'yui', 'gherkinlint', 'stylelint']; $this->setName('grunt') ->setDescription('Run Grunt task on a plugin') @@ -194,6 +194,9 @@ public function toGruntTask(string $task): ?GruntTaskModel } return new GruntTaskModel($task, $this->moodle->directory); + case 'stylelint': + // Let stylelint task logic to determine which type of linter to run. + return $this->plugin->hasFilesWithName('*.css') || $this->plugin->hasFilesWithName('*.scss') ? $defaultTaskPluginDir : null; case 'stylelint:css': return $this->plugin->hasFilesWithName('*.css') ? $defaultTaskPluginDir : null; case 'stylelint:scss': diff --git a/tests/Command/GruntCommandTest.php b/tests/Command/GruntCommandTest.php index 40dd79df..18b1cb83 100644 --- a/tests/Command/GruntCommandTest.php +++ b/tests/Command/GruntCommandTest.php @@ -132,10 +132,16 @@ public function testToGruntTaskWithGherkin() $this->assertNull($command->toGruntTask('gherkinlint')); } - public function testToGruntTaskWithStyles() + public function testToGruntTaskWithStylesCss() { $command = $this->newCommand(); + $task = $command->toGruntTask('stylelint'); + $this->assertInstanceOf(GruntTaskModel::class, $task); + $this->assertSame('stylelint', $task->taskName); + $this->assertSame('', $task->buildDirectory); + $this->assertSame($this->pluginDir, $task->workingDirectory); + $task = $command->toGruntTask('stylelint:css'); $this->assertInstanceOf(GruntTaskModel::class, $task); $this->assertSame('stylelint:css', $task->taskName); @@ -144,7 +150,31 @@ public function testToGruntTaskWithStyles() $this->fs->remove($this->pluginDir . '/styles.css'); + $this->assertNull($command->toGruntTask('stylelint')); $this->assertNull($command->toGruntTask('stylelint:css')); + } + + public function testToGruntTaskWithStylesScss() + { + $command = $this->newCommand(); + $this->fs->mkdir($this->pluginDir . '/scss'); + $this->fs->rename($this->pluginDir . '/styles.css', $this->pluginDir . '/scss/styles.scss'); + + $task = $command->toGruntTask('stylelint'); + $this->assertInstanceOf(GruntTaskModel::class, $task); + $this->assertSame('stylelint', $task->taskName); + $this->assertSame('', $task->buildDirectory); + $this->assertSame($this->pluginDir, $task->workingDirectory); + + $task = $command->toGruntTask('stylelint:scss'); + $this->assertInstanceOf(GruntTaskModel::class, $task); + $this->assertSame('stylelint:scss', $task->taskName); + $this->assertSame('', $task->buildDirectory); + $this->assertSame($this->pluginDir, $task->workingDirectory); + + $this->fs->remove($this->pluginDir . '/scss'); + + $this->assertNull($command->toGruntTask('stylelint')); $this->assertNull($command->toGruntTask('stylelint:scss')); }