Closed (works as designed)
Project:
Coder
Version:
8.x-2.x-dev
Component:
Coder Sniffer
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
19 Nov 2011 at 17:46 UTC
Updated:
25 Mar 2014 at 04:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
klausiImplemented in DrupalCodingStandard_Sniffs_WhiteSpace_EmptyLinesSniff, see http://drupalcode.org/project/drupalcs.git/commit/2b17f23
Comment #3
jcisio commentedSorry to reopen a closed issue in a closed project, but I can't find any other trace.
- This issue was committed on Dec 5th http://drupalcode.org/project/drupalcs.git/commitdiff/2b17f23
- Then 3 days later, the file was splitted into another file, and the code changed completely http://drupalcode.org/project/coder.git/commitdiff/3c4f2fa, now does not allow blank ending line.
Then which one is correct? Most Drupal core files don't have blank ending line, but they cause the verbose "\ No newline at end of file" without the blank ending line.
Comment #4
klausiDrupal Code Sniffer has been merged into Coder 7.x-2.x. Please move this issue to the Coder queue and reopen it if the problem still exists.
Comment #5
jcisio commented"The problem" is in fact an open question.
Comment #6
klausiThe current code should work as expected and as defined in our coding standards: https://drupal.org/coding-standards#indenting
Please note that some editors display the last "\n" in a file as separate line (e.g. Eclipse) and some not (e.g. Vim).
Comment #7
jcisio commentedI don't understand why I'm the only one who complains that. Currently, in core, there is no file that ends with a new line. And if files end with a new line, Coder makes a warning (see screenshot). I'm actually using vim.
If I remove the last empty line (so that my file ends with "\n}" (or
0a7d) and not "\n}\n"), Coder says ok.It is not what described in the coding standards https://drupal.org/coding-standards#indenting (the last paragraph).
Comment #8
klausiIt is single new line character, which is "\n". Vim does not display that as separate line.
Comment #9
jcisio commentedVim does display. In my example above, the last 3 characters are "\n}\n" (or "0a7d0a" by hexdump), and Vim does display the last character "\n" (line 2038).
In other IDE, like PHPStorm or Eclipse, a new "virtual" line is added (I'll see line 2039 even there is only 2038 lines).
Comment #11
seanrI believe this to be erroneously or at least inadvertently marked closed given the last couple replies. Can we verify whether this is working correctly according to the docs? A failure on something this simple would understandably discourage new contributors so I think it important we be sure to get it right.
Comment #12
klausiThis is working fine since a long time now, please provide a test case/file where you think it reports a false positive.
Comment #13
psynaptic commentedI'm seeing the same erroneous behaviour. It's complaining about there being no newline at the end of my test file, but there definitely is one.
It also displays an erroneous error about the file docblock.
I've attached the file so it can be tested by others. I'm on the phpcs-2.0 branch btw.
Comment #14
psynaptic commentedI'll happily make a patch for this but wanted to post it here now, since I don't know which branch to commit it to yet.
I moved the substr expression into the conditional to match the one below and make the code more readable. I also made the comments more accurate.
Aside from that, what coding standards are we following with the rules? I see
else ifis being used more often thanelseifwhich is against the Drupal coding standards, but perhaps not the ones used for the phpcs rules.Comment #15
psynaptic commentedSetting correct component and pushing to 8.x-2.x as it should be fixed there first and backported.
Comment #16
klausiThe test file from #13 has two newline characters at the end, so the sniff correctly reports that.
Comment #17
klausiOh, and we are using PHPCS coding standards for our sniffs to be more compatible with PHPCS when we copy or modify sniffs.
Comment #18
psynaptic commentedI see! You are right, klausi.
To prove exactly how spectacularly wrong I am, I downloaded the latest release (8.x-2.0-alpha1) and ran some tests to (hopefully) clear this up once and for all.
Here's the first example showing a file without a newline (single \n character) at the end of the file:
Here's the other side of the test (after committing the file):
We can see from 3 different sources how wrong I am (oh and also that and that phpcs didn't throw the error).
Conclusion
First of all, there is nothing wrong with the sniff, so if that's all you're interested in you can stop reading now.
Why this is confusing people (myself included) has become clear to me.
The confusion is caused by different editors handling the display of the newline in different ways. In vim you don't see the newline as an actual blank line, whereas in other editors e.g. TextMate you do see a whole blank line. Seeing the blank line in the editor makes it easier, for better or worse, to be able to remove the final \n character from a file.
I've been duped into thinking a newline at the end of a file meant a whole blank line when really this was just a product of the way the editor I used long ago handled the display of the final newline character. I've actually been putting blank lines at the end of files all this time!
Anyway, I think that's about all I can say on the no-newline-at-end-of-file issue.