## General plugins (Local): Code-checker

local_codechecker
Maintained by Tim Hunt, Eloy Lafuente (stronk7)
A tool for developers that helps them follow Moodle's coding style.
268 sites
17 fans

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.

### Contributors

Tim Hunt (Lead maintainer)
Eloy Lafuente (stronk7)
Please login to view contributors details and/or to contact them

### Awards

• 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
• 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?
• 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? • 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.
• 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.
• 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.
• 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
• 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
• 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.
• 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
• Tue, 1 Dec 2015, 10:30 PM
I don't understand, used plugins like?
• 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.
• 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?
• 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.