From b8d776c59c1697917602024b06f65ee597bb60f2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 13 Dec 2015 15:03:43 +0100 Subject: [PATCH] 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. --- .jscsrc | 7 +++ .jshintignore | 2 + .jshintrc | 26 +++++++++ .travis.yml | 140 +++++++++++++++++++++-------------------------- js/customizer.js | 4 +- js/navigation.js | 6 +- 6 files changed, 102 insertions(+), 83 deletions(-) create mode 100644 .jscsrc create mode 100644 .jshintignore create mode 100644 .jshintrc diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 00000000..6425f203 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,7 @@ +{ + "preset": "wordpress", + "fileExtensions": [ ".js" ], + "excludeFiles": [ + "js/skip-link-focus-fix.js" + ] +} \ No newline at end of file diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 00000000..92af1049 --- /dev/null +++ b/.jshintignore @@ -0,0 +1,2 @@ +js/skip-link-focus-fix.js +**.min.js \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..012652e9 --- /dev/null +++ b/.jshintrc @@ -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 + } +} diff --git a/.travis.yml b/.travis.yml index 72817805..b0e38c28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,47 +4,40 @@ # For use with the Underscores WordPress theme. # @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. # @link http://about.travis-ci.org/docs/user/languages/php/ language: php # 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/ matrix: - include: - - php: 5.6 - env: WP_VERSION=master - allow_failures: - - php: 5.6 - fast_finish: true + fast_finish: true + + include: + # Current $required_php_version for WordPress: 5.2.4 + # aliased to 5.2.17 + - 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. # e.g. sudo apt-get update. @@ -55,57 +48,46 @@ matrix: # e.g. copy database configurations, environment variables, etc. # Failures in this section will result in build status 'errored'. before_script: - # Set up WordPress installation. - - export WP_DEVELOP_DIR=/tmp/wordpress/ - - mkdir -p $WP_DEVELOP_DIR - # Use the Git mirror of WordPress. - - git clone --depth=1 --branch="$WP_VERSION" git://develop.git.wordpress.org/ $WP_DEVELOP_DIR - # Set up theme information. - - theme_slug=$(basename $(pwd)) - - theme_dir=$WP_DEVELOP_DIR/src/wp-content/themes/$theme_slug - - cd .. - - mv $theme_slug $theme_dir - # Set up WordPress configuration. - - cd $WP_DEVELOP_DIR - - echo $WP_DEVELOP_DIR - - cp wp-tests-config-sample.php wp-tests-config.php - - sed -i "s/youremptytestdbnamehere/wordpress_test/" wp-tests-config.php - - sed -i "s/yourusernamehere/root/" wp-tests-config.php - - sed -i "s/yourpasswordhere//" wp-tests-config.php - # 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 + - export PHPCS_DIR=/tmp/phpcs + - export WPCS_DIR=/tmp/wpcs + # Install CodeSniffer for WordPress Coding Standards checks. + - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git $PHPCS_DIR; fi + # Install WordPress Coding Standards. + - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $WPCS_DIR; fi + # Set install path for WordPress Coding Standards. + # @link https://github.com/squizlabs/PHP_CodeSniffer/blob/4237c2fc98cc838730b76ee9cee316f99286a2a7/CodeSniffer.php#L1941 + - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs --config-set installed_paths $WPCS_DIR; fi + # After CodeSniffer install you should refresh your path. + - if [[ "$SNIFF" == "1" ]]; then phpenv rehash; fi + # Install JSCS: JavaScript Code Style checker + # @link http://jscs.info/ + - if [[ "$SNIFF" == "1" ]]; then npm install -g jscs; fi + # Install JSHint, a JavaScript Code Quality Tool + # @link http://jshint.com/docs/ + - if [[ "$SNIFF" == "1" ]]; then npm install -g jshint; fi # Run test script commands. # Default is specific to project language. # All commands must exit with code 0 on success. Anything else is considered failure. script: - # Search for PHP syntax errors. - - find . \( -name '*.php' \) -exec php -lf {} \; - # WordPress Coding Standards - # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards - # @link http://pear.php.net/package/PHP_CodeSniffer/ - # -p flag: Show progress of the run. - # -s flag: Show sniff codes in all reports. - # -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. - - $WP_DEVELOP_DIR/php-codesniffer/scripts/phpcs -p -s -v -n . --standard=./codesniffer.ruleset.xml --extensions=php + # Search for PHP syntax errors. + - find -L . -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l + # Run the theme through JSHint. + - if [[ "$SNIFF" == "1" ]]; then jshint .; fi + # Run the theme through JavaScript Code Style checker. + - if [[ "$SNIFF" == "1" ]]; then jscs .; fi + # WordPress Coding Standards. + # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + # @link http://pear.php.net/package/PHP_CodeSniffer/ + # -p flag: Show progress of the run. + # -s flag: Show sniff codes in all reports. + # -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. # @link http://docs.travis-ci.com/user/notifications/#Email-notifications notifications: - email: false + email: false diff --git a/js/customizer.js b/js/customizer.js index a97f3156..4351a330 100644 --- a/js/customizer.js +++ b/js/customizer.js @@ -1,5 +1,5 @@ /** - * customizer.js + * File customizer.js. * * Theme Customizer enhancements for a better user experience. * @@ -7,6 +7,7 @@ */ ( function( $ ) { + // Site title and description. wp.customize( 'blogname', function( value ) { value.bind( function( to ) { @@ -18,6 +19,7 @@ $( '.site-description' ).text( to ); } ); } ); + // Header text color. wp.customize( 'header_textcolor', function( value ) { value.bind( function( to ) { diff --git a/js/navigation.js b/js/navigation.js index 24c83e8d..ac3c3a84 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -1,11 +1,11 @@ /** - * navigation.js + * File navigation.js. * * Handles toggling the navigation menu for small screens and enables tab * support for dropdown menus. */ ( function() { - var container, button, menu, links, subMenus; + var container, button, menu, links, subMenus, i, len; container = document.getElementById( 'site-navigation' ); if ( ! container ) { @@ -47,7 +47,7 @@ subMenus = menu.getElementsByTagName( 'ul' ); // 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' ); }