Skip to content

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

Closed
@mboynes

Description

@mboynes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions