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

moodle-extra doesn't catch 'Functions must not contain multiple empty lines in a row' #87

Open
individual-it opened this issue Dec 27, 2023 · 4 comments

Comments

@individual-it
Copy link

my .phpcs.xml looks like this

<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="MoodleCore">
  <rule ref="moodle-extra"/>
</ruleset>

and in db/install.php I have this code:

        } else {
            $issuerdata->image = $ocislogourl;
        }


        $issuer = core\oauth2\api::create_issuer($issuerdata);
        $result = $issuer->is_valid();
        if (!$result) {
            return $result;
        }

The multi empty line issue is not reported by phpcs

When I change the rule to <rule ref="moodle"/> it works correctly.

@andrewnicols
Copy link
Contributor

The Moodle-extra ruleset needs to also be included with the Moodle ruleset as per the docs. Can you check with that config?

@individual-it
Copy link
Author

Same issue, if I add both moodle and moodle-extra
I think moodle is already included in moodle-extra, see https://github.com/moodlehq/moodle-cs/blob/main/moodle-extra/ruleset.xml#L10

@individual-it
Copy link
Author

btw. the local/codechecker plugin detects the issue correctly

@stronk7
Copy link
Member

stronk7 commented Feb 14, 2024

This is a curious case, I've tried here with this simple php script:

<?php // phpcs:disable moodle

function something() {
    echo "Hello World";
    echo "Hello World";


    echo "Hello World";
}

And this is what I get:

With the "moodle" standard:

$ vendor/bin/phpcs -s --standard=moodle pp.php && echo "ok!" || echo "problem!"

FILE: /Users/stronk7/git_moodle/moodle/pp.php
----------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------------------------
 6 | ERROR | [x] Functions must not contain multiple empty lines in a row; found 2 empty lines
   |       |     (Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines)
----------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------------

Time: 245ms; Memory: 16MB

problem!

With the "moodle-extra" standard:

$ vendor/bin/phpcs -s --standard=moodle-extra pp.php && echo "ok!" || echo "problem!"
ok!

(I've tried the above with the testing file being within Moodle, within moodle-cs and in an empty directory, to avoid any [.]phpcs.xml[.dist] interference. Same result always)

Really curious, I've over-looked the moodle-extra ruleset and have not found anything disabling that SuperfluousWhitespace sniff. Sure that there is a reason, but we have to find it.

Ciao :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants