Slim down the travis script, add js checks and fix js errors thrown up.

What it will now do:
- Lint the php files against relevant PHP versions.
- Lint the js files once - the result won't change across PHP versions.
- Check against WPCS once - the result won't change across PHP versions.

What I have changed:
- Added linting against PHP 7 and HHVM, with HHVM being allowed to fail.
- Added js linting and style check per example from Twenty Sixteen.
- Moved to the faster container based environment for running travis.
- Script will no longer pull in PHPCS, WPCS and the JS linters in every build. Now they will only be pulled in when needed.
- Limited the clone depth for quicker cloning of external repositories.
- Removed the pulling in of WP and running builds against different WP versions as this wasn't used at all in the actual test scripts.
This commit is contained in:
jrfnl 2015-12-13 15:03:43 +01:00
parent e57d8c38b4
commit b8d776c59c
6 changed files with 102 additions and 83 deletions

7
.jscsrc Normal file
View File

@ -0,0 +1,7 @@
{
"preset": "wordpress",
"fileExtensions": [ ".js" ],
"excludeFiles": [
"js/skip-link-focus-fix.js"
]
}

2
.jshintignore Normal file
View File

@ -0,0 +1,2 @@
js/skip-link-focus-fix.js
**.min.js

26
.jshintrc Normal file
View File

@ -0,0 +1,26 @@
{
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"es3": true,
"expr": true,
"immed": true,
"noarg": true,
"nonbsp": true,
"onevar": true,
"quotmark": "single",
"trailing": true,
"undef": true,
"unused": true,
"browser": true,
"globals": {
"_": false,
"Backbone": false,
"jQuery": false,
"JSON": false,
"wp": false
}
}

View File

@ -4,47 +4,40 @@
# For use with the Underscores WordPress theme. # For use with the Underscores WordPress theme.
# @link https://github.com/Automattic/_s # @link https://github.com/Automattic/_s
# Ditch sudo and use containers.
# @link http://docs.travis-ci.com/user/migrating-from-legacy/#Why-migrate-to-container-based-infrastructure%3F
# @link http://docs.travis-ci.com/user/workers/container-based-infrastructure/#Routing-your-build-to-container-based-infrastructure
sudo: false
# Declare project language. # Declare project language.
# @link http://about.travis-ci.org/docs/user/languages/php/ # @link http://about.travis-ci.org/docs/user/languages/php/
language: php language: php
# Declare versions of PHP to use. Use one decimal max. # Declare versions of PHP to use. Use one decimal max.
php:
# aliased to a recent 5.5.x version
- "5.5"
# aliased to a recent 5.4.x version
- "5.4"
# aliased to a recent 5.3.x version
- "5.3"
# Current $required_php_version for WordPress: 5.2.4
- "5.2"
# Declare which versions of WordPress to test against.
# Also declare whether or not to test in Multisite.
env:
# Trunk
# @link https://github.com/WordPress/WordPress
- WP_VERSION=master WP_MULTISITE=0
- WP_VERSION=master WP_MULTISITE=1
# WordPress 4.2
# @link https://github.com/WordPress/WordPress/tree/4.2-branch
- WP_VERSION=4.2 WP_MULTISITE=0
- WP_VERSION=4.2 WP_MULTISITE=1
# WordPress 4.1
# @link https://github.com/WordPress/WordPress/tree/4.1-branch
- WP_VERSION=4.1 WP_MULTISITE=0
- WP_VERSION=4.1 WP_MULTISITE=1
# Declare 5.6 beta in test matrix.
# @link https://buddypress.trac.wordpress.org/ticket/5620
# @link http://docs.travis-ci.com/user/build-configuration/ # @link http://docs.travis-ci.com/user/build-configuration/
matrix: matrix:
include: fast_finish: true
- php: 5.6
env: WP_VERSION=master include:
allow_failures: # Current $required_php_version for WordPress: 5.2.4
- php: 5.6 # aliased to 5.2.17
fast_finish: true - php: '5.2'
# aliased to 5.3.29
- php: '5.3'
# aliased to a recent 5.4.x version
- php: '5.4'
# aliased to a recent 5.5.x version
- php: '5.5'
env: SNIFF=1
# aliased to a recent 5.6.x version
- php: '5.6'
# aliased to a recent 7.x version
- php: '7.0'
# aliased to a recent hhvm version
- php: 'hhvm'
allow_failures:
- php: 'hhvm'
# Use this to prepare the system to install prerequisites or dependencies. # Use this to prepare the system to install prerequisites or dependencies.
# e.g. sudo apt-get update. # e.g. sudo apt-get update.
@ -55,57 +48,46 @@ matrix:
# e.g. copy database configurations, environment variables, etc. # e.g. copy database configurations, environment variables, etc.
# Failures in this section will result in build status 'errored'. # Failures in this section will result in build status 'errored'.
before_script: before_script:
# Set up WordPress installation. - export PHPCS_DIR=/tmp/phpcs
- export WP_DEVELOP_DIR=/tmp/wordpress/ - export WPCS_DIR=/tmp/wpcs
- mkdir -p $WP_DEVELOP_DIR # Install CodeSniffer for WordPress Coding Standards checks.
# Use the Git mirror of WordPress. - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git $PHPCS_DIR; fi
- git clone --depth=1 --branch="$WP_VERSION" git://develop.git.wordpress.org/ $WP_DEVELOP_DIR # Install WordPress Coding Standards.
# Set up theme information. - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $WPCS_DIR; fi
- theme_slug=$(basename $(pwd)) # Set install path for WordPress Coding Standards.
- theme_dir=$WP_DEVELOP_DIR/src/wp-content/themes/$theme_slug # @link https://github.com/squizlabs/PHP_CodeSniffer/blob/4237c2fc98cc838730b76ee9cee316f99286a2a7/CodeSniffer.php#L1941
- cd .. - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs --config-set installed_paths $WPCS_DIR; fi
- mv $theme_slug $theme_dir # After CodeSniffer install you should refresh your path.
# Set up WordPress configuration. - if [[ "$SNIFF" == "1" ]]; then phpenv rehash; fi
- cd $WP_DEVELOP_DIR # Install JSCS: JavaScript Code Style checker
- echo $WP_DEVELOP_DIR # @link http://jscs.info/
- cp wp-tests-config-sample.php wp-tests-config.php - if [[ "$SNIFF" == "1" ]]; then npm install -g jscs; fi
- sed -i "s/youremptytestdbnamehere/wordpress_test/" wp-tests-config.php # Install JSHint, a JavaScript Code Quality Tool
- sed -i "s/yourusernamehere/root/" wp-tests-config.php # @link http://jshint.com/docs/
- sed -i "s/yourpasswordhere//" wp-tests-config.php - if [[ "$SNIFF" == "1" ]]; then npm install -g jshint; fi
# Create WordPress database.
- mysql -e 'CREATE DATABASE wordpress_test;' -uroot
# Install CodeSniffer for WordPress Coding Standards checks.
- git clone https://github.com/squizlabs/PHP_CodeSniffer.git php-codesniffer
# Install WordPress Coding Standards.
- git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wordpress-coding-standards
# Hop into CodeSniffer directory.
- cd php-codesniffer
# Set install path for WordPress Coding Standards.
# @link https://github.com/squizlabs/PHP_CodeSniffer/blob/4237c2fc98cc838730b76ee9cee316f99286a2a7/CodeSniffer.php#L1941
- scripts/phpcs --config-set installed_paths ../wordpress-coding-standards
# Hop into themes directory.
- cd $theme_dir
# After CodeSniffer install you should refresh your path.
- phpenv rehash
# Run test script commands. # Run test script commands.
# Default is specific to project language. # Default is specific to project language.
# All commands must exit with code 0 on success. Anything else is considered failure. # All commands must exit with code 0 on success. Anything else is considered failure.
script: script:
# Search for PHP syntax errors. # Search for PHP syntax errors.
- find . \( -name '*.php' \) -exec php -lf {} \; - find -L . -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
# WordPress Coding Standards # Run the theme through JSHint.
# @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards - if [[ "$SNIFF" == "1" ]]; then jshint .; fi
# @link http://pear.php.net/package/PHP_CodeSniffer/ # Run the theme through JavaScript Code Style checker.
# -p flag: Show progress of the run. - if [[ "$SNIFF" == "1" ]]; then jscs .; fi
# -s flag: Show sniff codes in all reports. # WordPress Coding Standards.
# -v flag: Print verbose output. # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
# -n flag: Do not print warnings. (shortcut for --warning-severity=0) # @link http://pear.php.net/package/PHP_CodeSniffer/
# --standard: Use WordPress as the standard. # -p flag: Show progress of the run.
# --extensions: Only sniff PHP files. # -s flag: Show sniff codes in all reports.
- $WP_DEVELOP_DIR/php-codesniffer/scripts/phpcs -p -s -v -n . --standard=./codesniffer.ruleset.xml --extensions=php # -v flag: Print verbose output.
# -n flag: Do not print warnings. (shortcut for --warning-severity=0)
# --standard: Use WordPress as the standard.
# --extensions: Only sniff PHP files.
- if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs -p -s -v -n . --standard=./codesniffer.ruleset.xml --extensions=php; fi
# Receive notifications for build results. # Receive notifications for build results.
# @link http://docs.travis-ci.com/user/notifications/#Email-notifications # @link http://docs.travis-ci.com/user/notifications/#Email-notifications
notifications: notifications:
email: false email: false

