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

Fixes #176. Match blank boilerplate lines correctly. #177

Merged
merged 1 commit into from
Jul 4, 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
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/>.