Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use general stylelint task in grunt command #320

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions src/Command/GruntCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function configure(): void
{
parent::configure();

$tasks = ['amd', 'yui', 'gherkinlint', 'stylelint:css', 'stylelint:less', 'stylelint:scss'];
$tasks = ['amd', 'yui', 'gherkinlint', 'stylelint'];

$this->setName('grunt')
->setDescription('Run Grunt task on a plugin')
Expand Down Expand Up @@ -194,10 +194,11 @@ 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:less':
return $this->plugin->hasFilesWithName('*.less') ? $defaultTaskPluginDir : null;
case 'stylelint:scss':
return $this->plugin->hasFilesWithName('*.scss') ? $defaultTaskPluginDir : null;
default:
Expand Down
33 changes: 31 additions & 2 deletions tests/Command/GruntCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -144,8 +150,31 @@ public function testToGruntTaskWithStyles()

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

$this->assertNull($command->toGruntTask('stylelint'));
$this->assertNull($command->toGruntTask('stylelint:css'));
$this->assertNull($command->toGruntTask('stylelint:less'));
}

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'));
}

Expand Down
Loading