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

Add sniff for deprecated Theme related WP Constants. #30

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jul 18, 2016

Covers the sniff + unit test for issue #23.

This PR covers the currently known list as can be found in: https://github.com/Otto42/theme-check/pull/162/files

@jrfnl jrfnl force-pushed the WPTRT/feature/issue-23-forbidden-constants branch 2 times, most recently from 61ba2fd to 20dfc70 Compare July 18, 2016 20:05
Covers the sniff + unit test for issue #23.

This PR covers the currently known list as can be found in: https://github.com/Otto42/theme-check/pull/162/files
@jrfnl jrfnl force-pushed the WPTRT/feature/issue-23-forbidden-constants branch from 20dfc70 to 0f08cff Compare July 19, 2016 10:48
@jrfnl jrfnl changed the title Add sniff for forbidden Theme related WP Constants. Add sniff for deprecated Theme related WP Constants. Jul 19, 2016
@jrfnl
Copy link
Contributor Author

jrfnl commented Jul 19, 2016

Updated to read 'Deprecated' not 'Forbidden'

*/

/**
* WordPress_Tests_Theme_DeprecatedWPConstants
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a full stop at the end here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on improving the standard documentation in WPCS and will port back to any code in the theme review branch if/when my changes are accepted in WPCS. Ok?

@ernilambar
Copy link
Member

@grappler define( 'HEADER_TEXTCOLOR', '#F00' ); this code does not seem to be caught by this sniff.

@jrfnl
Copy link
Contributor Author

jrfnl commented Jan 20, 2017

@ernilambar That's correct behaviour.
This sniff is not testing for people defining Core constants as that would give a PHP error of "Constant already defined" anyway.
It is only testing for usage of the deprecated constants.

@ernilambar
Copy link
Member

define('HEADER_IMAGE_WIDTH',1200);
define('HEADER_IMAGE_HEIGHT',600);

This type of code and similar should be caught by the sniff I believe. This code wont give Constant already defined error, since this was the recommended method used to override Custom Header before 3.4. And WP is good at BC even if it is lame. :D
// Constants are lame. Don't reference them. This is just for backwards compatibility.

@jrfnl
Copy link
Contributor Author

jrfnl commented Jan 21, 2017

In that case, another sniff should be created (or additional check added to this sniff) to check for define() statements and const statements.
That was not the original purview of this sniff "Check for usage of deprecated WP constants" See #23

If you think that TRTCS should also check for constants being defined, please open a new issue in this repo so this can be properly discussed.

jrfnl added a commit to WordPress/WordPress-Coding-Standards that referenced this pull request Aug 5, 2017
This sniff is based on a sniff previously pulled to the TRT fork of WPCS as `Theme.DeprecatedConstants`.

Related issue: WPTT/WPThemeReview/issues/23
Original PR: WPTT/WPThemeReview/pull/30
Covers the list of constants found in: WordPress/theme-check/pull/162

Differences between that sniff and this one:
* This sniff is a **_lot_** more comprehensive in preventing false positives.
    The original sniff was one of the first ones I wrote and it's kind of sweet to look back at that code which I wrote over a year ago and see how much I've learned about writing sniffs in the mean time.
* The original sniff was called `Theme.DeprecatedConstants`, but in reality, most of these constants aren't officially deprecated, though their usage is discouraged and the constants being addressed are not 100% related to themes either. With that in mind, I've renamed the sniff to `WP.DiscouragedConstants` and changed the error level from Error to Warning.
    Also see: https://core.trac.wordpress.org/ticket/18298
* This version of the sniff also addresses the concerns raised in WPTT/WPThemeReview/issues/110 about themes `define`-ing any of these constants and leverages the `AbstractFunctionParameterSniff` to do so.

Includes quite extensive unit tests. More are definitely welcome, especially to prevent false positives.

I've added the sniff to the `WordPress-Extra` ruleset.

Fixes 97
Will also fix WPTT/WPThemeReview/issues/110 once the original sniff gets removed from the TRT fork and this sniff is added to the TRT ruleset instead.
jrfnl added a commit to WordPress/WordPress-Coding-Standards that referenced this pull request Aug 5, 2017
This sniff is based on a sniff previously pulled to the TRT fork of WPCS as `Theme.DeprecatedConstants`.

Related issue: WPTT/WPThemeReview/issues/23
Original PR: WPTT/WPThemeReview/pull/30
Covers the list of constants found in: WordPress/theme-check/pull/162

Differences between that sniff and this one:
* This sniff is a **_lot_** more comprehensive in preventing false positives.
    The original sniff was one of the first ones I wrote and it's kind of sweet to look back at that code which I wrote over a year ago and see how much I've learned about writing sniffs in the mean time.
* The original sniff was called `Theme.DeprecatedConstants`, but in reality, most of these constants aren't officially deprecated, though their usage is discouraged and the constants being addressed are not 100% related to themes either. With that in mind, I've renamed the sniff to `WP.DiscouragedConstants` and changed the error level from Error to Warning.
    Also see: https://core.trac.wordpress.org/ticket/18298
* This version of the sniff also addresses the concerns raised in WPTT/WPThemeReview/issues/110 about themes `define`-ing any of these constants and leverages the `AbstractFunctionParameterSniff` to do so.

Includes quite extensive unit tests. More are definitely welcome, especially to prevent false positives.

I've added the sniff to the `WordPress-Extra` ruleset.

Based on https://vip.wordpress.com/documentation/code-review-what-we-look-for/#using-theme-constants and https://core.trac.wordpress.org/ticket/18298#comment:2, I've also added the sniff to the `WordPress-VIP` ruleset. /cc @sboisvert @david-binda @ntwb

Fixes 97
Will also fix WPTT/WPThemeReview/issues/110 once the original sniff gets removed from the TRT fork and this sniff is added to the TRT ruleset instead.
@jrfnl jrfnl added this to the 0.1.0 milestone Aug 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants