Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
f99585e
WPCS native PHPCS ruleset: minor tweaks
jrfnl Dec 25, 2018
83f445f
Bumped suggested installer version
Rarst Jan 16, 2019
17826a7
Merge pull request #1628 from Rarst/patch-1
jrfnl Jan 16, 2019
75fc071
Merge pull request #1627 from WordPress-Coding-Standards/master
jrfnl Jan 18, 2019
97167b2
PrefixAllGlobals: prevent false negatives for autoloaded user-defined…
jrfnl Jan 22, 2019
b5acadb
ValidatedSanitizedInput: only recognize a variable as validated if th…
jrfnl Jan 23, 2019
3666bbb
Merge pull request #1633 from WordPress-Coding-Standards/feature/1632…
GaryJones Jan 23, 2019
913f9cc
Merge pull request #1634 from WordPress-Coding-Standards/feature/snif…
GaryJones Jan 23, 2019
44e5857
ValidatedSanitizedInput: add tests validating variables with array_ke…
jrfnl Jan 23, 2019
4e8d27f
Sniff::is_in_isset_or_empty(): allow for array_key_exists()
jrfnl Jan 23, 2019
5f3905a
Sniff::is_validated(): allow for array_key_exists()
jrfnl Jan 23, 2019
71ace56
Sniff::$test_class_whitelist: add newly added base test class to the …
jrfnl Jan 28, 2019
90cc817
Merge pull request #1635 from WordPress-Coding-Standards/feature/snif…
GaryJones Jan 29, 2019
126b2e3
Merge pull request #1604 from WordPress-Coding-Standards/feature/nati…
GaryJones Jan 29, 2019
12c5647
Merge pull request #1636 from WordPress-Coding-Standards/feature/new-…
GaryJones Jan 29, 2019
ca209e7
Travis: test builds against PHP 7.4
jrfnl Feb 11, 2019
4426a06
Travis: work around PHPUnit 8.x on PHP >= 7.2 images
jrfnl Feb 11, 2019
e41ea6a
Merge pull request #1643 from WordPress-Coding-Standards/feature/trav…
GaryJones Feb 11, 2019
7529b4d
WP.EnqueuedResources: bug fix
jrfnl Feb 13, 2019
b6d7052
Merge pull request #1644 from WordPress-Coding-Standards/feature/enqu…
GaryJones Feb 13, 2019
0f425fb
Remove `sudo: false`
ntwb Feb 15, 2019
7e54b98
Merge pull request #1645 from WordPress-Coding-Standards/travis-remov…
GaryJones Feb 15, 2019
76011f6
PrefixAllGlobals: improve error message clarity
jrfnl Feb 18, 2019
a392d28
Fixes #1447, adds new sniff for blacklisted ini_set directives.
NielsdeBlaauw Feb 20, 2019
bb93c38
Fixes unit-test for removed ini_set check
NielsdeBlaauw Feb 20, 2019
1650b77
Fixes codestyle
NielsdeBlaauw Feb 20, 2019
55c08d7
AlternativeFunctions: allow for php://input used by file_get_contents()
jrfnl Feb 20, 2019
1f4d912
Merge pull request #1649 from WordPress-Coding-Standards/feature/alte…
GaryJones Feb 20, 2019
d3536cf
Update WordPress/Sniffs/PHP/IniSetSniff.php
jrfnl Feb 20, 2019
18a5ccc
Update WordPress/Tests/PHP/IniSetUnitTest.php
jrfnl Feb 20, 2019
8d7593e
Adds ini_alter checks
NielsdeBlaauw Feb 20, 2019
43acdd2
Adds test marking variable option name as risky
NielsdeBlaauw Feb 20, 2019
f0b223e
Isset instead of array_key_exists
NielsdeBlaauw Feb 20, 2019
a8f3f10
Adds modular sniff name, removes use
NielsdeBlaauw Feb 20, 2019
1290ca4
Adds alternative invalid and valid values
NielsdeBlaauw Feb 20, 2019
8da3b6d
Apply suggestions from code review
jrfnl Feb 20, 2019
bc8d26a
Adds @since tags
NielsdeBlaauw Feb 20, 2019
6d54ff3
Adds sniff to WP-extra, doc fixes and unused statement removed
NielsdeBlaauw Feb 20, 2019
5e5a871
Better wording for warning message
NielsdeBlaauw Feb 22, 2019
51331e1
Consistent wording for the discouraged PHP functions
NielsdeBlaauw Feb 22, 2019
7235326
Array in target_functions had no use, replaced with true
NielsdeBlaauw Feb 22, 2019
d97fba4
Alphabetical ordering for blacklisted_options
NielsdeBlaauw Feb 22, 2019
029f02e
Better message for filter.default_flags
NielsdeBlaauw Feb 22, 2019
be87a89
Resets phpcbf on Sniff.php
NielsdeBlaauw Feb 22, 2019
9f6c94b
Adds more testcases. Option value is no longer case sensitive
NielsdeBlaauw Feb 24, 2019
d462b85
Merge pull request #1648 from NielsdeBlaauw/feature/ini-set-sniff
GaryJones Feb 24, 2019
d0717e7
Merge pull request #1647 from WordPress-Coding-Standards/feature/pref…
GaryJones Feb 25, 2019
b417db3
WP/AlternativeFunctions: allow for more input streams with file relat…
jrfnl Mar 6, 2019
95b904e
Merge pull request #1655 from WordPress-Coding-Standards/feature/295-…
GaryJones Mar 6, 2019
b1f3210
Docs: exclude the `InlineComment.SpacingAfter` errorcode
jrfnl Mar 7, 2019
d30d22f
Docs: make the inclusion of the Generic sniff slightly more specific
jrfnl Mar 7, 2019
a6dbd88
WP/AlternativeFunctions: allow calling `curl_version()`
jrfnl Mar 7, 2019
56be671
Merge pull request #1656 from WordPress-Coding-Standards/feature/1534…
GaryJones Mar 7, 2019
1ddc654
Merge pull request #1657 from WordPress-Coding-Standards/feature/docs…
GaryJones Mar 7, 2019
5f27d8e
Merge pull request #1658 from WordPress-Coding-Standards/feature/wp-a…
GaryJones Mar 7, 2019
d43381a
Sniff::is_sanitized(): make the method more code style independent
jrfnl Mar 28, 2019
2600112
GlobalVariablesOverride: implement the Sniff::is_foreach_as() method
jrfnl Mar 28, 2019
15b7ffb
Merge pull request #1664 from WordPress-Coding-Standards/feature/is_s…
GaryJones Mar 28, 2019
3ba3005
Merge pull request #1665 from WordPress-Coding-Standards/feature/glob…
GaryJones Mar 28, 2019
0a18e6b
Clean up: use array_change_key_case()
jrfnl Mar 28, 2019
d392c45
Sniff: add two new utility methods `is_class_object_call()` and `is_t…
jrfnl Mar 28, 2019
7c1b6f8
Sniff::is_in_isset_or_empty(): implement is_class_object_call() and i…
jrfnl Mar 28, 2019
e5c6ecb
Sniff::is_validated(): implement is_class_object_call() and is_token_…
jrfnl Mar 28, 2019
a55e3e0
Sniff::is_use_of_global_constant(): implement is_token_namespaced()
jrfnl Mar 28, 2019
c98ecc2
AbstractFunctionRestrictions: implement Sniff::is_class_object_call()…
jrfnl Mar 28, 2019
374691c
GlobalVariablesOverride: implement Sniff::is_class_object_call()
jrfnl Mar 28, 2019
08f4a7f
DiscouragedConstants: implement Sniff::is_token_namespaced()
jrfnl Mar 28, 2019
d3ac40a
Merge pull request #1667 from WordPress-Coding-Standards/feature/impr…
GaryJones Mar 29, 2019
7d01ff3
New utility method `Sniff::is_in_function_call()`
jrfnl Mar 28, 2019
95e3a3d
Sniff::is_in_isset_or_empty(): implement new `is_in_function_call()` …
jrfnl Mar 28, 2019
6e470de
Sniff::is_sanitized(): implement new `is_in_function_call()` method
jrfnl Mar 28, 2019
91b053f
CronInterval: implement new `Sniff::is_in_function_call()` method
jrfnl Mar 28, 2019
4e05eaa
ValidatedSanitizedInput: minor code readability improvement
jrfnl Mar 30, 2019
5cb689f
Sniff::is_comparison(): minor defensive coding tweak
jrfnl Mar 30, 2019
1b3cdfc
Sniff::is_assignment(): minor defensive coding tweak
jrfnl Mar 30, 2019
3a30b78
Merge pull request #1669 from WordPress-Coding-Standards/feature/snif…
GaryJones Mar 31, 2019
f3a603f
Merge pull request #1670 from WordPress-Coding-Standards/feature/vali…
GaryJones Mar 31, 2019
cb8cd90
Merge pull request #1671 from WordPress-Coding-Standards/feature/snif…
GaryJones Mar 31, 2019
4e143ec
Sniff::is_in_function_call(): expand the function documentation with …
jrfnl Mar 31, 2019
8fa98f6
Merge pull request #1668 from WordPress-Coding-Standards/feature/new-…
GaryJones Mar 31, 2019
c088b1b
Sniff::$unslashingSanitizingFunctions: add doubleval() and count()
jrfnl Mar 28, 2019
79287e3
Merge pull request #1666 from WordPress-Coding-Standards/feature/arra…
jrfnl Mar 31, 2019
34920c7
Update default minimum_supported_version to WP 4.8
jrfnl Mar 31, 2019
f4e645f
Merge pull request #1674 from WordPress-Coding-Standards/feature/upda…
GaryJones Mar 31, 2019
2a0f154
Merge pull request #1673 from WordPress-Coding-Standards/feature/1659…
GaryJones Apr 1, 2019
3894437
ValidatedSanitizedInput: allow for validation using key_exists()
jrfnl Mar 30, 2019
1a2b777
Merge pull request #1675 from WordPress-Coding-Standards/feature/vali…
GaryJones Apr 1, 2019
8664364
Sniff: add new get_array_access_keys() utility method
jrfnl Mar 29, 2019
a598b08
ValidatedSanitizedInput/Sniff::is_validated(): allow for multi-level …
jrfnl Mar 29, 2019
33b55fe
Merge pull request #1676 from WordPress-Coding-Standards/feature/vali…
GaryJones Apr 1, 2019
b4fb6ba
ValidatedSanitizedInput: make the error messages more informative
jrfnl Mar 30, 2019
0535c1a
Merge pull request #1677 from WordPress-Coding-Standards/feature/1541…
GaryJones Apr 1, 2019
05a71ff
Security: allow for type testing superglobals
jrfnl Mar 28, 2019
854964b
Merge pull request #1678 from WordPress-Coding-Standards/feature/secu…
GaryJones Apr 1, 2019
7841dab
Sniff::is_sanitized(): allow for map_deep() to sanitize arrays
jrfnl Mar 30, 2019
d0f7084
Sniff::has_nonce_check(): add new `is_class_object_call()` and `is_to…
jrfnl Mar 31, 2019
af937cc
Merge pull request #1680 from WordPress-Coding-Standards/feature/nonc…
GaryJones Apr 1, 2019
14c77a8
Merge pull request #1679 from WordPress-Coding-Standards/feature/1660…
GaryJones Apr 1, 2019
e05b727
EscapeOutput: allow for map_deep() to output escape arrays
jrfnl Mar 30, 2019
0934e18
ValidatedSanitizedInput: treat array-value comparison functions same …
jrfnl Mar 30, 2019
5f2d6b5
Sniff::has_nonce_check(): ignore nonce checks in nested closed scopes
jrfnl Mar 31, 2019
5f56dbb
Merge pull request #1683 from WordPress-Coding-Standards/feature/nonc…
GaryJones Apr 1, 2019
3dbe602
Merge pull request #1682 from WordPress-Coding-Standards/feature/vali…
GaryJones Apr 1, 2019
0ef9e85
Merge pull request #1681 from WordPress-Coding-Standards/feature/esca…
GaryJones Apr 1, 2019
1a79eae
ValidatedSanitizedInput: add unit tests for null coalesce (equals) op…
jrfnl Mar 30, 2019
6c8d052
Sniff::is_comparison(): allow to disregard null coalesce
jrfnl Mar 30, 2019
449ea64
Sniff::is_validated(): recognize null coalesce (equal) operator as a …
jrfnl Mar 30, 2019
625f221
ValidatedSanitizedInput: throw unslash/sanitization errors for null c…
jrfnl Mar 30, 2019
7c6f0a8
ValidatedSanitizedInput: allow for validation via null coalesce / nul…
jrfnl Mar 30, 2019
7b18749
Sniff::has_nonce_check(): allow for comparing a variable before nonce…
jrfnl Mar 31, 2019
146e9a1
Merge pull request #1685 from WordPress-Coding-Standards/feature/1114…
GaryJones Apr 2, 2019
363ff11
Merge pull request #1684 from WordPress-Coding-Standards/feature/837-…
GaryJones Apr 2, 2019
2ac765f
ValidatedSanitizedInput: allow for more unslashing functions
jrfnl Apr 2, 2019
19e45db
Merge pull request #1686 from WordPress-Coding-Standards/feature/vali…
GaryJones Apr 2, 2019
bb646b6
Sniff::has_nonce_check(): allow for unslashing a variable before nonc…
jrfnl Apr 1, 2019
ca3d41f
Merge pull request #1687 from WordPress-Coding-Standards/feature/572-…
GaryJones Apr 2, 2019
a8d8c6c
NonceVerification: bug fix - sanitization is no alternative for nonce…
jrfnl Mar 31, 2019
cce11ae
Core: forbid assignments in conditions
jrfnl Mar 27, 2019
031bac0
Merge pull request #1688 from WordPress-Coding-Standards/feature/nonc…
GaryJones Apr 3, 2019
f04207c
Merge pull request #1661 from WordPress-Coding-Standards/feature/core…
GaryJones Apr 3, 2019
d6f9dc0
Core: warn against the use of loose comparisons
jrfnl Mar 27, 2019
4d814b7
Changelog for WPCS 2.1.0
jrfnl Apr 3, 2019
3b2f881
Merge pull request #1662 from WordPress-Coding-Standards/feature/core…
GaryJones Apr 3, 2019
f4b82ae
Changelog: clarified the addition of the `count()` and `sizeof()` fun…
jrfnl Apr 3, 2019
975613f
Merge pull request #1689 from WordPress-Coding-Standards/feature/chan…
GaryJones Apr 4, 2019
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
6 changes: 3 additions & 3 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

