Skip to content

Commit 8d1c7df

Browse files
authored
Merge pull request #320 from kabalin/stylelint
Use general stylelint task in grunt command
2 parents 367c973 + f09b894 commit 8d1c7df

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
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 & 3 deletions
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:less', 'stylelint:scss'];
36+
$tasks = ['amd', 'yui', 'gherkinlint', 'stylelint'];
3737

3838
$this->setName('grunt')
3939
->setDescription('Run Grunt task on a plugin')
@@ -194,10 +194,11 @@ 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;
199-
case 'stylelint:less':
200-
return $this->plugin->hasFilesWithName('*.less') ? $defaultTaskPluginDir : null;
201202
case 'stylelint:scss':
202203
return $this->plugin->hasFilesWithName('*.scss') ? $defaultTaskPluginDir : null;
203204
default:

tests/Command/GruntCommandTest.php

Lines changed: 31 additions & 2 deletions
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,8 +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'));
148-
$this->assertNull($command->toGruntTask('stylelint:less'));
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'));
149178
$this->assertNull($command->toGruntTask('stylelint:scss'));
150179
}
151180

0 commit comments

Comments
 (0)