Skip to content

Commit f09b894

Browse files
committed
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
1 parent 360562c commit f09b894

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

docs/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ This project adheres to [Semantic Versioning](https://semver.org/).
99
The format of this change log follows the advice given at [Keep a CHANGELOG](https://keepachangelog.com).
1010

1111
## [Unreleased]
12+
### Fixed
13+
- Fixed stylelinting error in non-theme plugins containing scss.
14+
15+
### Removed
16+
- Stylelint less component task (`grunt stylelint:less`) has been deprecated in
17+
Moodle 3.7.
18+
1219
## [4.5.4] - 2024-08-23
1320
### Changed
1421
- Fixed nvm loading issue caused by upstream regression.

src/Command/GruntCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function configure(): void
3333
{
3434
parent::configure();
3535

36-
$tasks = ['amd', 'yui', 'gherkinlint', 'stylelint:css', 'stylelint:scss'];
36+
$tasks = ['amd', 'yui', 'gherkinlint', 'stylelint'];
3737

3838
$this->setName('grunt')
3939
->setDescription('Run Grunt task on a plugin')
@@ -194,6 +194,9 @@ public function toGruntTask(string $task): ?GruntTaskModel
194194
}
195195

196196
return new GruntTaskModel($task, $this->moodle->directory);
197+
case 'stylelint':
198+
// Let stylelint task logic to determine which type of linter to run.
199+
return $this->plugin->hasFilesWithName('*.css') || $this->plugin->hasFilesWithName('*.scss') ? $defaultTaskPluginDir : null;
197200
case 'stylelint:css':
198201
return $this->plugin->hasFilesWithName('*.css') ? $defaultTaskPluginDir : null;
199202
case 'stylelint:scss':

tests/Command/GruntCommandTest.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,16 @@ public function testToGruntTaskWithGherkin()
132132
$this->assertNull($command->toGruntTask('gherkinlint'));
133133
}
134134

135-
public function testToGruntTaskWithStyles()
135+
public function testToGruntTaskWithStylesCss()
136136
{
137137
$command = $this->newCommand();
138138

139+
$task = $command->toGruntTask('stylelint');
140+
$this->assertInstanceOf(GruntTaskModel::class, $task);
141+
$this->assertSame('stylelint', $task->taskName);
142+
$this->assertSame('', $task->buildDirectory);
143+
$this->assertSame($this->pluginDir, $task->workingDirectory);
144+
139145
$task = $command->toGruntTask('stylelint:css');
140146
$this->assertInstanceOf(GruntTaskModel::class, $task);
141147
$this->assertSame('stylelint:css', $task->taskName);
@@ -144,7 +150,31 @@ public function testToGruntTaskWithStyles()
144150

145151
$this->fs->remove($this->pluginDir . '/styles.css');
146152

153+
$this->assertNull($command->toGruntTask('stylelint'));
147154
$this->assertNull($command->toGruntTask('stylelint:css'));
155+
}
156+
157+
public function testToGruntTaskWithStylesScss()
158+
{
159+
$command = $this->newCommand();
160+
$this->fs->mkdir($this->pluginDir . '/scss');
161+
$this->fs->rename($this->pluginDir . '/styles.css', $this->pluginDir . '/scss/styles.scss');
162+
163+
$task = $command->toGruntTask('stylelint');
164+
$this->assertInstanceOf(GruntTaskModel::class, $task);
165+
$this->assertSame('stylelint', $task->taskName);
166+
$this->assertSame('', $task->buildDirectory);
167+
$this->assertSame($this->pluginDir, $task->workingDirectory);
168+
169+
$task = $command->toGruntTask('stylelint:scss');
170+
$this->assertInstanceOf(GruntTaskModel::class, $task);
171+
$this->assertSame('stylelint:scss', $task->taskName);
172+
$this->assertSame('', $task->buildDirectory);
173+
$this->assertSame($this->pluginDir, $task->workingDirectory);
174+
175+
$this->fs->remove($this->pluginDir . '/scss');
176+
177+
$this->assertNull($command->toGruntTask('stylelint'));
148178
$this->assertNull($command->toGruntTask('stylelint:scss'));
149179
}
150180

0 commit comments

Comments
 (0)