<arg value="sp"/>
<arg name="extensions" value="php"/>
<arg name="basepath" value="."/>
<arg name="parallel" value="8"/>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting that PHPCS appears to have an issue with this arg being used on some installs of PHP 7.3.

It might be worth leaving this out for now, though it would only potentially affect contributors to WPCS.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is the ruleset for WPCS itself, I'm not too concerned. If this (upstream) issue would affect a contributor, they can easily get round it by passing --parallel=1 on the command line.

Correct me if I'm wrong, but I don't think changing this is a reason to delay the release.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think changing this is a reason to delay the release.

Completely agree, which is why I approved it - just mentioning it for future reference for future readers.


<exclude-pattern>/bin/class-ruleset-test.php</exclude-pattern>
<!-- Exclude Composer vendor directory. -->
<exclude-pattern>*/vendor/*</exclude-pattern>

<rule ref="WordPress-Extra">
<rule ref="WordPress">
<exclude name="WordPress.Files.FileName"/>
<exclude name="WordPress.NamingConventions.ValidVariableName"/>
<exclude name="WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition"/>
</rule>

<rule ref="WordPress-Docs"/>

<!-- Enforce PSR1 compatible namespaces. -->
<rule ref="PSR1.Classes.ClassDeclaration"/>

Expand Down
16 changes: 11 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
sudo: false

dist: trusty

cache:
Expand All @@ -21,7 +19,7 @@ php:
- 7.1
- 7.2
- 7.3
- nightly
- "7.4snapshot"

env:
# `master` is now 3.x.
Expand All @@ -42,7 +40,7 @@ matrix:

allow_failures:
# Allow failures for unstable builds.
- php: nightly
- php: "7.4snapshot"

before_install:
# Speed up build time by disabling Xdebug.
Expand All @@ -60,12 +58,20 @@ before_install:
# The above require already does the install.
$(pwd)/vendor/bin/phpcs --config-set installed_paths $(pwd)
fi
# Download PHPUnit 7.x for builds on PHP >= 7.2 as the PHPCS
# test suite is currently not compatible with PHPUnit 8.x.
- if [[ ${TRAVIS_PHP_VERSION:0:3} > "7.1" ]]; then wget -P $PHPUNIT_DIR https://phar.phpunit.de/phpunit-7.phar && chmod +x $PHPUNIT_DIR/phpunit-7.phar; fi

script:
# Lint the PHP files against parse errors.
- if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi
# Run the unit tests.
- phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php
- |
if [[ ${TRAVIS_PHP_VERSION:0:3} > "7.1" ]]; then
php $PHPUNIT_DIR/phpunit-7.phar --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php
else
phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php
fi
# Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files.
# This is not an exhaustive test, but should give an early indication for typical fixer conflicts.
# For the first run, the exit code will be 1 (= all fixable errors fixed).
Expand Down
77 changes: 77 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,82 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a

_No documentation available about unreleased changes as of yet._

## [2.1.0] - 2019-04-08

### Added
- New `WordPress.PHP.IniSet` sniff to the `WordPress-Extra` ruleset.
This sniff will detect calls to `ini_set()` and `ini_alter()` and warn against their use as changing configuration values at runtime leads to an unpredictable runtime environment, which can result in conflicts between core/plugins/themes.
- The sniff will not throw notices about a very limited set of "safe" ini directives.
- For a number of ini directives for which there are alternative, non-conflicting ways to achieve the same available, the sniff will throw an `error` and advise using the alternative.
- `doubleval()`, `count()` and `sizeof()` to `Sniff::$unslashingSanitizingFunctions` property.
While `count()` and its alias `sizeof()`, don't actually unslash or sanitize, the output of these functions is safe to use without unslashing or sanitizing.
This affects the `WordPress.Security.ValidatedSanitizedInput` and the `WordPress.Security.NonceVerification` sniffs.
- The new WP 5.1 `WP_UnitTestCase_Base` class to the `Sniff::$test_class_whitelist` property.
- New `Sniff::get_array_access_keys()` utility method to retrieve all array keys for a variable using multi-level array access.
- New `Sniff::is_class_object_call()`, `Sniff::is_token_namespaced()` utility methods.
These should help make the checking of whether or not a function call is a global function, method call or a namespaced function call more consistent.
This also implements allowing for the [namespace keyword being used as an operator](https://www.php.net/manual/en/language.namespaces.nsconstants.php#example-258).
- New `Sniff::is_in_function_call()` utility method to facilitate checking whether a token is (part of) a parameter passed to a specific (set of) function(s).
- New `Sniff::is_in_type_test()` utility method to determine if a variable is being type tested, along with a `Sniff::$typeTestFunctions` property containing the names of the functions this applies to.
- New `Sniff::is_in_array_comparison()` utility method to determine if a variable is (part of) a parameter in an array-value comparison, along with a `Sniff::$arrayCompareFunctions` property containing the names of the relevant functions.
- New `Sniff::$arrayWalkingFunctions` property containing the names of array functions which apply a callback to the array, but don't change the array by reference.
- New `Sniff::$unslashingFunctions` property containing the names of functions which unslash data passed to them and return the unslashed result.

### Changed
- Moved the `WordPress.PHP.StrictComparisons`, `WordPress.PHP.StrictInArray` and the `WordPress.CodeAnalysis.AssignmentInCondition` sniff from the `WordPress-Extra` to the `WordPress-Core` ruleset.
- The `Squiz.Commenting.InlineComment.SpacingAfter` error is no longer included in the `WordPress-Docs` ruleset.
- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.8`.
- The `WordPress.WP.DeprecatedFunctions` sniff will now detect functions deprecated in WP 5.1.
- The `WordPress.Security.NonceVerification` sniff now allows for variable type testing, comparisons, unslashing and sanitization before the nonce check. A nonce check within the same scope, however, is still required.
- The `WordPress.Security.ValidatedSanitizedInput` sniff now allows for using a superglobal in an array-value comparison without sanitization, same as when the superglobal is used in a scalar value comparison.
- `WordPress.NamingConventions.PrefixAllGlobals`: some of the error messages have been made more explicit.
- The error messages for the `WordPress.Security.ValidatedSanitizedInput` sniff will now contain information on the index keys accessed.
- The error message for the `WordPress.Security.ValidatedSanitizedInput.InputNotValidated` has been reworded to make it more obvious what the actual issue being reported is.
- The error message for the `WordPress.Security.ValidatedSanitizedInput.MissingUnslash` has been reworded.
- The `Sniff::is_comparison()` method now has a new `$include_coalesce` parameter to allow for toggling whether the null coalesce operator should be seen as a comparison operator. Defaults to `true`.
- All sniffs are now also being tested against PHP 7.4 (unstable) for consistent sniff results.
- The recommended version of the suggested DealerDirect PHPCS Composer plugin is now `^0.5.0`.
- Various minor code tweaks and clean up.

### Removed
- `ini_set` and `ini_alter` from the list of functions detected by the `WordPress.PHP.DiscouragedFunctions` sniff.
These are now covered via the new `WordPress.PHP.IniSet` sniff.
- `in_array()` and `array_key_exists()` from the list of `Sniff::$sanitizingFunctions`. These are now handled differently.

### Fixed
- The `WordPress.NamingConventions.PrefixAllGlobals` sniff would underreport when global functions would be autoloaded via a Composer autoload `files` configuration.
- The `WordPress.Security.EscapeOutput` sniff will now recognize `map_deep()` for escaping the values in an array via a callback to an output escaping function. This should prevent false positives.
- The `WordPress.Security.NonceVerification` sniff will no longer inadvertently allow for a variable to be sanitized without a nonce check within the same scope.
- The `WordPress.Security.ValidatedSanitizedInput` sniff will no longer throw errors when a variable is only being type tested.
- The `WordPress.Security.ValidatedSanitizedInput` sniff will now correctly recognize the null coalesce (PHP 7.0) and null coalesce equal (PHP 7.4) operators and will now throw errors for missing unslashing and sanitization where relevant.
- The `WordPress.WP.AlternativeFunctions` sniff will no longer recommend using the WP_FileSystem when PHP native input streams, like `php://input`, or the PHP input stream constants are being read or written to.
- The `WordPress.WP.AlternativeFunctions` sniff will no longer report on usage of the `curl_version()` function.
- The `WordPress.WP.CronInterval` sniff now has improved function recognition which should lower the chance of false positives.
- The `WordPress.WP.EnqueuedResources` sniff will no longer throw false positives for inline jQuery code trying to access a stylesheet link tag.
- Various bugfixes for the `Sniff::has_nonce_check()` method:
- The method will no longer incorrectly identify methods/namespaced functions mirroring the name of WP native nonce verification functions as if they were the global functions.
This will prevent some false negatives.
- The method will now skip over nested closed scopes, such as closures and anonymous classes. This should prevent some false negatives for nonce verification being done while not in the correct scope.

These fixes affect the `WordPress.Security.NonceVerification` sniff.
- The `Sniff::is_in_isset_or_empty()` method now also checks for usage of `array_key_exist()` and `key_exists()` and will regard these as correct ways to validate a variable.
This should prevent false positives for the `WordPress.Security.ValidatedSanitizedInput` and the `WordPress.Security.NonceVerification` sniffs.
- Various bugfixes for the `Sniff::is_sanitized()` method:
- The method presumed the WordPress coding style regarding code layout, which could lead to false positives.
- The method will no longer incorrectly identify methods/namespaced functions mirroring the name of WP/PHP native unslashing/sanitization functions as if they were the global functions.
This will prevent some false negatives.
- The method will now recognize `map_deep()` for sanitizing an array via a callback to a sanitization function. This should prevent false positives.
- The method will now recognize `stripslashes_deep()` and `stripslashes_from_strings_only()` as valid unslashing functions. This should prevent false positives.
All these fixes affect both the `WordPress.Security.ValidatedSanitizedInput` and the `WordPress.Security.NonceVerification` sniff.
- Various bugfixes for the `Sniff::is_validated()` method:
- The method did not verify correctly whether a variable being validated was the same variable as later used which could lead to false negatives.
- The method did not verify correctly whether a variable being validated had the same array index keys as the variable as later used which could lead to both false negatives as well as false positives.
- The method now also checks for usage of `array_key_exist()` and `key_exists()` and will regard these as correct ways to validate a variable. This should prevent some false positives.
- The methods will now recognize the null coalesce and the null coalesce equal operators as ways to validate a variable. This prevents some false positives.
The results from the `WordPress.Security.ValidatedSanitizedInput` sniff should be more accurate because of these fixes.
- A potential "Undefined index" notice from the `Sniff::is_assignment()` method.


## [2.0.0] - 2019-01-16

### Important information about this release:
Expand Down Expand Up @@ -994,6 +1070,7 @@ See the comparison for full list.
Initial tagged release.

[Unreleased]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/master...HEAD
[2.1.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.0.0...2.1.0
[2.0.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.0.0-RC1...2.0.0
[2.0.0-RC1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.1...2.0.0-RC1
[1.2.1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.0...1.2.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ When installing the WordPress Coding Standards as a dependency in a larger proje

There are two actively maintained Composer plugins which can handle the registration of standards with PHP_CodeSniffer for you:
* [composer-phpcodesniffer-standards-plugin](https://github.com/higidi/composer-phpcodesniffer-standards-plugin)
* [phpcodesniffer-composer-installer](https://github.com/DealerDirect/phpcodesniffer-composer-installer):"^0.4.3"
* [phpcodesniffer-composer-installer](https://github.com/DealerDirect/phpcodesniffer-composer-installer):"^0.5.0"

It is strongly suggested to `require` one of these plugins in your project to handle the registration of external standards with PHPCS for you.

Expand Down
12 changes: 12 additions & 0 deletions WordPress-Core/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,18 @@
<rule ref="Squiz.PHP.DisallowMultipleAssignments"/>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>

<!-- Rule: Unless absolutely necessary, loose comparisons should not be used,
as their behaviour can be misleading. -->
<rule ref="WordPress.PHP.StrictComparisons"/>
<rule ref="WordPress.PHP.StrictInArray"/>

<!-- Rule: Assignments must not be placed in placed in conditionals.
Note: sniff is a duplicate of upstream. Can be removed once minimum PHPCS requirement has gone up.
https://github.com/squizlabs/PHP_CodeSniffer/pull/1594
Update: the "assignment in ternary" part of the sniff is currently not yet covered in
the upstream version. This needs to be pulled first before we can defer to upstream. -->
<rule ref="WordPress.CodeAnalysis.AssignmentInCondition"/>

<!-- Rule: In a switch statement... If a case contains a block, then falls through
to the next block, this must be explicitly commented. -->
<!-- Covered by the PSR2.ControlStructures.SwitchDeclaration sniff. -->
Expand Down
7 changes: 3 additions & 4 deletions WordPress-Docs/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
<exclude name="Squiz.Commenting.InlineComment.DocBlock"/>
<!-- Excluded to allow /* translators: ... */ comments -->
<exclude name="Squiz.Commenting.InlineComment.NotCapital"/>
<!-- WP handbook doesn't clarify one way or another, so ignore -->
<exclude name="Squiz.Commenting.InlineComment.SpacingAfter"/>

