diff --git a/moodle/Sniffs/Files/BoilerplateCommentSniff.php b/moodle/Sniffs/Files/BoilerplateCommentSniff.php index d53c1e7..22d2754 100644 --- a/moodle/Sniffs/Files/BoilerplateCommentSniff.php +++ b/moodle/Sniffs/Files/BoilerplateCommentSniff.php @@ -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?\\:'], diff --git a/moodle/Tests/FilesBoilerPlateCommentTest.php b/moodle/Tests/FilesBoilerPlateCommentTest.php index a945a57..263a3ab 100644 --- a/moodle/Tests/FilesBoilerPlateCommentTest.php +++ b/moodle/Tests/FilesBoilerPlateCommentTest.php @@ -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(); + } } diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/missing_lines.php b/moodle/Tests/fixtures/files/boilerplatecomment/missing_lines.php new file mode 100644 index 0000000..5e80b79 --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/missing_lines.php @@ -0,0 +1,12 @@ +. diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/missing_lines.php.fixed b/moodle/Tests/fixtures/files/boilerplatecomment/missing_lines.php.fixed new file mode 100644 index 0000000..5abeeab --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/missing_lines.php.fixed @@ -0,0 +1,15 @@ +.