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

Theme Restricted Parameter #80

Closed
wants to merge 3 commits into from
Closed

Theme Restricted Parameter #80

wants to merge 3 commits into from

Conversation

khacoder
Copy link
Contributor

Initial PR
Issue #72


foreach ( $checks as $key => $check ) {
if ( trim( $token['content'], '\"\'"' ) === $key ) {
$nextStackPtr = $stackPtr;
Copy link
Member

Choose a reason for hiding this comment

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

Is this line needed?

foreach ( $checks as $key => $check ) {
if ( trim( $token['content'], '\"\'"' ) === $key ) {
$nextStackPtr = $stackPtr;
$nextStackPtr = $phpcsFile->findNext( $types , $nextStackPtr + 1 );
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps just place array( T_CONSTANT_ENCAPSED_STRING ) directly in here.

if ( trim( $token['content'], '\"\'"' ) === $key ) {
$nextStackPtr = $stackPtr;
$nextStackPtr = $phpcsFile->findNext( $types , $nextStackPtr + 1 );
foreach ( $check as $key2 => $arg ) {
Copy link
Member

Choose a reason for hiding this comment

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

What about $args_key instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are numbers as bad as globals :)
Will fix in the next update.

@grappler grappler force-pushed the feature/theme-review-sniffs branch 2 times, most recently from 563cd1d to 6671823 Compare September 27, 2016 12:28
);

foreach ( $checks as $key => $check ) {
if ( trim( $token['content'], '\"\'"' ) === $key ) {
Copy link
Member

Choose a reason for hiding this comment

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

Functions in PHP can be uppercase too. So BlogInfo() would work too. The check would not catch that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, functions in PHP are case-insensitive, no matter how the function was declared and whether it is a native PHP function or a user-land function.

So any comparison for function names should be done in a case-insensitive way.

function my_function() {
    // do something
}

my_function(); // works
MY_function(); // works
MY_FUNCTION(); // works
My_FuncTion(); // works

@jrfnl
Copy link
Contributor

jrfnl commented Sep 29, 2016

I suggest pausing work on this one in anticipation of the AbstractFunctionCall base class as discussed in Slack.

I intend to add an AbstractFunctionCall base class to WPCS which will first process to check if something a) is a function call and b) is in the list of functions you're looking for and will only pass off the processing to the child class once that has been established

Once in the child class, you can then use for instance the (upcoming) getFunctionCallParameter( $offset ) method to get the exact parameter to check or if you only wanted to check whether a function is used, you could just throw an error straight away


if ( isset( $this->functions[ $token['content'] ] ) ) {
$function = $this->functions[ $token['content'] ];
$parameter_arg = $this->getFunctionCallParameter( $phpcsFile, $stackPtr, 1 );
Copy link
Contributor

Choose a reason for hiding this comment

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

Quick remark: I would make the parameter position part of the array above as for different functions, the parameter position might be different and hardcoding it to 1 here does not allow for that flexibility.

See these example sniffs which also uses this utility function:

The array for WP would look differently, but you can probably get some inspiration from the array as used there.

@grappler
Copy link
Member

Not all of the parameters are actually deprecated. So I am checking if there is a reason why they were not supposed to be used. https://wordpress.slack.com/archives/core/p1479063392002489

Also it seems like feed_url is also not a valid parameter.

@justintadlock
Copy link

Some of the URL ones are not technically deprecated. However, they are inconsistent. Just look at this mess:

case 'stylesheet_url':
    $output = get_stylesheet_uri();
    break;
case 'stylesheet_directory':
    $output = get_stylesheet_directory_uri();
    break;
case 'template_directory':
case 'template_url':
    $output = get_template_directory_uri();
    break;

IIRC, once core WP added getter functions for the URLs, we decided to make them required for consistency sake.

I'd actually like to see core WP drop the entire function and separate it into multiple functions. It might be worth exploring putting a core ticket for that together as a team.

@grappler
Copy link
Member

Ok, I move the parameters that are not deprecated to a restricted parameters sniff so that there is a clear distinction.

I'd actually like to see core WP drop the entire function and separate it into multiple functions. It might be worth exploring putting a core ticket for that together as a team.

Sounds like a good idea.

@pattonwebz
Copy link
Member

Verify restrictions and alts against TRT handbook.

@jrfnl
Copy link
Contributor

jrfnl commented May 31, 2018

I will review the actual logic in the process_parameter() method and let you know if I have feedback.

@jrfnl
Copy link
Contributor

jrfnl commented May 31, 2018

I will also rebase the PR & update for PHPCS 3.x.

@grappler grappler removed their assignment May 31, 2018
@khacoder
Copy link
Contributor Author

I would like to finish this one if I could please.

@khacoder
Copy link
Contributor Author

khacoder commented Jun 2, 2018

Looks like this one has had some changes, I will let you set it up for 3.x. If it needs any additional attention let me know.

Initial Commit
Issue #72
@jrfnl
Copy link
Contributor

jrfnl commented Jun 2, 2018

@khacoder Could you give me the rights to push to your fork of the repo ? I've made the PHPCS 3.x update, but my push gets rejected.

@jrfnl
Copy link
Contributor

jrfnl commented Jun 2, 2018

@khacoder Saw the invite. Thanks for that. I've just (force) pushed the updated branch. You will need to reset your local branch to the remote version to get access to the changes.

As you asked to continue with the sniff yourself, I've only done a rebase and added a commit which sorts out the PHPCS 3.x compatibility and some minor updates for consistency with WPCS.

Would you like me to review the logic in the process_parameter() method at this time or do you want to have a look yourself first ?

@khacoder
Copy link
Contributor Author

khacoder commented Jun 2, 2018

Sure I can take a look.

@khacoder
Copy link
Contributor Author

khacoder commented Jun 3, 2018

Just going over the logic and reason for this sniff. It was initially set up to replicate the more-deprecated.php sniff in the theme check plugin. The theme check is currently unchanged from when this sniff was initially developed.

So why has this sniff changed? Many parameters have been added that are not deprecated, and parameters have been removed that are deprecated.

So why are Error's being generated for non deprecated parameters? I would think that they should be Warnings ?

Edit: Many of the alts are output by the functions, so I was kind of wondering why they are even in the sniff?

@khacoder
Copy link
Contributor Author

khacoder commented Jun 4, 2018

Hey @jrfnl

I think I'll let you finish this off, sorry about the above comments.

Just a heads up, the error message needs some love. Also check the bloginfo() alts as bloginfo echos get bloginfo().

@grappler
Copy link
Member

grappler commented Jun 4, 2018

As @khacoder prompted me to look closer at the PR I realised I had worked on a sniff to check for deprecated parameter values that should be merged into WPCS itself.

grappler/WordPress-Coding-Standards@61897bf

For that reason I think this PR should be marked as wait for upstream for the moment till that sniff it added to WPCS and then this Sniff could extend that.

@jrfnl
Copy link
Contributor

jrfnl commented Jun 4, 2018

@grappler 👍 Sounds good to me. Go for it! (and let me know if you want me to take a look in advance)

@jrfnl
Copy link
Contributor

jrfnl commented Jun 5, 2018

and then this Sniff could extend that.

@grappler Having just reviewed the upstream sniff, if you want to be able to extend that one, it will need some changes in the setup.

@justintadlock
Copy link

The team decided that this should mirror Theme Check and only catch the stylesheet and directory URLs. @khacoder can fill in the details if necessary.

Meeting: https://wordpress.slack.com/archives/C02RP4Y3K/p1528822802001090

@jrfnl
Copy link
Contributor

jrfnl commented Jul 25, 2018

PR #165 has been pulled which will include the WPCS deprecated parameter values sniff as created by @grappler. Once that PR has been merged, this PR can be adjusted to extend the upstream WPCS sniff.

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.

None yet

5 participants