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

Add code quality checking via phpcs, eslint, jscs, and jshint #795

Merged
merged 7 commits into from
Nov 6, 2017
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 .eslintrc
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "dev-lib"]
path = dev-lib
url = https://github.com/xwp/wp-dev-lib.git
branch = master
1 change: 1 addition & 0 deletions .jscsrc
1 change: 1 addition & 0 deletions .jshintrc
44 changes: 28 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Tell Travis CI we're using PHP
language: php

# Opt to use Travis container-based environment.
sudo: false

# PHP version used in first build configuration.
php:
- "7.1"
Expand All @@ -26,16 +29,27 @@ dist: precise
# along with 2 versions of WordPress (which would build 8 configs otherwise).
# This takes half as long to run while still providing adequate coverage.

notifications:
email:
on_success: never
on_failure: change

cache:
directories:
- node_modules
- vendor
- $HOME/phpunit-bin

matrix:
include:
- php: "5.2"
env: WP_VERSION=latest
env: WP_VERSION=latest DEV_LIB_SKIP=phpcs
- php: "5.2"
env: WP_VERSION=4.7
env: WP_VERSION=4.7 DEV_LIB_SKIP=phpcs
- php: "5.3"
env: WP_VERSION=latest
env: WP_VERSION=latest DEV_LIB_SKIP=phpcs
- php: "5.3"
env: WP_VERSION=4.7
env: WP_VERSION=4.7 DEV_LIB_SKIP=phpcs
- php: "5.4"
env: WP_VERSION=latest
- php: "5.4"
Expand All @@ -48,15 +62,13 @@ matrix:
- php: "7.1"
env: WP_VERSION=4.7

before_script:
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- |
if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then
composer global require "phpunit/phpunit=5.7.*"
elif [[ ${TRAVIS_PHP_VERSION:0:3} != "5.2" ]]; then
composer global require "phpunit/phpunit=4.8.*"
fi
- phpunit --version
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION

script: phpunit
install:
- nvm install 6 && nvm use 6
- export DEV_LIB_PATH=dev-lib
- source $DEV_LIB_PATH/travis.install.sh

script:
- source $DEV_LIB_PATH/travis.script.sh

after_script:
- source $DEV_LIB_PATH/travis.after_script.sh
6 changes: 6 additions & 0 deletions amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,9 @@ function amp_redirect_old_slug_to_new_url( $link ) {

return $link;
}

// Unconditionally load code required when running unit tests.
if ( function_exists( 'tests_add_filter' ) ) {
amp_load_classes();
require_once dirname( __FILE__ ) . '/tests/stubs.php';
}
1 change: 1 addition & 0 deletions dev-lib
Submodule dev-lib added at 52874e
3 changes: 2 additions & 1 deletion includes/actions/class-amp-paired-post-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public static function add_analytics_data( $amp_template ) {

foreach ( $analytics_entries as $id => $analytics_entry ) {
if ( ! isset( $analytics_entry['type'], $analytics_entry['attributes'], $analytics_entry['config_data'] ) ) {
_doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'Analytics entry for %s is missing one of the following keys: `type`, `attributes`, or `config_data` (array keys: %s)', 'amp' ), esc_html( $id ), esc_html( implode( ', ', array_keys( $analytics_entry ) ) ) ), '0.3.2' );
/* translators: %1$s is analytics entry ID, %2$s is actual entry keys. */
_doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'Analytics entry for %1$s is missing one of the following keys: `type`, `attributes`, or `config_data` (array keys: %2$s)', 'amp' ), esc_html( $id ), esc_html( implode( ', ', array_keys( $analytics_entry ) ) ) ), '0.3.2' );
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion includes/class-amp-post-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ private function verify_and_include( $file, $template_type ) {

$file = apply_filters( 'amp_post_template_file', $file, $template_type, $this->post );
if ( ! $this->is_valid_template( $file ) ) {
_doing_it_wrong( __METHOD__, sprintf( esc_html__( 'Path validation for template (%s) failed. Path cannot traverse and must be located in `%s`.', 'amp' ), esc_html( $file ), 'WP_CONTENT_DIR' ), '0.1' );
/* translators: %1$s is template file, %2$s is 'WP_CONTENT_DIR' string. */
_doing_it_wrong( __METHOD__, sprintf( esc_html__( 'Path validation for template (%1$s) failed. Path cannot traverse and must be located in `%2$s`.', 'amp' ), esc_html( $file ), 'WP_CONTENT_DIR' ), '0.1' );
return;
}

Expand Down
22 changes: 22 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for AMP">

<rule ref="WordPress-Core" />
<rule ref="WordPress-Docs" />
<rule ref="WordPress-Extra" />

<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" value="amp" />
</properties>
</rule>

<arg value="s"/>
<arg name="extensions" value="php"/>
<file>.</file>

<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*/dev-lib/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
</ruleset>
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<phpunit
bootstrap="tests/bootstrap.php"
bootstrap="dev-lib/phpunit-plugin-bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
Expand Down
19 changes: 0 additions & 19 deletions tests/bootstrap.php

This file was deleted.

4 changes: 2 additions & 2 deletions wpcom/class-amp-polldaddy-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public function shortcode( $attr ) {
$url = 'https://polldaddy.com/';
if ( ! empty( $attr['poll'] ) ) {
$url .= 'poll/' . $attr['poll'] . '/';
$name = ! empty( $attr['title'] ) ? $attr['title'] : __( 'View Poll' );
$name = ! empty( $attr['title'] ) ? $attr['title'] : __( 'View Poll', 'amp' );
} elseif ( ! empty( $attr['survey'] ) ) { // Surveys and Quizzes both use attr survey
$url .= 's/' . $attr['survey'] . '/';
$name = ! empty( $attr['title'] ) ? $attr['title'] : __( 'View Survey' );
$name = ! empty( $attr['title'] ) ? $attr['title'] : __( 'View Survey', 'amp' );
} else {
return ''; // We can't embed anything useful for rating
}
Expand Down