<!-- Not in Inline Docs standard, and a code smell -->
<exclude name="Squiz.Commenting.LongConditionClosingComment"/>
Expand All @@ -86,7 +88,7 @@
<exclude name="Squiz.Commenting.VariableComment.VarOrder"/>
</rule>

<rule ref="Generic.Commenting">
<rule ref="Generic.Commenting.DocComment">
<!-- WP has different alignment of tag values -->
<exclude name="Generic.Commenting.DocComment.TagValueIndent"/>
<!-- WP has a different prefered order of tags -->
Expand All @@ -103,8 +105,5 @@
<exclude name="Generic.Commenting.DocComment.SpacingBeforeShort"/>
<!-- Exclude to allow duplicate hooks to be documented -->
<exclude name="Generic.Commenting.DocComment.ContentBeforeClose"/>

<!-- WP allows @todo's in comments -->
<exclude name="Generic.Commenting.Todo"/>
</rule>
</ruleset>
17 changes: 3 additions & 14 deletions WordPress-Extra/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
</properties>
</rule>

<!-- Duplicate of upstream. Can be removed once minimum PHPCS requirement has gone up.
https://github.com/squizlabs/PHP_CodeSniffer/pull/1594
Note: the "assignment in ternary" part of the sniff is currently not yet covered in
the upstream version. This needs to be pulled first before we can defer to upstream. -->
<rule ref="WordPress.CodeAnalysis.AssignmentInCondition"/>

