Closed ahmadawais closed 8 years ago
Hey @ahmadawais, thanks for the bug report. Let's see if we can triage this, shall we?
First, can you please verify the version of WP Enforcer you have installed? There have been a few releases in the last week, and I want to make sure it's not a problem that's already been solved.
If you run ./vendor/bin/phpcs
from the root of the repository, what output do you see? If the answer is "none", then the changes you made might not be egregious enough to trigger PHP_CodeSniffer. An easy way to check is inserting something like this:
if('foo' == 'bar'){
echo "baz";
}
That block should set off all sorts of whitespace alarms :)
Next, please verify that your Git repository has a "pre-commit" hook (e.g. .git/hooks/pre-commit). The contents of the file should look something like what's in the repository.
Finally, if PHP_CodeSniffer is finding a problem and the hook is in place but you're able to commit that bogus code, please try swapping out the contents of the pre-commit hook with the version from the release/0.4.0 branch, which was adjusted in #13. If that solves it, I'll get a point release pushed out this morning to expedite that fix.
Thanks again for the report, and I'll look forward to hearing back from you!
@stevegrunwell Now it seems to be working. I guess you fixed something.
Is that how it works? Does it not provide any info on what and where is the problem?
@ahmadawais what all does your gcma
alias do? The output should look something like this:
MacBook-Pro:wp-enforcer steve$ git add index.php
MacBook-Pro:wp-enforcer steve$ git commit -m "This file is riddled with errors"
Running PHP CodeSniffer...
FILE: /Users/steve/Sites/httpdocs/wp-enforcer/index.php
----------------------------------------------------------------------
FOUND 10 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
1 | ERROR | [ ] Missing file doc comment
3 | ERROR | [ ] Empty IF statement detected
3 | ERROR | [x] Expected 1 space after IF keyword; 0 found
3 | ERROR | [x] Space after opening control structure is required
3 | ERROR | [x] No space before opening parenthesis is prohibited
3 | ERROR | [x] No space after opening parenthesis is prohibited
3 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
3 | ERROR | [x] No space before closing parenthesis is prohibited
3 | ERROR | [x] Space between opening control structure and closing
| | parenthesis is required
5 | ERROR | [x] File must end with a newline character
----------------------------------------------------------------------
PHPCBF CAN FIX THE 8 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
Time: 102ms; Memory: 4.75Mb
Please fix coding standards errors before committing
@ahmadawais let's revisit this when 0.4.0 drops – there have been a lot of updates and hopefully we'll get closer to the expected behavior :smile:
You can also update your composer.json to pull from the release/0.4.0
branch in the meantime.
@stevegrunwell gcma is git commit all. Check here.
I thought it would run for all files, shouldn't it?
In the very first release (0.1.0), the entire codebase was being run through PHP_CodeSniffer, which meant integrating WP Enforcer on an existing codebase could be a painful process. In #1 I adjusted this behavior so that only the files that are staged for commit are being checked; this way, if you're only touching functions.php in your commit you're not held liable for index.php, which you may or may not have ever touched.
You're still able to run PHP_CodeSniffer against the entire codebase, but I'd recommend doing that in a cleanup branch (see "Adding to an Existing Project").
Does that clarify things for you?
@ahmadawais ping for ^ ?
@stevegrunwell I'm going to try it next weekend, was busy with a WP Meetup.
Forgot to mention, it's working fine :)
Fantastic, thanks for following up!
I added a few problems in my code to see if it works, but I am commiting code and nothing happens. I am using Mac, testing a plugin and I have installed it just the way you wrote and added extra config in the composer.json.
What could be wrong?