Skip to content

Commit e6d2726

Browse files
committedJul 4, 2024·
Fixes #176. Match blank boilerplate lines correctly.
1 parent f7668d9 commit e6d2726

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed
 

‎moodle/Sniffs/Files/BoilerplateCommentSniff.php

+5
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ private function completeBoilerplate(File $file, $stackptr, int $lineindex): voi
288288
*/
289289
private function regexForLine(string $line): string
290290
{
291+
// We need to match the blank lines in their entirety.
292+
if ($line === '//') {
293+
return '/^\/\/$/';
294+
}
295+
291296
return str_replace(
292297
['Moodle', 'https\\:'],
293298
['.*', 'https?\\:'],

‎moodle/Tests/FilesBoilerPlateCommentTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,26 @@ public function testMoodleFilesBoilerplateCommentWithPhpcsTag() {
240240

241241
$this->verifyCsResults();
242242
}
243+
244+
public function testMoodleFilesBoilerplateCommentMissingLines() {
245+
$this->setStandard('moodle');
246+
$this->setSniff('moodle.Files.BoilerplateComment');
247+
$this->setFixture(__DIR__ . '/fixtures/files/boilerplatecomment/missing_lines.php');
248+
249+
$this->setErrors([
250+
3 => 'moodle.Files.BoilerplateComment.WrongLine',
251+
4 => 'moodle.Files.BoilerplateComment.WrongLine',
252+
5 => 'moodle.Files.BoilerplateComment.WrongLine',
253+
6 => 'moodle.Files.BoilerplateComment.WrongLine',
254+
7 => 'moodle.Files.BoilerplateComment.WrongLine',
255+
8 => 'moodle.Files.BoilerplateComment.WrongLine',
256+
9 => 'moodle.Files.BoilerplateComment.WrongLine',
257+
10 => 'moodle.Files.BoilerplateComment.WrongLine',
258+
11 => 'moodle.Files.BoilerplateComment.WrongLine',
259+
12 => ['moodle.Files.BoilerplateComment.WrongLine', 'moodle.Files.BoilerplateComment.CommentEndedTooSoon'],
260+
]);
261+
$this->setWarnings([]);
262+
263+
$this->verifyCsResults();
264+
}
243265
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
// This file is part of Moodle - https://moodle.org/
3+
// Moodle is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
// Moodle is distributed in the hope that it will be useful,
8+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
// GNU General Public License for more details.
11+
// You should have received a copy of the GNU General Public License
12+
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
// This file is part of Moodle - https://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

0 commit comments

Comments
 (0)
Please sign in to comment.