Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've encountered an issue where newlines are stripped from standard input, causing the FileEnd sniff to signal an unwarranted error. This might not be a problem on all environments but it shows the fragility of the implementation.
I've rewritten the sniff based on the EndFileNewlineSniff from the PSR2 standard. It's better in the following ways:
- Does not read the whole file but uses existing tokens
- Contains no hacks to read from standard input
- Also signals an error on too many newlines at the end of file, like the PSR2 sniff
Some compatibility remarks:
- The error code is unchanged (FileEnd.FileEnd)
- The erorr message contains additional info: (none found, x found)
- The new error message for too many newlines is FileEnd.TooMany
Comment | File | Size | Author |
---|---|---|---|
#2 | coder-fileend-sniff-improvements-2647784-1-7.x.patch | 3.5 KB | jsst |
Comments
Comment #2
jsst CreditAttribution: jsst at Ibuildings commentedSee attached patch.
Comment #3
klausiCan you test again with Coder 8.x-2.x? It can be used to check code for any version of Drupal.
Comment #4
klausiClosing due to lack of activity, feel free to reopen with new information.
Comment #5
jsst CreditAttribution: jsst at Ibuildings commentedThanks, I can confirm this works as expected in 8.x.
Some people might not be willing to switch to the 8.x version since the sniffs are slightly different compared to the 7.x version, above patch might be helpful in that situation.