Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Added Wordpress Coding Standards Sniffs to Gulp #626

Merged
merged 2 commits into from
Dec 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ assets/javascript/vendor/
assets/javascript/foundation.js
assets/javascript/custom/demosite.js
packaged/
wpcs/
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ Version control on these files are turned off because they are automatically gen

* `assets/javascript/vendor`: Vendor scripts are copied from `assets/components/` to this directory. We use this path for enqueing the vendor scripts in WordPress.

### Check For WordPress Coding Standards

Foundation comes with everything you need to run tests that will check your theme for WordPress Coding Standards. To enable this feature you'll need to install PHP Codesniffer, along with the WordPress Coding Standards set of "Sniffs". You'll need to have [Composer](https://getcomposer.org/) To install both run the following:
```bash
$ composer create-project wp-coding-standards/wpcs:dev-master --no-dev
```
When prompted to remove existing VCS, answer Yes by typing `Y`.

Once you have installed the packages, you can check your entire theme by running:
```bash
$ npm run phpcs
```

If there are errors that Code Sniffer can fix automatically, run the following command to fix them:
```bash
$ npm run phpcbf
```

## Demo

* [Clean FoundationPress install](http://foundationpress.olefredrik.com/)
Expand Down
28 changes: 26 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

var $ = require('gulp-load-plugins')();
var argv = require('yargs').argv;
var gulp = require('gulp');
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var merge = require('merge-stream');
var sequence = require('run-sequence');
var colors = require('colors');
var phpcs = require('gulp-phpcs');
var phpcbf = require('gulp-phpcbf');
var gutil = require('gulp-util');

// Enter URL of your local server here
// Example: 'http://localwebsite.dev'
Expand Down Expand Up @@ -172,6 +175,27 @@ gulp.task('build', function(done) {
done);
});

gulp.task('phpcs', function() {
return gulp.src(['*.php'])
.pipe(phpcs({
bin: 'wpcs/vendor/bin/phpcs',
standard: './codesniffer.ruleset.xml',
showSniffCode: true,
}))
.pipe(phpcs.reporter('log'));
});

gulp.task('phpcbf', function () {
return gulp.src(['*.php'])
.pipe(phpcbf({
bin: 'wpcs/vendor/bin/phpcbf',
standard: './codesniffer.ruleset.xml',
warningSeverity: 0
}))
.on('error', gutil.log)
.pipe(gulp.dest('.'));
});

// Default gulp task
// Run build task and watch for file changes
gulp.task('default', ['build', 'browser-sync'], function() {
Expand All @@ -192,4 +216,4 @@ gulp.task('default', ['build', 'browser-sync'], function() {
.on('change', function(event) {
logFileChange(event);
});
});
});
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"gulp-if": "^2.0.0",
"gulp-load-plugins": "^1.1.0",
"gulp-minify-css": "^1.2.2",
"gulp-phpcbf": "latest",
"gulp-phpcs": "^1.0.0",
"gulp-sass": "^2.1.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-uglify": "^1.5.1",
Expand All @@ -47,8 +49,10 @@
"scripts": {
"build": "gulp build",
"package": "gulp package",
"phpcs": "gulp phpcs",
"phpcbf": "gulp phpcbf",
"postinstall": "bower install && gulp build",
"production": "gulp --production",
"watch": "gulp"
}
}
}