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
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jsst created an issue. See original summary.

jsst’s picture

See attached patch.

klausi’s picture

Version: 7.x-2.5 » 8.x-2.x-dev
Status: Needs review » Postponed (maintainer needs more info)

Can you test again with Coder 8.x-2.x? It can be used to check code for any version of Drupal.

klausi’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Closing due to lack of activity, feel free to reopen with new information.

jsst’s picture

Thanks, 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.