Last modified: 2014-11-19 21:50:21 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T46875, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 44875 - Jenkins: Create phpcs sniff to detect text before the first <?php tag
Jenkins: Create phpcs sniff to detect text before the first <?php tag
Status: NEW
Product: Wikimedia
Classification: Unclassified
Continuous integration (Other open bugs)
unspecified
All All
: Lowest enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-02-11 14:26 UTC by Matthew Flaschen
Modified: 2014-11-19 21:50 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Matthew Flaschen 2013-02-11 14:26:38 UTC
It would be helpful to comment or downvote if there was whitespace (or possibly any character) before the <?php/<? tag.  This causes unexpected output, which can lead to annoying issues.

It could initially be done as a non-voting job.

PHP CodeSniffer might be one way to implement this check.
Comment 1 Antoine "hashar" Musso (WMF) 2013-02-11 14:33:45 UTC
Maybe something as lame as:

 grep --perl-regexp '\s+\<\?php' -R  mediawiki/core

But that in turns return a toooon of false positive since we have templates using <?php :-D
Comment 2 Chad H. 2013-02-11 14:45:26 UTC
(In reply to comment #1)
> But that in turns return a toooon of false positive since we have templates
> using <?php :-D

Yeah, I was going to say, you'd want to check the first line only or we'd probably get a lot of false positives.
Comment 3 Matthew Flaschen 2013-02-11 15:05:25 UTC
Yeah, I meant the first line, just forgot to say it.

I found a good way to do it.  The relevant CodeSniffer rule is Generic.PHP.CharacterBeforePHPOpeningTag.

I tested it with:

phpcs --standard=Generic --sniffs=Generic.PHP.CharacterBeforePHPOpeningTag somefile.php
Comment 4 Antoine "hashar" Musso (WMF) 2013-02-12 08:24:28 UTC
Ah thanks for looking in codesniffer rules!

The Generic.PHP.CharacterBeforePHPOpeningTag rule looks almost like something we could use. Unfortunately it complains whenever the T_OPEN_TAG token is not the very first token, for example when we have several open tags in a file.

A few examples from core:

includes/Feed.php
includes/SkinTemplate.php
includes/api/ApiFormatBase.php
includes/templates/Userlogin.php


Not ideal yet :(
Comment 5 Matthew Flaschen 2013-02-13 10:38:08 UTC
You're right.  The error message is not consistent with the actual behavior.
Comment 6 Krinkle 2013-06-25 19:15:35 UTC
The CharacterBeforePHPOpeningTag sniff is good, but we can't use it as-is because it also warns when you use multiple <?php tag in the file (e.g. Skin templates).

We should create our own version based on CharacterBeforePHPOpeningTag that only warns for the first one.
Comment 8 Greg Grossmeier 2014-09-23 23:17:37 UTC
Krinkle: Over a year since last activity, removing Krinkle as assignee. He know how to re-add if he wants :)

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links