From ba88826dd58b61c456b18b6e230a926b6bcb556a Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Fri, 14 Jun 2024 11:27:15 +0200 Subject: [PATCH] Add a few .fixed files for existing tests and complete coverage --- CHANGELOG.md | 1 + moodle/Tests/FilesBoilerPlateCommentTest.php | 18 +++++++++++++++++- .../files/boilerplatecomment/blank.php.fixed | 17 +++++++++++++++++ .../files/boilerplatecomment/short.php.fixed | 15 +++++++++++++++ .../boilerplatecomment/short_empty.php.fixed | 15 +++++++++++++++ .../short_not_eof.php.fixed | 18 ++++++++++++++++++ .../trailing_whitespace.php.fixed | 16 ++++++++++++++++ .../trailing_whitespace_missing.php | 18 ++++++++++++++++++ .../trailing_whitespace_missing.php.fixed | 19 +++++++++++++++++++ .../files/boilerplatecomment/wrong_place.php | 2 +- .../boilerplatecomment/wrong_place.php.fixed | 19 +++++++++++++++++++ .../boilerplatecomment/wrongline.php.fixed | 17 +++++++++++++++++ 12 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 moodle/Tests/fixtures/files/boilerplatecomment/blank.php.fixed create mode 100644 moodle/Tests/fixtures/files/boilerplatecomment/short.php.fixed create mode 100644 moodle/Tests/fixtures/files/boilerplatecomment/short_empty.php.fixed create mode 100644 moodle/Tests/fixtures/files/boilerplatecomment/short_not_eof.php.fixed create mode 100644 moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace.php.fixed create mode 100644 moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace_missing.php create mode 100644 moodle/Tests/fixtures/files/boilerplatecomment/trailing_whitespace_missing.php.fixed create mode 100644 moodle/Tests/fixtures/files/boilerplatecomment/wrong_place.php.fixed create mode 100644 moodle/Tests/fixtures/files/boilerplatecomment/wrongline.php.fixed diff --git a/CHANGELOG.md b/CHANGELOG.md index 73754e99..82cd4474 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 508d0b96..74051240 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 00000000..925b3cc6 --- /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 00000000..a03b0152 --- /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 00000000..5abeeabc --- /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 00000000..93e0b358 --- /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 00000000..a7b697dd --- /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 00000000..610f4868 --- /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 00000000..220779f6 --- /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 b35919fd..ad4a7774 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 00000000..9cbbe970 --- /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 00000000..47da4892 --- /dev/null +++ b/moodle/Tests/fixtures/files/boilerplatecomment/wrongline.php.fixed @@ -0,0 +1,17 @@ +. + +class someclass { }