Skip to content

Commit

Permalink
Release version 0.2.1
Browse files Browse the repository at this point in the history
Release version 0.2.1
  • Loading branch information
dingo-d committed Nov 17, 2019
2 parents 1141d45 + 9244d3e commit 462e590
Show file tree
Hide file tree
Showing 35 changed files with 216 additions and 191 deletions.
4 changes: 4 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<exclude name="WordPress.NamingConventions.ValidVariableName"/>
<exclude name="WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition"/>
<exclude name="WordPress.WP.AlternativeFunctions"/>
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
</rule>

<rule ref="WordPress-Docs"/>
Expand All @@ -30,6 +31,9 @@
</properties>
</rule>

<!-- Enforce array short syntax. -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

<rule ref="PSR2.Methods.FunctionClosingBrace"/>

<!-- Check code for cross-version PHP compatibility. -->
Expand Down
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ php:

env:
# Highest supported PHPCS + WPCS versions.
- PHPCS_BRANCH="dev-master" WPCS_BRANCH="dev-master" LINT=1
- PHPCS_BRANCH="dev-master" WPCS_BRANCH="dev-develop" LINT=1
# Lowest supported PHPCS + WPCS versions.
- PHPCS_BRANCH="3.3.1" WPCS_BRANCH="2.1.0"

Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
php: 7.2
env: PHPCS_BRANCH="dev-master" WPCS_BRANCH="2.1.0" LINT=1
- php: 7.2
env: PHPCS_BRANCH="3.3.1" WPCS_BRANCH="dev-master"
env: PHPCS_BRANCH="3.3.1" WPCS_BRANCH="dev-develop"

allow_failures:
# Allow failures for unstable builds.
Expand All @@ -65,6 +65,14 @@ jobs:
before_install:
# Speed up build time by disabling Xdebug.
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'

# On stable PHPCS versions, allow for PHP deprecation notices.
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
- |
if [[ "$TRAVIS_BUILD_STAGE_NAME" != "Sniff" && $PHPCS_BRANCH != "dev-master" && $WPCS_BRANCH != "dev-develop" ]]; then
echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
fi
- export XMLLINT_INDENT=" "
- composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} wp-coding-standards/wpcs:${WPCS_BRANCH} --no-update --no-suggest --no-scripts
- |
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a

_No documentation available about unreleased changes as of yet._

## [0.2.1] - 2019-11-17

### Changed

- Added new `$in_list` parameter to the `PrefixAllGlobalsSniff::process_variable_assignment()` method, so that the method is compatible with the upstream WPCS method (changed in WPCS 2.2.0).
- Updated the minimum version requirement for the WordPress Coding Standards dependency to version 2.2.0.
- Replaced the deprecated `WordPress.WP.TimezoneChange` with `WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set`
- Enforce the array short syntax when writing sniffs.
- Travis: Minor build script tweaks.

## [0.2.0] - 2019-07-17

### Added
Expand Down Expand Up @@ -99,5 +109,6 @@ _No documentation available about unreleased changes as of yet._
- `WordPress.WP.TimezoneChange`: themes should never touch the timezone.

