Skip to content

Commit

Permalink
Fixes #176. Match blank boilerplate lines correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
micaherne committed Jul 4, 2024
1 parent a0bfb12 commit 2b829d7
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 @@ -280,6 +280,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 @@ -212,4 +212,26 @@ public function testMoodleFilesBoilerplateCommentTrailingWhitespaceMissing() {

$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 2b829d7

Please sign in to comment.