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

phpcs-patch #1

Closed
wants to merge 18 commits into from
Closed

phpcs-patch #1

wants to merge 18 commits into from

Conversation

westonruter
Copy link

No description provided.

* @package PHP_CodeSniffer
* @author Jack Bates <ms419@freezone.co.uk>
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Weston Ruter <weston@x-team.com>
Copy link
Author

Choose a reason for hiding this comment

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

@shadyvb actually this should be you 😄

Copy link

Choose a reason for hiding this comment

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

@westonruter Modified in f40fe46, Thanks!

// If supplied a transaction, or running on server, use svnlook, to handle svn:pre-commit ( on svn server )
if ( in_array( '-t', $values['vcsArgs'] ) || ! $values['direct-call'] ) {
$command = sprintf(
'svnlook changed %s',
Copy link
Author

Choose a reason for hiding this comment

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

@shadyvb ah, here we're not using PHP_CODESNIFFER_SVNLOOK anyway.

Copy link

Choose a reason for hiding this comment

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

@westonruter that's a glitch, will switch to using the const till we get a response from squizlabs.

? $rev = str_replace( ':', ' ', $vcs_rev )
: '';
$command = sprintf(
'git show %s:%s',
Copy link
Author

Choose a reason for hiding this comment

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

@shadyvb if I invoke phpcs-patch with a commit-span like:

phpcs-patch --standard=WordPress -r e82920f:31174f73

Then I see among the command log:

== Executing: git show e82920f 31174f73:path/to/file.php

This seems to produce the incorrect results, including a patch followed by the file at the commit 31174f73, I believe.

So isn't the need to ensure that only the recent-most commit is used for git-show?

Copy link
Author

Choose a reason for hiding this comment

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

@shadyvb for example:

diff --git a/scripts/phpcs-patch b/scripts/phpcs-patch
index 939a7ae..73e06bc 100755
--- a/scripts/phpcs-patch
+++ b/scripts/phpcs-patch
@@ -310,7 +310,7 @@ class PHP_CodeSniffer_Patch_CLI extends PHP_CodeSniffer_CLI
             if ( $values['vcsType'] == 'git' ) {
                 // Get file from a certain revision, fallback to STAGED if not provided
                 $rev = ( $vcs_rev )
-                    ? $rev = str_replace( ':', ' ', $vcs_rev )
+                    ? $rev = preg_replace( '/.*:/', '', $vcs_rev )
                     : '';
                 $command = sprintf( 
                     'git show %s:%s',

Copy link
Author

Choose a reason for hiding this comment

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

westonruter referenced this pull request in squizlabs/PHP_CodeSniffer Nov 12, 2013
…mit hook. Also reworked the way the phpcs script works to make it easier to wrap it with other functionality.

git-svn-id: http://svn.php.net/repository/pear/packages/PHP_CodeSniffer/trunk@254739 c90b9560-bf6c-de11-be94-00142212c4b1
$rev = ( intval( $info ) - 1 ) . ':' . 'HEAD';
}
$command = sprintf(
'svn diff -r %s %s --summarize',
Copy link
Author

Choose a reason for hiding this comment

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

@shadyvb what if the user just wants to apply the sniffs against the changes which are not committed at all? For Git, this is accomplished with --staged. But since SVN lacks a stage, we need to just look at the currently modified files. So if no revision is provided, then instead of looking for the most recent commit (as done in the else above), shouldn't it omit the -r parameter entirely?

Copy link

Choose a reason for hiding this comment

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

@westonruter As far as i remember, I believe the assumption of the user testing staged changes is heavily considered throughout the code. We'll need some changes to make this work for non-staged changes as well, probably starting with a new parameter to distinguish which changes to check, and some code changes/testing.

@westonruter
Copy link
Author

I talked with @aaronjorbin about getting the PHP_CodeSniffer WordPress-Coding-Standards added to WordPress core develop repo, and invoked automatically by grunt for pre-commit checks. This phpcs-patch script should be a dependency for this, however, since there is a ton in Core that violates the established coding standards.

All that to say, I want to some more testing on your great work here @shadyvb and then open a PR for merging upstream into the PHP_CodeSniffer project. Once that is done, then we can open a WP Trac ticket for getting this integrated into the dev tools!

@shadyvb
Copy link

shadyvb commented Jul 20, 2014

@westonruter This seems like a great thing to do! Let me know if i can do anything to help!
/five!

westonruter pushed a commit that referenced this pull request Oct 11, 2014
@westonruter
Copy link
Author

Opened a Trac ticket for this: https://core.trac.wordpress.org/ticket/30153

@westonruter westonruter mentioned this pull request Feb 1, 2015
@shadyvb
Copy link

shadyvb commented Feb 2, 2015

Closing in favor of #5

@shadyvb shadyvb closed this Feb 2, 2015
@aaronjorbin
Copy link

Awesome stuff. Are you planning on submitting this upstream to PHP_CodeSniffer?

@westonruter
Copy link
Author

@aaronjorbin yes, #5 is the changes we'd upstream.

westonruter pushed a commit that referenced this pull request Oct 11, 2015
Pull master from squizlabs
westonruter pushed a commit that referenced this pull request Jul 14, 2017
westonruter pushed a commit that referenced this pull request Jul 14, 2017
westonruter pushed a commit that referenced this pull request Jul 14, 2017
westonruter pushed a commit that referenced this pull request Jul 14, 2017
westonruter pushed a commit that referenced this pull request Jul 14, 2017
westonruter pushed a commit that referenced this pull request Jul 14, 2017
westonruter pushed a commit that referenced this pull request Jul 14, 2017
westonruter pushed a commit that referenced this pull request Jul 14, 2017
westonruter pushed a commit that referenced this pull request Jul 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants