By earlofsandwich on
I'm slightly confused about the module coding standard which states "All text files should end in a single newline (\n)"
http://drupal.org/node/318#indenting
Does this mean
}\n
or does it mean
}\n
\n(hope that makes sense)
My interpretation is that the top example is the correct one as the file does finish with a single newline character, NOT the second one which actually finishes with two newlines. I ask because PAReview.sh is bumping my code complaining that I don't end in a single newline.
Many thanks
Comments
Your interpretation is
Your interpretation is correct, although the real meaning of that statement is "\n (Unix style), not \r\n (Windows style)". If you're using Win, look into editor settings (can't tell where exactly, haven't used Win myself for years).
Thanks Drave, I think I was
Thanks Drave,
I think I was getting confused because it says a 'single newline' (which could imply a line on its own) rather than a 'single newline character' - which would be at the end of a line of code.
I think I should maybe post this in the documentation pages instead?
new line on its own
the documentation means
For eg. take up index.php file that comes with drupal 7, it has 21 lines of code but it actually has 22 lines (the extra one blank line. The same goes with update.php. The best way to identify and understand the coding standards is to open up the drupal core and compare it :-)
Thanks for the suggestion
Thanks for the suggestion about checking core, should have thought of that one!
If you examine the D7 files with line endings turned on they are just }\n - Komodo IDE/EDIT has a great show EOL marker view.
The index.php has 21 lines of text with the \n at the very end of line 21 giving one extra (completely empty line) number 22 - I think we are both saying the same thing that basically there being one line of space at the bottom.
If it was }\n\n then when you moved the cursor to the bottom of the file it would sit 2 lines below which would not match core and would be 23 lines long!
Pedantic, I know, but this is why I was ending up in a tizz. Thanks all.
Hello again, I think I got
Hello again, I think I got the wrong end of the stick last post - It does indeed appear to be }\n\n - Thanks doitdave
This does appear to differ from what is in Core though, which, at least on my PC, only has a single newline at the end of its files... (Its not out of the question that my Windows GIT setup is stripping the final \n?)
Anyway, the long and the short of it is that a module/readme should end in a completely blank line - as in have one completely blank line after all the rest of the code, or two newline characters.
This seems to be what PAReview.sh validates to.
Phew. Thank you everyone.
Nonsense. The documentation
Nonsense. The documentation means
It has always meant that, and that is the way all Drupal core is written. PAReview.sh has a flawed test that was introduced just 12 days ago that tells you there should be an extra blank line at the end, which is what started all this confusion, but that's just a PAReview.sh bug - nothing has changed in the coding standards.
Specifically, to use your example, index.php has 21 lines. The last line is:
I really don't know where you come up with "22 lines". Perhaps you're using Windows and are seeing some side effect of that. Look at the hexdump below - it's perfectly clear that there are 21 lines and that the last character in line 21 is \n. All Drupal core files end with one and only one \n, no Drupal core has an "extra one blank line". Adding extra blank lines at the end of module files, for example, can lead to the dreaded "Cannot modify header information - headers already sent" error, which is why this rule is part of the Drupal coding standards.
You're right, I was
You're right, I was describing a newline as a separator between two lines (albeit a null one) rather than a line terminator. I see that \n as a line terminator is the more common use, (thanks Wikipedia) and therefore index.php would have 21 actual lines rather than 22. Apologies if I added to the mire of confusion there!
I see, TR, that you have updated the PAReview.sh issue queue. Hopefully this will stop all the misunderstandings and we can all get our modules approved again - I'm pretty new to submitting modules to Drupal so didn't want to wade in to PAReviews issue queue without getting the facts straight.
I suspect it would make sense to change the Drupal documentation to say
All files should end in a single newline character ('\n') - then there would be no ambiguity?
Thanks again for all your help.