Feedback only, no action required, please close on reading.
The Drupal coding standard regarding whitespace requires:
Lines should have no trailing whitespace at the end.
Even if one has NetBeans IDE configured to use these excellent tips on NetBeans formatting settings for Drupal - which go a long way to help one meet the Coder rules - NetBeans often introduces whitespace automatically, which trips up Coder. It can be a real time waster and annoyance.
It happens for example when one hits ENTER/RETURN at the end of a line of code like this:
$a = $b + 1;
// NetBeans will put in 2 whitespaces above, they have to be removed by hand
Comments
Comment #1
klausiYep, I'm using Netbeans myself and this is annoying.
Thanks for reporting, I guess we cannot do anything at Coder's end. Do you know if a bug report against Netbeans already exists regarding this?
Comment #2
klausiTip: if you use PHPCS 2.x and Coder 8.x-2.x you can fix such whitespace issues automatically with phpcbf.
Comment #3
webel commentedHi @klausi, thanks for the tip.
For now I am doing a lot by hand in NetBeans, because I have a special coding recipe that is amenable o reverse engineering for PEAR PHP_UML and MagicDrawUML, so I am avoiding any other code manipulation tools.
The problem I am reporting here is really a NetBeans IDE formatting problem, not a Coder problem.
Here is another example, if I hit return after the end of a Class declaration (after the {) NetBeans inserts 2 spaces:
There are actually 2 spaces there above that I have to remove by hand.
[EDIT: to show it on Drupal.org (which takes away my whitespace as pasted) I have now inserted 2 underscores]
Comment #4
webel commentedAnother example using the NetBeans configuration as per the excellent link above.
NetBeans8.0 makes the line longer than 80, although the config seems to have 80 lines as the line length setting:
I have to train it to do some things differently to pass some Coder rules automatically.
Eventually, I want to be able to pass all Coder rules directly from NetBeans, without any further manipulation.
Comment #5
webel commented@klausi commented a day ago:
May I ask 2 questions.
Q1: My current module project is for Drupal7, so I am using Coder 7.x-2.x. Are you saying that the automatic whitespace fix only works with Coder 8.x-2.x ?
From http://www.squizlabs.com/php-codesniffer:
Q2: It seems from the above I can only choose to accept all suggested changes from a Coder run, or none. Would it be possible to only accept whitespace changes ?
The reason is that some of the changes Coder is suggesting break my own coding rules for PHP that is amenable to reverse engineering to graphical UML with PEAR: PHP_UML, and if I use a tool to perform automated changes, it could break the synchronisation between my PHP code and my reverse engineered UML models.
Editing whitespace is harmless for that synchronisation, but such issues as the following are not: OO: Coder complains about camel caps (camelCase) argument to setter method in Class. I do not only strongly, and with good reason, completely reject that current rule, if I run it (along with say the whitespace change) it will cause me a heck of a lot of work changing my UML model to match, by hand, and reexporting and reuploading these UML diagrams.
Comment #6
webel commentedFrom Using coder.module to auto-format your code with drush:
drush coder-format sites/all/modules/custom/{$modulename}It is not clear to me whether one can choose to apply only specific rules, such as whitespace cleanup.
Comment #7
klausiYes, the fixer part of PHPCS only works on Coder 8.x-2.x, since only that branch is compatible with PHPCS 2.x.
We don't have automatic fixer rules for all errors that Coder reports, only for the obvious ones (not even completely for those, patches welcome). You can pass config options to phpcbf to only run certain fixers and not all of them, see https://github.com/squizlabs/PHP_CodeSniffer/wiki/Fixing-Errors-Automati...
Comment #8
webel commentedSolution for NetBeans trailing whitespace
This works for removing trailing whitespace in NetBeans 8.0 (Mac version):
Make sure you have:
And you may need to deselect:
It was not at all obvious to me that this might be under On Save.
You have to at least perform a dummy edit then save the file for it to work.
NetBeans still seems to introduce the whitespaces on an empty next line
or empty documentation line sometimes on [ENTER]/[RETURN], but at
least it gets removed on save.
See also: http://stackoverflow.com/questions/4119872/netbeans-removing-trailing-wh...