General plugins (Local): Code-checker

local_codechecker
Maintained by Tim at Lone Pine Koala Sanctuary Tim Hunt, One poor developer... Eloy Lafuente (stronk7)
A tool for developers that helps them follow Moodle's coding style.
329 sites
538 downloads
17 fans
Moodle 2.7, 2.8, 2.9, 3.0, 3.1

The code checker tool is based on the PHP CodeSniffer library. It implements a set of 'sniffs' that check for many parts of the Moodle coding style. They also present a nice web interface for viewing the results.

Screenshots

Screenshot #0
Screenshot #1

Contributors

Tim at Lone Pine Koala Sanctuary
Tim Hunt (Lead maintainer)
One poor developer...
Eloy Lafuente (stronk7)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Tim at Lone Pine Koala Sanctuary
    Mon, 3 Aug 2015, 7:50 PM
    A lot of old code does not match all of the coding style. That is sad, but not easy to fix (fixing it all would create a lot of noise in git).

    The policy is that you should fix probles on the lines you need to change, then ignore the rest. When you submit a patch to Moodle core, it just checks the problems on the lines in the patch. E.g. https://tracker.moodle.org/browse/MDL-27177?focusedCommentId=364873&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-364873
  • Picture of Urs Hunkler
    Tue, 4 Aug 2015, 7:54 PM
    Thank you for your answer Tim. So the code-checker conforms to the actual Moodle coding style and I can rely on it's output.

    Many errors are comment errors like »Inline comments must end in full-stops, exclamation marks, or question marks«. Is it really important for a good coding style that inline comments must end in a predefined way? Many of these coding errors or warnings could be avoided when this rule may be removed. Especially because I would never add any mark after a short comment and find it strange to be forced to do so to avoid the coding errors. And looking at Moodle core code it's not only me.

    What do you think?
  • Picture of Urs Hunkler
    Tue, 4 Aug 2015, 7:58 PM
    And I wonder about the »#398: ····protected·$unique_performance_info_token;
    Member variable "unique_performance_info_token" must not contain underscores.« error. I always thought compound variable names must be separated by underscores. How should that variable name be written conforming to the coding style?
  • Tim at Lone Pine Koala Sanctuary
    Tue, 4 Aug 2015, 9:14 PM
    $uniqueperformanceinfotoken - as it says on https://docs.moodle.org/dev/Coding_style#Variables

    The comment style is really not important. I don't know why Eloy implemented it. (Eloy says he implemented it because I said he should, but I don't remember that.)

    Anyway, the point of coding style is readability, so that when you are trying to understand some code, there are as few irrelevant distractions as possible.
  • Picture of Urs Hunkler
    Tue, 4 Aug 2015, 10:40 PM
    Eloy, in the case you read the comments - please consider to remove the »Inline comments must end in full-stops, exclamation marks, or question marks« errors.
  • Picture of Urs Hunkler
    Tue, 4 Aug 2015, 10:50 PM
    Yep, »the point of coding style is readability«. But I have difficulties to read $uniqueperformanceinfotoken - $unique_performance_info_token is much easier to read. But with the info from the coding style page you had linked to »keep them short as possible« the varianble may have been named something like $perfinfotoken.

    I don't complain - it's just a complex field and I am just starting dig deeper into Moodle coding style.
  • One poor developer...
    Mon, 10 Aug 2015, 5:12 PM
    Hi Urs,

    sorry for the delay, I've been out last weeks and has been long to catch up with everything on return.

    Mimicking (and joking) Tim: The comment style is really not important. I don't know why Tim proposed it. It was proposed, voted and agreed, so I don't think we are going to vote it again soon. I just implemented it.

    In any case, it's only a warning. If anything you should be looking for errors only, warnings are recommendations, basically.

    Ciao smile
  • One poor developer...
    Mon, 10 Aug 2015, 5:25 PM
    Hi Gareth,

    somehow I missed your comment above about some operators not being detected properly when looking for whitespace around them. I've create CONTRIB-5862 about that, for reference.

    Ciao smile
  • Picture of Urs Hunkler
    Mon, 10 Aug 2015, 11:41 PM
    Thanks for your feedback Eloy. You recommend to »ignore« warnings - I can turn off PHP Code Sniffer warnings in the IDE to avoid the not relevant PHP Code Sniffer feedback. Great and thanks.
  • One poor developer...
    Tue, 11 Aug 2015, 12:27 AM
    LOL, Urs.

    I don't recommend to ignore warnings. In fact, I do recommend to check both errors and warnings. More yet, I do check both always.

    I only say that, while errors are clear violations, warnings can be understood as recommendations. If you decide to follow or ignore them it's up to you. Personally I follow them, it's not so hard, really. But your choice, anyway.

    Ciao smile
  • Picture of Nguyễn Tuấn Anh
    Tue, 1 Dec 2015, 10:30 PM
    I don't understand, used plugins like?
  • Picture of Ruslan Kabalin
    Tue, 1 Mar 2016, 10:50 PM
    "More documentation" link above should probably point to https://docs.moodle.org/dev/CodeSniffer rather than style documentation. Not sure though.
  • Picture of Derek Henderson
    Wed, 5 Oct 2016, 11:16 PM
    Would it be possible to include the latest version of the PHPCompatibility sniff and also add in the ability to pass in versions, so the code can be tested against different versions?
  • One poor developer...
    Mon, 21 Nov 2016, 5:19 AM
    Hi Derek, just for reference, there is https://tracker.moodle.org/browse/CONTRIB-5158 about that. It's old, but any movement towards that feature should happen there.
1 2 3
Please login to post comments