Skip to content

Commit

Permalink
Merge pull request moodlehq#177 from micaherne/176-fix-boilerplate-up…
Browse files Browse the repository at this point in the history
…date

Fixes moodlehq#176. Match blank boilerplate lines correctly.
  • Loading branch information
stronk7 authored Jul 4, 2024
2 parents f7668d9 + e6d2726 commit 5f0d1f2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions moodle/Sniffs/Files/BoilerplateCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ private function completeBoilerplate(File $file, $stackptr, int $lineindex): voi
*/
private function regexForLine(string $line): string
{
// We need to match the blank lines in their entirety.
if ($line === '//') {
return '/^\/\/$/';
}

return str_replace(
['Moodle', 'https\\:'],
['.*', 'https?\\:'],
Expand Down
22 changes: 22 additions & 0 deletions moodle/Tests/FilesBoilerPlateCommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,26 @@ public function testMoodleFilesBoilerplateCommentWithPhpcsTag() {

$this->verifyCsResults();
}

public function testMoodleFilesBoilerplateCommentMissingLines() {
$this->setStandard('moodle');
$this->setSniff('moodle.Files.BoilerplateComment');
$this->setFixture(__DIR__ . '/fixtures/files/boilerplatecomment/missing_lines.php');

$this->setErrors([
3 => 'moodle.Files.BoilerplateComment.WrongLine',
4 => 'moodle.Files.BoilerplateComment.WrongLine',
5 => 'moodle.Files.BoilerplateComment.WrongLine',
6 => 'moodle.Files.BoilerplateComment.WrongLine',
7 => 'moodle.Files.BoilerplateComment.WrongLine',
8 => 'moodle.Files.BoilerplateComment.WrongLine',
9 => 'moodle.Files.BoilerplateComment.WrongLine',
10 => 'moodle.Files.BoilerplateComment.WrongLine',
11 => 'moodle.Files.BoilerplateComment.WrongLine',
12 => ['moodle.Files.BoilerplateComment.WrongLine', 'moodle.Files.BoilerplateComment.CommentEndedTooSoon'],
]);
$this->setWarnings([]);

$this->verifyCsResults();
}
}
12 changes: 12 additions & 0 deletions moodle/Tests/fixtures/files/boilerplatecomment/missing_lines.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
// This file is part of Moodle - https://moodle.org/
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

0 comments on commit 5f0d1f2

Please sign in to comment.