Code-checker
Maintained by
Victor Deniz, Sara Arjona, Eloy Lafuente (stronk7), Tim Hunt
A tool for developers that helps them follow Moodle's coding style.
Comments
Comments are no longer open for new posts. Existing comments remain available to read.
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
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
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
I don't complain - it's just a complex field and I am just starting dig deeper into Moodle coding style.
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.
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?
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?
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
Does the code checker need an updated to follow the actual Moodle coding style or is Moodle core code not validated against the Moodle coding style?
I would like to be able to reliable use the code checker to validate coding style. The code checker is a great tool, especially when it is integrated into the IDE and errors/warnings are shown while working on the code. But when it throws may errors for core code it becomes confusing and irritating.
Any idea how the issue can be solved?
An example:
lib/outputrenderers.php - 209 error(s) and 239 warning(s)
Total: 209 error(s) and 239 warning(s)
lib/outputrenderers.php
#183: ········//·Remove·_renderable·suffixes
Inline comments must end in full-stops, exclamation marks, or question marks
#311: ········//·Remove·_renderable·suffixes
Inline comments must end in full-stops, exclamation marks, or question marks
#335: ········//·pass·to·core·renderer·if·method·not·found·here
Inline comments must start with a capital letter, digit or 3-dots sequence
Inline comments must end in full-stops, exclamation marks, or question marks
#393: ····protected·$unique_end_html_token;
a
#398: ····protected·$unique_performance_info_token;
Member variable "unique_performance_info_token" must not contain underscores.
#403: ····protected·$unique_main_content_token;
Member variable "unique_main_content_token" must not contain underscores.
#437: ············//·legacy·xhtml·1.0
Inline comments must start with a capital letter, digit or 3-dots sequence
Inline comments must end in full-stops, exclamation marks, or question marks
#439: ············return·(''·.·"\n");
Line exceeds 132 characters; contains 140 characters
#479: ········//·This·is·only·set·by·the·{@link·redirect()}·method
Inline comments must end in full-stops, exclamation marks, or question marks
#483: ········//·already·meta·refreshing
Inline comments must end in full-stops, exclamation marks, or question marks
#484: ········if·($this->metarefreshtag==''·&&·$this->page->periodicrefreshdelay!==null)·{
Expected 1 space before "=="; 0 found
Expected 1 space after "=="; 0 found
Expected 1 space before "!=="; 0 found
Expected 1 space after "!=="; 0 found
#485: ············$output·.=·'page->periodicrefreshdelay.';url='.$this->page->url->out().'"·/>';
Line exceeds 132 characters; contains 135 characters
However, print_r is generally only used in debug code. And debug code should generally be removed before everything is finished. That is why the warning exists.
Why is that? I have look at some Moodle core code and it is using this function. What function should we use instead?