[Unreleased]: https://github.com/WPTRT/WPThemeReview/compare/master...HEAD
[0.2.1]: https://github.com/WPTRT/WPThemeReview/compare/0.2.0...0.2.1
[0.2.0]: https://github.com/WPTRT/WPThemeReview/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/WPTRT/WPThemeReview/compare/1dabb9876caf78209849a01381c0b863ce583d07...0.1.0
6 changes: 3 additions & 3 deletions WPThemeReview/Sniffs/CoreFunctionality/FileIncludeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class FileIncludeSniff implements Sniff {
*
* @var array
*/
protected $file_whitelist = array(
protected $file_whitelist = [
'functions.php' => true,
);
];

/**
* Returns an array of tokens this test wants to listen for.
Expand Down Expand Up @@ -61,7 +61,7 @@ public function process( File $phpcsFile, $stackPtr ) {
'Check that %s is not being used to load template files. "get_template_part()" should be used to load template files.',
$stackPtr,
'FileIncludeFound',
array( $token['content'] )
[ $token['content'] ]
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class NoDeregisterCoreScriptSniff extends AbstractFunctionParameterSniff {
*
* @var array
*/
protected $target_functions = array(
'wp_deregister_script' => array(
protected $target_functions = [
'wp_deregister_script' => [
'jcrop' => true,
'swfobject' => true,
'swfupload' => true,
Expand Down Expand Up @@ -140,8 +140,8 @@ class NoDeregisterCoreScriptSniff extends AbstractFunctionParameterSniff {
'underscore' => true,
'backbone' => true,
'imagesloaded' => true,
),
);
],
];

/**
* Process the parameters of a matched function.
Expand Down Expand Up @@ -170,7 +170,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
);

if ( isset( $this->target_functions[ $matched_content ][ $matched_parameter ] ) ) {
$this->throw_prohibited_error( $first_param_token, array( $matched_parameter ) );
$this->throw_prohibited_error( $first_param_token, [ $matched_parameter ] );
return;
}

Expand All @@ -193,12 +193,12 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
}

if ( isset( $this->target_functions[ $matched_content ][ $text ] ) ) {
$this->throw_prohibited_error( $first_param_token, array( $text ) );
$this->throw_prohibited_error( $first_param_token, [ $text ] );
return;
}

if ( true === $found_variable_token ) {
$this->throw_variable_handle_warning( $first_param_token, array( $matched_content, $matched_parameter ) );
$this->throw_variable_handle_warning( $first_param_token, [ $matched_content, $matched_parameter ] );
}
}

Expand All @@ -208,7 +208,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
* @param int $stackPtr The position of the first non-empty parameter token in the stack.
* @param array $data Optional input for the data replacements.
*/
public function throw_prohibited_error( $stackPtr, $data = array() ) {
public function throw_prohibited_error( $stackPtr, $data = [] ) {
$this->phpcsFile->addError(
'Deregistering core script "%s" is prohibited.',
$stackPtr,
Expand All @@ -223,7 +223,7 @@ public function throw_prohibited_error( $stackPtr, $data = array() ) {
* @param int $stackPtr The position of the first non-empty parameter token in the stack.
* @param array $data Optional input for the data replacements.
*/
public function throw_variable_handle_warning( $stackPtr, $data = array() ) {
public function throw_variable_handle_warning( $stackPtr, $data = [] ) {
$this->phpcsFile->addWarning(
'Deregistering core scripts is prohibited. A variable script handle was found. Inspection of the %s() call needed. Found: %s',
$stackPtr,
Expand Down
14 changes: 7 additions & 7 deletions WPThemeReview/Sniffs/CoreFunctionality/NoFaviconSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ class NoFaviconSniff implements Sniff {
*
* @var array
*/
protected $attribute_blacklist = array(
'rel' => array(
protected $attribute_blacklist = [
'rel' => [
'icon',
'shortcut icon',
'bookmark icon',
'apple-touch-icon',
'apple-touch-icon-precomposed',
),
'name' => array(
],
'name' => [
'msapplication-config',
'msapplication-TileImage',
'msapplication-square70x70logo',
'msapplication-square150x150logo',
'msapplication-wide310x150logo',
'msapplication-square310x310logo',
),
);
],
];

/**
* The regex to catch the blacklisted attributes.
Expand All @@ -77,7 +77,7 @@ class NoFaviconSniff implements Sniff {
*/
public function register() {
// Build the regex to be used only once.
$regex_parts = array();
$regex_parts = [];

foreach ( $this->attribute_blacklist as $key => $values ) {
$values = array_map( 'preg_quote', $values, array_fill( 0, count( $values ), '`' ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,16 @@ class PrefixAllGlobalsSniff extends WPCSPrefixAllGlobalsSniff {
* local to that function.
*
* @since 0.2.0
* @since 0.2.1 Added $in_list parameter as introduced in WPCS 2.2.0.
*
* @param int $stackPtr The position of the current token in the stack.
* @param int $stackPtr The position of the current token in the stack.
* @param bool $in_list Whether or not this is a variable in a list assignment.
* Defaults to false.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
*/
protected function process_variable_assignment( $stackPtr ) {
protected function process_variable_assignment( $stackPtr, $in_list = false ) {

// Usage of `strip_quotes` is to ensure `stdin_path` passed by IDEs does not include quotes.
$file = $this->strip_quotes( $this->phpcsFile->getFileName() );
Expand All @@ -161,7 +164,7 @@ protected function process_variable_assignment( $stackPtr ) {
}

// Not a typical template file name, defer to the prefix checking in the parent sniff.
return parent::process_variable_assignment( $stackPtr );
return parent::process_variable_assignment( $stackPtr, $in_list );
}

/**
Expand Down
28 changes: 14 additions & 14 deletions WPThemeReview/Sniffs/PluginTerritory/AdminBarRemovalSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AdminBarRemovalSniff extends AbstractFunctionParameterSniff {
*
* @var array
*/
public $supportedTokenizers = array( 'PHP', 'CSS' );
public $supportedTokenizers = [ 'PHP', 'CSS' ];

/**
* Whether or not the sniff only checks for removal of the admin bar
Expand All @@ -58,10 +58,10 @@ class AdminBarRemovalSniff extends AbstractFunctionParameterSniff {
*
* @var array
*/
protected $target_functions = array(
protected $target_functions = [
'show_admin_bar' => true,
'add_filter' => true,
);
];

/**
* CSS properties this sniff is looking for.
Expand All @@ -70,20 +70,20 @@ class AdminBarRemovalSniff extends AbstractFunctionParameterSniff {
*
* @var array
*/
protected $target_css_properties = array(
'visibility' => array(
protected $target_css_properties = [
'visibility' => [
'type' => '!=',
'value' => 'hidden',
),
'display' => array(
],
'display' => [
'type' => '!=',
'value' => 'none',
),
'opacity' => array(
],
'opacity' => [
'type' => '>',
'value' => 0.3,
),
);
],
];

/**
* CSS selectors this sniff is looking for.
Expand All @@ -92,10 +92,10 @@ class AdminBarRemovalSniff extends AbstractFunctionParameterSniff {
*
* @var array
*/
protected $target_css_selectors = array(
protected $target_css_selectors = [
'.show-admin-bar',
'#wpadminbar',
);
];

/**
* Regex template for use with the CSS selectors in combination with PHP text strings.
Expand Down Expand Up @@ -369,7 +369,7 @@ protected function process_css_style( $stackPtr ) {

if ( true === $this->remove_only ) {
// Check the value of the CSS property.
$valuePtr = $this->phpcsFile->findNext( array( \T_COLON, \T_WHITESPACE ), ( $stackPtr + 1 ), null, true );
$valuePtr = $this->phpcsFile->findNext( [ \T_COLON, \T_WHITESPACE ], ( $stackPtr + 1 ), null, true );
$value = $this->tokens[ $valuePtr ]['content'];
$valid = $this->validate_css_property_value( $value, $css_property['type'], $css_property['value'] );
if ( true === $valid ) {
Expand Down
38 changes: 19 additions & 19 deletions WPThemeReview/Sniffs/PluginTerritory/ForbiddenFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,51 @@ class ForbiddenFunctionsSniff extends AbstractFunctionRestrictionsSniff {
/**
* Groups of functions to restrict.
*
* Example: groups => array(
* 'lambda' => array(
* Example: groups => [
* 'lambda' => [
* 'type' => 'error' | 'warning',
* 'message' => 'Use anonymous functions instead please!',
* 'functions' => array( 'file_get_contents', 'create_function' ),
* )
* )
* 'functions' => [ 'file_get_contents', 'create_function' ],
* ]
* ]
*
* @return array
*/
public function getGroups() {
return array(
'plugin-territory' => array(
return [
'plugin-territory' => [
'type' => 'error',
'message' => 'Function %s() is not allowed because it is plugin territory.',
'functions' => array(
'functions' => [
'register_post_type',
'register_taxonomy',
'add_shortcode',
'register_taxonomy_for_object_type',
'flush_rewrite_rules',
),
),
],
],

'editor-blocks' => array(
'editor-blocks' => [
'type' => 'error',
'message' => 'Registering and deregistering editor blocks should be done in a plugin, not in a theme. Found %s().',
'functions' => array(
'functions' => [
'register_block_*',
'unregister_block_*',
),
),
],
],

'cron-functionality' => array(
'cron-functionality' => [
'type' => 'error',
'message' => 'Themes should not be running regular (Cron) tasks. Found %s().',
'functions' => array(
'functions' => [
'wp_clear_scheduled_hook',
'wp_cron',
'wp_reschedule_event',
'wp_schedule_*',
'wp_unschedule_*',
),
),
);
],
],
];
}

}

0 comments on commit 462e590

Please sign in to comment.