View File

@ -1,5 +1,5 @@
/** /**
* customizer.js * File customizer.js.
* *
* Theme Customizer enhancements for a better user experience. * Theme Customizer enhancements for a better user experience.
* *
@ -7,6 +7,7 @@
*/ */
( function( $ ) { ( function( $ ) {
// Site title and description. // Site title and description.
wp.customize( 'blogname', function( value ) { wp.customize( 'blogname', function( value ) {
value.bind( function( to ) { value.bind( function( to ) {
@ -18,6 +19,7 @@
$( '.site-description' ).text( to ); $( '.site-description' ).text( to );
} ); } );
} ); } );
// Header text color. // Header text color.
wp.customize( 'header_textcolor', function( value ) { wp.customize( 'header_textcolor', function( value ) {
value.bind( function( to ) { value.bind( function( to ) {

View File

@ -1,11 +1,11 @@
/** /**
* navigation.js * File navigation.js.
* *
* Handles toggling the navigation menu for small screens and enables tab * Handles toggling the navigation menu for small screens and enables tab
* support for dropdown menus. * support for dropdown menus.
*/ */
( function() { ( function() {
var container, button, menu, links, subMenus; var container, button, menu, links, subMenus, i, len;
container = document.getElementById( 'site-navigation' ); container = document.getElementById( 'site-navigation' );
if ( ! container ) { if ( ! container ) {
@ -47,7 +47,7 @@
subMenus = menu.getElementsByTagName( 'ul' ); subMenus = menu.getElementsByTagName( 'ul' );
// Set menu items with submenus to aria-haspopup="true". // Set menu items with submenus to aria-haspopup="true".
for ( var i = 0, len = subMenus.length; i < len; i++ ) { for ( i = 0, len = subMenus.length; i < len; i++ ) {
subMenus[i].parentNode.setAttribute( 'aria-haspopup', 'true' ); subMenus[i].parentNode.setAttribute( 'aria-haspopup', 'true' );
} }