diff --git a/CHANGELOG.md b/CHANGELOG.md index 73754e9..82cd447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt ## [Unreleased] ### Added - The existing `moodle.PHPUnit.TestCaseCovers` sniff now detects multiple uses of the `@coversDefaultClass` annotation. Only one is allowed by class. +- The existing `moodle.Files.BoilerplateComment` sniff now performs more checks (spacing, placement, blank lines, ...) and is able to fix many of them. ### Changed - Made codes for `moodle.Commenting.MissingDocblock` more specific to the scenario (Fixes #154). diff --git a/moodle/Tests/FilesBoilerPlateCommentTest.php b/moodle/Tests/FilesBoilerPlateCommentTest.php index 508d0b9..7405124 100644 --- a/moodle/Tests/FilesBoilerPlateCommentTest.php +++ b/moodle/Tests/FilesBoilerPlateCommentTest.php @@ -174,7 +174,7 @@ public function testMoodleFilesBoilerplateCommentWrongPlace() { } /** - * Assert that boilerplate is followed by a single newline. + * Assert that boilerplate is followed by a single newline (detect and remove excessive) */ public function testMoodleFilesBoilerplateCommentTrailingWhitespace() { $this->setStandard('moodle'); @@ -188,4 +188,20 @@ public function testMoodleFilesBoilerplateCommentTrailingWhitespace() { $this->verifyCsResults(); } + + /** + * Assert that boilerplate is followed by a single newline (detect and fix missing) + */ + public function testMoodleFilesBoilerplateCommentTrailingWhitespaceMissing() { + $this->setStandard('moodle'); + $this->setSniff('moodle.Files.BoilerplateComment'); + $this->setFixture(__DIR__ . '/fixtures/files/boilerplatecomment/trailing_whitespace_missing.php'); + + $this->setErrors([ + 16 => 'SingleTrailingNewLine', + ]); + $this->setWarnings([]); + + $this->verifyCsResults(); + } } diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/blank.php.fixed b/moodle/Tests/fixtures/files/boilerplatecomment/blank.php.fixed new file mode 100644 index 0000000..925b3cc --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/blank.php.fixed @@ -0,0 +1,17 @@ +. + +class someclass { } diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/short.php.fixed b/moodle/Tests/fixtures/files/boilerplatecomment/short.php.fixed new file mode 100644 index 0000000..a03b015 --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/short.php.fixed @@ -0,0 +1,15 @@ +. diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/short_empty.php.fixed b/moodle/Tests/fixtures/files/boilerplatecomment/short_empty.php.fixed new file mode 100644 index 0000000..5abeeab --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/short_empty.php.fixed @@ -0,0 +1,15 @@ +. diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/short_not_eof.php.fixed b/moodle/Tests/fixtures/files/boilerplatecomment/short_not_eof.php.fixed new file mode 100644 index 0000000..93e0b35 --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/short_not_eof.php.fixed @@ -0,0 +1,18 @@ +. + +class some_class { +} diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace.php.fixed b/moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace.php.fixed new file mode 100644 index 0000000..a7b697d --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace.php.fixed @@ -0,0 +1,16 @@ +. + diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace_missing.php b/moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace_missing.php new file mode 100644 index 0000000..610f486 --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace_missing.php @@ -0,0 +1,18 @@ +. + // It's not important that these lines are wrongly indented, Here + // we are only confirming that the Boilerplate Sniff fixed respects it. + class someclass { } diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace_missing.php.fixed b/moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace_missing.php.fixed new file mode 100644 index 0000000..220779f --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace_missing.php.fixed @@ -0,0 +1,19 @@ +. + + // It's not important that these lines are wrongly indented, Here + // we are only confirming that the Boilerplate Sniff fixed respects it. + class someclass { } diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/wrong_place.php b/moodle/Tests/fixtures/files/boilerplatecomment/wrong_place.php index b35919f..ad4a777 100644 --- a/moodle/Tests/fixtures/files/boilerplatecomment/wrong_place.php +++ b/moodle/Tests/fixtures/files/boilerplatecomment/wrong_place.php @@ -17,4 +17,4 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -class someclass { } \ No newline at end of file +class someclass { } diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/wrong_place.php.fixed b/moodle/Tests/fixtures/files/boilerplatecomment/wrong_place.php.fixed new file mode 100644 index 0000000..9cbbe97 --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/wrong_place.php.fixed @@ -0,0 +1,19 @@ +. + +use core\context\system; + +class someclass { } diff --git a/moodle/Tests/fixtures/files/boilerplatecomment/wrongline.php.fixed b/moodle/Tests/fixtures/files/boilerplatecomment/wrongline.php.fixed new file mode 100644 index 0000000..47da489 --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/wrongline.php.fixed @@ -0,0 +1,17 @@ +. + +class someclass { }