Select Page

PHPCS (code sniffer) is a great tool for linting & checking your codes against the set of rules. Along with PHPCS, as WordPress folk, we use WordPress coding standards (WPCS) as well. It is very useful to maintain coding standards, ensure output escaping, nonce verification, SQL escape, etc. But sometimes, there will be cases to avoid rules checking for specific code snippets.

Let’s discuss the useful comments to suppress warnings

To Ignore code snippets we can use the below comments:

// @codingStandardsIgnoreStart

// @codingStandardsIgnoreEnd

All the codes inside the above comments will be ignored

Ignore just the below line:

//phpcs:ignore

Ignore nonce verification warning:

//phpcs:disable WordPress.Security.NonceVerification.Recommended

Suppress PHPCS(WordPress.DB.PreparedSQL.InterpolatedNotPrepared)

//phpcs:ignore WordPress.DB.PreparedSQL

Ignore nonce verification missing warning

// phpcs:disable WordPress.Security.NonceVerification.Missing

Suppress PHPCS(Squiz.Commenting.FileComment.Missing)

//phpcs:ignore Generic.Commenting.DocComment.MissingShort

PHPCS(WordPress.Files.FileName.NotHyphenatedLowercase)

//phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase

There may have a lot more comments to suppress warnings. If you know others’ comments, feel free to share through the comments section below! Happy coding 😀