<!-- More generic PHP best practices.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/607 -->
<rule ref="Squiz.PHP.NonExecutableCode"/>
Expand Down Expand Up @@ -109,14 +103,9 @@
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/26 -->
<rule ref="WordPress.WP.GlobalVariablesOverride"/>

<!-- Encourage the use of strict ( === and !== ) comparisons.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/242 -->
<rule ref="WordPress.PHP.StrictComparisons"/>

<!-- Check that in_array() and array_search() use strict comparisons.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/399
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/503 -->
<rule ref="WordPress.PHP.StrictInArray"/>
<!-- Detect incorrect or risky use of the `ini_set()` function.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1447 -->
<rule ref="WordPress.PHP.IniSet"/>

<!-- Check enqueue and register styles and scripts to have version and in_footer parameters explicitly set.
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1146 -->
Expand Down
20 changes: 9 additions & 11 deletions WordPress/AbstractFunctionRestrictionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,15 @@ public function process_token( $stackPtr ) {
public function is_targetted_token( $stackPtr ) {

// Exclude function definitions, class methods, and namespaced calls.
if ( \T_STRING === $this->tokens[ $stackPtr ]['code'] && isset( $this->tokens[ ( $stackPtr - 1 ) ] ) ) {
if ( \T_STRING === $this->tokens[ $stackPtr ]['code'] ) {
if ( $this->is_class_object_call( $stackPtr ) === true ) {
return false;
}

if ( $this->is_token_namespaced( $stackPtr ) === true ) {
return false;
}

$prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );

if ( false !== $prev ) {
Expand All @@ -222,21 +230,11 @@ public function is_targetted_token( $stackPtr ) {
\T_FUNCTION => \T_FUNCTION,
\T_CLASS => \T_CLASS,
\T_AS => \T_AS, // Use declaration alias.
\T_DOUBLE_COLON => \T_DOUBLE_COLON,
\T_OBJECT_OPERATOR => \T_OBJECT_OPERATOR,
);

if ( isset( $skipped[ $this->tokens[ $prev ]['code'] ] ) ) {
return false;
}

// Skip namespaced functions, ie: \foo\bar() not \bar().
if ( \T_NS_SEPARATOR === $this->tokens[ $prev ]['code'] ) {
$pprev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prev - 1 ), null, true );
if ( false !== $pprev && \T_STRING === $this->tokens[ $pprev ]['code'] ) {
return false;
}
}
}

return true;
Expand Down
Loading