Skip to content

Commit b1ad6e8

Browse files
committed
Merge pull request #100 from WordPoints/develop
2.2.0
2 parents 6bcc518 + 8c04472 commit b1ad6e8

15 files changed

+224
-4
lines changed

CHANGELOG.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55
And as you can see, we [keep a CHANGELOG](http://keepachangelog.com/).
66

7+
## [2.2.0] - 2015-10-30
8+
### Added
9+
- `WordPoints.PHP.RequiredParentMethodCall` sniff to flag missing calls to
10+
`parent::setUp()`, etc. (#75).
11+
- `WordPoints_Modules::register()` and `WordPoints_Widget::get_field_name()`
12+
to the l10n validator ignores (#85 and #92).
13+
- `do_meta_boxes()`, `settings_errors()` and `$this->display_content` to the list of
14+
output functions in the `WordPoints.PHP.MissingEcho` sniff (#91).
15+
- `esc_sql()` to the list of disallowed functions in the
16+
`WordPoints.PHP.DisallowedFunctions` sniff (#90).
17+
- Exclusion for test files for the `WordPress.WP.PreparedSQL` sniff (#84).
18+
- WordPress 4.3 to the Travis CI config for PHPUnit tests.
19+
- `esc_js()` to the list of disallowed functions in the
20+
`WordPoints.PHP.DisallowedFunctions` sniff (#98).
21+
22+
### Changed
23+
- `makepot` to inclue fuzzy strings in `.mo` files (#83).
24+
- Default PHPCS version to `4122da6604e2967c257d6c81151122d08cae60cf` (#95).
25+
- Default WPCS version to `a54499411fb9ca55a35fc7003422868cdd072ef2` (#96).
26+
27+
### Removed
28+
- `boss` from jshint config (#93).
29+
730
## [2.1.1] - 2015-07-22
831
### Changed
932
- WPCS version to latest commit on `develop` (0.6.0).
@@ -132,3 +155,21 @@ automatically installed if there is a config file for it. #23
132155
## [1.0.0] - 2015-02-17
133156
### Added
134157
- Initial code.
158+
159+
[Unreleased]: https://github.com/WordPoints/dev-lib/compare/master...develop
160+
[2.2.0]: https://github.com/WordPoints/dev-lib/compare/2.1.1...2.2.0
161+
[2.1.1]: https://github.com/WordPoints/dev-lib/compare/2.1.0...2.1.1
162+
[2.1.0]: https://github.com/WordPoints/dev-lib/compare/2.0.4...2.1.0
163+
[2.0.4]: https://github.com/WordPoints/dev-lib/compare/2.0.3...2.0.4
164+
[2.0.3]: https://github.com/WordPoints/dev-lib/compare/2.0.2...2.0.3
165+
[2.0.2]: https://github.com/WordPoints/dev-lib/compare/2.0.1...2.0.2
166+
[2.0.1]: https://github.com/WordPoints/dev-lib/compare/2.0.0...2.0.1
167+
[2.0.0]: https://github.com/WordPoints/dev-lib/compare/1.3.3...2.0.0
168+
[1.3.3]: https://github.com/WordPoints/dev-lib/compare/1.3.2...1.3.3
169+
[1.3.2]: https://github.com/WordPoints/dev-lib/compare/1.3.1...1.3.2
170+
[1.3.1]: https://github.com/WordPoints/dev-lib/compare/1.3.0...1.3.1
171+
[1.3.0]: https://github.com/WordPoints/dev-lib/compare/1.2.0...1.3.0
172+
[1.2.0]: https://github.com/WordPoints/dev-lib/compare/1.1.0...1.2.0
173+
[1.1.0]: https://github.com/WordPoints/dev-lib/compare/1.0.0...1.1.0
174+
[1.0.0]: https://github.com/WordPoints/dev-lib/compare/...1.0.0
175+

bin/env.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export CODESNIFF_PATH
1515
export DO_PHPCS=$(if [ -e phpcs.ruleset.xml ]; then echo 1; else echo 0; fi)
1616
export PHPCS_DIR=/tmp/phpcs
1717
export PHPCS_GITHUB_SRC=squizlabs/PHP_CodeSniffer
18-
export PHPCS_GIT_TREE=master
18+
export PHPCS_GIT_TREE=4122da6604e2967c257d6c81151122d08cae60cf
1919

2020
# WPCS
2121
export WPCS_DIR=/tmp/wpcs
2222
export WPCS_GITHUB_SRC=WordPress-Coding-Standards/WordPress-Coding-Standards
23-
export WPCS_GIT_TREE=a9a032ef2ce775bd5c45b52db98fda45efa87148
23+
export WPCS_GIT_TREE=a54499411fb9ca55a35fc7003422868cdd072ef2
2424
export WPCS_STANDARD=$(if [ -e phpcs.ruleset.xml ]; then echo phpcs.ruleset.xml; else echo WordPress; fi)
2525

2626
# WP L10n Validator

bin/makepot.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ php "$DEV_LIB_PATH/i18n/makepot.php" "$project_type" src "src/languages/$text_do
1414
echo 'Updating po/mo files (if any)'
1515
for file in $(find "src/languages" -name '*.po' -type f); do
1616
msgmerge --backup=off --update "$file" "src/languages/$text_domain.pot"
17-
msgfmt -o "${file%po}mo" "$file"
17+
msgfmt --use-fuzzy -o "${file%po}mo" "$file"
1818
done
1919

2020
echo Done.

jshint/.jshintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"boss": true,
32
"curly": true,
43
"eqeqeq": true,
54
"eqnull": true,

l10n-validator/wordpoints.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
'WordPoints_Installables::install' => true,
4545
'WordPoints_Installables::register' => true,
4646
'WordPoints_Installables::uninstall' => true,
47+
'WordPoints_Modules::register' => true,
4748
'WordPoints_Points_Hook::_set' => true,
4849
'WordPoints_Points_Hook::get_description' => true,
4950
'WordPoints_Points_Hook::get_field_id' => true,
@@ -82,6 +83,7 @@
8283
'WordPoints_Un_Installer_Base::uninstall_metadata' => true,
8384
'WordPoints_Un_Installer_Base::uninstall_' => true,
8485
'WordPoints_Un_Installer_Base::update_' => true,
86+
'WordPoints_Widget::get_field_name' => true,
8587

8688
// Instance methods.
8789
'$hook->get_description' => true,

phpcs/WordPoints/Sniffs/PHP/DisallowedFunctionsSniff.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ class WordPoints_Sniffs_PHP_DisallowedFunctionsSniff
2323
public function getGroups() {
2424

2525
return array(
26+
'esc_js' => array(
27+
'type' => 'error',
28+
'message' => 'Do not use esc_js(), use wp_json_encode() instead.',
29+
'functions' => array( 'esc_js' ),
30+
),
31+
'esc_sql' => array(
32+
'type' => 'error',
33+
'message' => 'Do not use esc_sql(), use $wpdb->prepare() instead.',
34+
'functions' => array( 'esc_sql' ),
35+
),
2636
'unserialize' => array(
2737
'type' => 'error',
2838
'message' => 'Do not unserialize untrusted data.',

phpcs/WordPoints/Sniffs/PHP/MissingEchoSniff.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ class WordPoints_Sniffs_PHP_MissingEchoSniff implements PHP_CodeSniffer_Sniff {
4444
'$wp_list_table->views',
4545
'checked',
4646
'disabled',
47+
'do_meta_boxes',
4748
'esc_attr_e',
4849
'esc_html_e',
4950
'selected',
51+
'settings_errors',
5052
'submit_button',
5153
'wp_nonce_field',
5254

@@ -55,6 +57,7 @@ class WordPoints_Sniffs_PHP_MissingEchoSniff implements PHP_CodeSniffer_Sniff {
5557
'$hook->form_callback',
5658
'$hook->the_field_id',
5759
'$hook->the_field_name',
60+
'$this->display_content',
5861
'$this->the_field_id',
5962
'$this->the_field_name',
6063
'wordpoints_admin_show_tabs',
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
/**
4+
* Sniff for methods that are required to call the parent method.
5+
*
6+
* @package WordPoints_Dev_Lib\PHPCS
7+
* @since 2.2.0
8+
*/
9+
10+
/**
11+
* Warns about methods not calling the parent method when they are supposed to.
12+
*
13+
* @since 2.2.0
14+
*/
15+
class WordPoints_Sniffs_PHP_RequiredParentMethodCallSniff implements PHP_CodeSniffer_Sniff {
16+
17+
/**
18+
* A list of methods whose parents are required to be called.
19+
*
20+
* @since 2.2.0
21+
*
22+
* @var string[]
23+
*/
24+
public $methods = array(
25+
'setUp' => true,
26+
'tearDown' => true,
27+
'setUpBeforeClass' => true,
28+
'tearDownAfterClass' => true,
29+
);
30+
31+
/**
32+
* @since 2.2.0
33+
*/
34+
public function register() {
35+
return array( T_FUNCTION );
36+
}
37+
38+
/**
39+
* @since 2.0.0
40+
*/
41+
public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {
42+
43+
$tokens = $phpcsFile->getTokens();
44+
$token = $tokens[ $stackPtr ];
45+
46+
// Skip function without body.
47+
if ( isset( $token['scope_opener'] ) === false ) {
48+
return;
49+
}
50+
51+
// Get function name.
52+
$methodName = $phpcsFile->getDeclarationName( $stackPtr );
53+
54+
// If this method isn't required to call it's parent, bail out.
55+
if ( ! isset( $this->methods[ $methodName ] ) ) {
56+
return;
57+
}
58+
59+
$next = ++$token['scope_opener'];
60+
$end = --$token['scope_closer'];
61+
62+
for ( ; $next <= $end; ++$next ) {
63+
64+
if ( T_PARENT !== $tokens[ $next ]['code'] ) {
65+
continue;
66+
}
67+
68+
// Find next non empty token index, should be double colon.
69+
$next = $phpcsFile->findNext(
70+
PHP_CodeSniffer_Tokens::$emptyTokens
71+
, $next + 1
72+
, null
73+
, true
74+
);
75+
76+
// Skip for invalid code.
77+
if ( false === $next || T_DOUBLE_COLON !== $tokens[ $next ]['code'] ) {
78+
continue;
79+
}
80+
81+
// Find next non empty token index, should be the function name.
82+
$next = $phpcsFile->findNext(
83+
PHP_CodeSniffer_Tokens::$emptyTokens
84+
, $next + 1
85+
, null
86+
, true
87+
);
88+
89+
// If this is the method we are looking for, we're done.
90+
if ( false !== $next && $tokens[ $next ]['content'] === $methodName ) {
91+
return;
92+
}
93+
}
94+
95+
// We didn't find a call to the parent method.
96+
$phpcsFile->addError(
97+
'Missing call to parent::%s()'
98+
, $stackPtr
99+
, 'Missing'
100+
, $methodName
101+
);
102+
}
103+
}
104+
105+
// EOF

phpcs/WordPoints/Tests/PHP/DisallowedFunctionsUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ wp_remote_get( $args ); // Bad
1212
wp_safe_remote_get( $args ); // OK
1313

1414
$body = wp_remote_retrieve_body( $response ); // OK
15+
16+
esc_sql( $data ); // Bad
17+
18+
esc_js( $data ); // Bad

phpcs/WordPoints/Tests/PHP/DisallowedFunctionsUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public function getErrorList() {
2525
6 => 1,
2626
9 => 1,
2727
11 => 1,
28+
16 => 1,
29+
18 => 1,
2830
);
2931
}
3032

0 commit comments

Comments
 (0)