Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant use phpcs:ignore where the next line is HTML #1867

Closed
mboynes opened this issue Jan 29, 2018 · 2 comments
Closed

Cant use phpcs:ignore where the next line is HTML #1867

mboynes opened this issue Jan 29, 2018 · 2 comments
Milestone

Comments

@mboynes
Copy link

mboynes commented Jan 29, 2018

Summary

As best I can tell, it's not possible to use phpcs:ignore where the next line is HTML and not PHP.

Details

Given the following line in a block of HTML in a PHP file:

<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

When using the WordPress Standards, this line fails the WordPress.WP.EnqueuedResources.NonEnqueuedScript sniff. In order to ignore that sniff for this line, I expected to be able to do this:

<?php // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript ?>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

... however, that doesn't work. From what I gather, it's not possible to use the phpcs:ignore feature on a line of HTML. In fact, because the WordPress standards includes the Squiz.PHP.EmbeddedPhp.SpacingBeforeClose sniff, it adds that additional error (I'm not sure if that's deliberate or a false positive).

In my case, what I had to do was:

<?php /* phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript */ ?>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<?php /* phpcs:enable WordPress.WP.EnqueuedResources.NonEnqueuedScript */ ?>

It would be nice to be able to use phpcs:ignore on an HTML line using a single line of PHP with a comment as demonstrated above.

@gsherwood
Copy link
Member

This is because a phpcs:ignore command ignores the current line when there is other content on that line, and only ignores the following line if there is no content. Currently, PHPCS is seeing the opening tag as a piece of content, which is why the following code works:

<?php
// phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript ?>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

So I just need to ignore opening tags in this check and you'll be able to use the ignore command properly for this case.

@gsherwood gsherwood changed the title Use phpcs:ignore where the next line is HTML Cant use phpcs:ignore where the next line is HTML Jan 30, 2018
@gsherwood
Copy link
Member

I had to ignore open tags and blank inline HTML in case you were indenting the comment, but it should work ok for you now. Thanks for reporting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants