Skip to content

Commit 0460804

Browse files
committed
Merge pull request #370 from WordPress-Coding-Standards/develop
0.5.0
2 parents 4b7f565 + 3d6a7eb commit 0460804

26 files changed

+2510
-916
lines changed

.travis.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,32 @@ php:
88
- 5.4
99
- 5.5
1010
- 5.6
11-
- nightly
12-
- hhvm
11+
12+
env:
13+
- PHPCS_BRANCH=master
14+
- PHPCS_BRANCH=2.2.0
1315

1416
matrix:
17+
include:
18+
# Run against PHPCS 3.0. I just picked to run it against 5.6.
19+
- php: 5.6
20+
env: PHPCS_BRANCH=3.0
21+
# Run against HHVM and PHP nightly.
22+
- php: hhvm
23+
env: PHPCS_BRANCH=master
24+
- php: nightly
25+
env: PHPCS_BRANCH=master
1526
allow_failures:
27+
# Allow failures for unstable builds.
1628
- php: nightly
1729
- php: hhvm
30+
- env: PHPCS_BRANCH=3.0
1831

1932
before_script:
2033
- export PHPCS_DIR=/tmp/phpcs
21-
- export PHPCS_BRANCH=master
34+
- export PHPCS_BIN=$(if [[ $PHPCS_BRANCH == 3.0 ]]; then echo $PHPCS_DIR/bin/phpcs; else echo $PHPCS_DIR/scripts/phpcs; fi)
2235
- mkdir -p $PHPCS_DIR && git clone --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git -b $PHPCS_BRANCH $PHPCS_DIR
23-
- $PHPCS_DIR/scripts/phpcs --config-set installed_paths $(pwd)
36+
- $PHPCS_BIN --config-set installed_paths $(pwd)
2437

2538
script:
2639
- find . \( -name '*.php' \) -exec php -lf {} \;

CHANGELOG.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,45 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C
55

66
## [Unreleased]
77

8+
### Added
9+
- Sniff to flag dynamic translatable strings and textdomains.
10+
- `get_children()`, `wp_get_object_terms()`, `wp_get_post_(categories|tags|terms)()`,
11+
`get_category_by_slug()`, `get_cat_ID()`, `count_user_posts()`, and `wp_old_slug_redirect()`
12+
to the list of restricted functions in the `WordPress.VIP.RestrictedFunctions` sniff.
13+
14+
## [0.5.0] - 2015-06-01
15+
816
### Added
917
- `WordPress.CSRF.NonceVerification` sniff to flag form processing without nonce verification.
18+
- `in_array()` and `is_array()` to the list of sanitizing functions.
19+
- Support for automatic error fixing to the `WordPress.Arrays.ArrayDeclaration` sniff.
20+
- `WordPress.PHP.StrictComparisions` to the `WordPress-VIP` and `WordPress-Extra` rulesets.
21+
- `WordPress-Docs` ruleset to sniff for proper commenting.
22+
- `Generic.PHP.LowerCaseKeyword`, `Generic.Files.EndFileNewline`, `Generic.Files.LowercasedFilename`,
23+
`Generic.Formatting.SpaceAfterCast`, and `Generic.Functions.OpeningFunctionBraceKernighanRitchie` to the `WordPress-Core` ruleset.
24+
- `Generic.PHP.DeprecatedFunctions`, `Generic.PHP.ForbiddenFunctions`, `Generic.Functions.CallTimePassByReference`,
25+
`Generic.Formatting.DisallowMultipleStatements`, `Generic.CodeAnalysis.EmptyStatement`,
26+
`Generic.CodeAnalysis.ForLoopShouldBeWhileLoop`, `Generic.CodeAnalysis.ForLoopWithTestFunctionCall`,
27+
`Generic.CodeAnalysis.JumbledIncrementer`, `Generic.CodeAnalysis.UnconditionalIfStatement`,
28+
`Generic.CodeAnalysis.UnnecessaryFinalModifier`, `Generic.CodeAnalysis.UselessOverridingMethod`,
29+
`Generic.Classes.DuplicateClassName`, and `Generic.Strings.UnnecessaryStringConcat` to the `WordPress-Extra` ruleset.
30+
- Error for missing use of `wp_unslash()` on superglobal data to the `WordPress.VIP.ValidatedSanitizedInput` sniff.
31+
32+
### Changed
33+
- The `WordPress.VIP.ValidatedSanitizedInput` sniff to require sanitization of input even when it is being directly escaped and output.
34+
- The minimum required PHP_CodeSniffer version to 2.2.0.
35+
- The `WordPress.VIP.ValidatedSanitizedInput` and `WordPress.XSS.EscapeOutput` sniffs:
36+
the list of escaping functions was split from the list of sanitizing functions. The `customSanitizingFunctions`
37+
property has been moved to the `ValidatedSanitizedInput` sniff, and the `customEscapingFunctions`
38+
property should now be used instead for the `EscapeOutput` sniff.
39+
- The `WordPress.Arrays.ArrayDeclaration` sniff to give errors for `NoSpaceAfterOpenParenthesis`, `SpaceAfterArrayOpener`, and `SpaceAfterArrayCloser`, instead of warnings.
40+
- The `WordPress.NamingConventions.ValidFunctionName` sniff to allow camelCase method names in classes that implement interfaces.
41+
42+
### Fixed
43+
- The `WordPress.VIP.ValidatedSanitizedInput` sniff not reporting missing validation when reporting missing sanitization.
44+
- The `WordPress.VIP.ValidatedSanitizedInput` sniff flagging superglobals as needing sanitization when they were only being used in a comparison using `if` or `switch`, etc.
1045

11-
## [0.4.0] - 2015-5-1
46+
## [0.4.0] - 2015-05-01
1247

1348
### Added
1449
- Change log file.

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ For convenience of using `phpcs` as global command you might want to add path to
3131

3232
1. Install PHP_CodeSniffer by following its [installation instructions](https://github.com/squizlabs/PHP_CodeSniffer#installation) (via Composer, PEAR, or Git checkout).
3333

34-
Do ensure, if for example you're using [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV), that you have the **latest version** of CodeSniffer (earlier versions, e.g. ~1.5.5, may warn about incorrect line indentation on every single line even if your code is actually correct.)
34+
Do ensure, if for example you're using [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV), that PHP_CodeSniffer's version matches our requirements (you can check the required version in [composer.json](composer.json#L18)).
3535

3636
2. Clone WordPress standards repository:
3737

@@ -41,6 +41,21 @@ For convenience of using `phpcs` as global command you might want to add path to
4141

4242
phpcs --config-set installed_paths /path/to/wpcs
4343

44+
45+
To summarize:
46+
47+
```bash
48+
cd ~/projects
49+
git clone https://github.com/squizlabs/PHP_CodeSniffer.git phpcs
50+
git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs
51+
cd phpcs
52+
./scripts/phpcs --config-set installed_paths ../wpcs
53+
```
54+
55+
And then add the `~/projects/phpcs/scripts` directory to your `PATH` environment variable via your `.bashrc`.
56+
57+
You should then see `WordPress-Core` et al listed when you run `phpcs -i`.
58+
4459
## How to use
4560

4661
### Command line

WordPress-Core/ruleset.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,27 @@
3838
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
3939
<severity>0</severity>
4040
</rule>
41+
42+
<rule ref="Generic.PHP.LowerCaseKeyword"/>
4143

4244
<rule ref="Generic.Files.LineEndings">
4345
<properties>
4446
<property name="eolChar" value="\n"/>
4547
</properties>
4648
</rule>
4749

50+
51+
<rule ref="Generic.Files.EndFileNewline"/>
52+
53+
<!-- https://make.wordpress.org/core/handbook/coding-standards/php/#naming-conventions -->
54+
<rule ref="Generic.Files.LowercasedFilename"/>
55+
56+
<!-- https://make.wordpress.org/core/handbook/coding-standards/php/#space-usage -->
57+
<rule ref="Generic.Formatting.SpaceAfterCast"/>
58+
59+
<!-- https://make.wordpress.org/core/handbook/coding-standards/php/#brace-style -->
60+
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie"/>
61+
4862
<rule ref="PEAR.Functions.FunctionCallSignature">
4963
<properties>
5064
<property name="requiredSpacesAfterOpen" value="1" />
@@ -58,7 +72,9 @@
5872
<severity>0</severity>
5973
</rule>
6074

61-
<rule ref="WordPress.Arrays.ArrayDeclaration"/>
75+
<rule ref="WordPress.Arrays.ArrayDeclaration">
76+
<exclude name="WordPress.Arrays.ArrayDeclaration.SingleLineNotAllowed" />
77+
</rule>
6278
<rule ref="WordPress.Arrays.ArrayKeySpacingRestrictions"/>
6379
<rule ref="WordPress.Classes.ValidClassName"/>
6480
<rule ref="WordPress.Files.FileName"/>

WordPress-Docs/ruleset.xml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WordPress Docs">
3+
<description>WordPress Coding Standards for Inline Documentation and Comments</description>
4+
5+
<rule ref="Squiz.Commenting">
6+
<!-- Excluded to allow /* translators: ... */ comments -->
7+
<exclude name="Squiz.Commenting.BlockComment.SingleLine"/>
8+
<!-- Sniff seems to require indenting with spaces -->
9+
<exclude name="Squiz.Commenting.BlockComment.FirstLineIndent"/>
10+
<!-- Sniff seems to require indenting with spaces -->
11+
<exclude name="Squiz.Commenting.BlockComment.LineIndent"/>
12+
<!-- Sniff seems to require indenting with spaces -->
13+
<exclude name="Squiz.Commenting.BlockComment.LastLineIndent"/>
14+
<!-- WP requires /** for require() et al. See https://github.com/squizlabs/PHP_CodeSniffer/pull/581 -->
15+
<exclude name="Squiz.Commenting.BlockComment.WrongStart"/>
16+
<!-- WP handbook doesn't clarify one way or another, so ignore -->
17+
<exclude name="Squiz.Commenting.BlockComment.NoEmptyLineAfter"/>
18+
19+
<!-- WP prefers indicating @since, @package, @subpackage etc in class comments -->
20+
<exclude name="Squiz.Commenting.ClassComment.TagNotAllowed"/>
21+
22+
<!-- WP doesn't require //end ... for classes and functions -->
23+
<exclude name="Squiz.Commenting.ClosingDeclarationComment.Missing"/>
24+
25+
<!-- Excluded to allow param documentation for arrays -->
26+
<exclude name="Squiz.Commenting.DocCommentAlignment.SpaceAfterStar"/>
27+
28+
<!-- WP doesn't require a @author value for Squiz -->
29+
<exclude name="Squiz.Commenting.FileComment.IncorrectAuthor"/>
30+
<!-- WP doesn't require a @copyright value for Squiz -->
31+
<exclude name="Squiz.Commenting.FileComment.IncorrectCopyright"/>
32+
<!-- WP doesn't require @author tags -->
33+
<exclude name="Squiz.Commenting.FileComment.MissingAuthorTag"/>
34+
<!-- WP doesn't require @subpackage tags -->
35+
<exclude name="Squiz.Commenting.FileComment.MissingSubpackageTag"/>
36+
<!-- WP doesn't require @copyright tags -->
37+
<exclude name="Squiz.Commenting.FileComment.MissingCopyrightTag"/>
38+
<!-- WP has a different prefered order of tags -->
39+
<exclude name="Squiz.Commenting.FileComment.PackageTagOrder"/>
40+
<!-- WP has a different prefered order of tags -->
41+
<exclude name="Squiz.Commenting.FileComment.SubpackageTagOrder"/>
42+
<!-- WP has a different prefered order of tags -->
43+
<exclude name="Squiz.Commenting.FileComment.AuthorTagOrder"/>
44+
<!-- WP has a different prefered order of tags -->
45+
<exclude name="Squiz.Commenting.FileComment.CopyrightTagOrder"/>
46+
47+
<!-- WP prefers int and bool instead of integer and boolean -->
48+
<exclude name="Squiz.Commenting.FunctionComment.IncorrectParamVarName"/>
49+
<!-- WP prefers int and bool instead of integer and boolean -->
50+
<exclude name="Squiz.Commenting.FunctionComment.InvalidReturn"/>
51+
<!-- WP prefers indicating a @return null for early returns -->
52+
<exclude name="Squiz.Commenting.FunctionComment.InvalidReturnNotVoid"/>
53+
<!-- WP states not all functions require @return -->
54+
<exclude name="Squiz.Commenting.FunctionComment.MissingReturn"/>
55+
<!-- Excluded to allow param documentation for arrays -->
56+
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentNotCapital"/>
57+
<!-- Excluded to allow param documentation for arrays -->
58+
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamName"/>
59+
<!-- WP doesn't require type hints -->
60+
<exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing"/>
61+
62+
<!-- Exclude to allow duplicate hooks to be documented -->
63+
<exclude name="Squiz.Commenting.InlineComment.DocBlock"/>
64+
65+
<!-- Not in Inline Docs standard, and a code smell -->
66+
<exclude name="Squiz.Commenting.LongConditionClosingComment"/>
67+
68+
<!-- Not in Inline Docs standard, and needed to bypass WPCS checks -->
69+
<exclude name="Squiz.Commenting.PostStatementComment"/>
70+
71+
<!-- WP prefers int and bool instead of integer and boolean -->
72+
<exclude name="Squiz.Commenting.VariableComment.IncorrectVarType"/>
73+
<!-- WP demands a @since tag for class variables -->
74+
<exclude name="Squiz.Commenting.VariableComment.TagNotAllowed"/>
75+
<!-- WP prefers @since first -->
76+
<exclude name="Squiz.Commenting.VariableComment.VarOrder"/>
77+
</rule>
78+
79+
<rule ref="Generic.Commenting">
80+
<!-- WP has different alignment of tag values -->
81+
<exclude name="Generic.Commenting.DocComment.TagValueIndent"/>
82+
<!-- WP has a different prefered order of tags -->
83+
<exclude name="Generic.Commenting.DocComment.ParamNotFirst"/>
84+
<!-- Excluded to allow param documentation for arrays -->
85+
<exclude name="Generic.Commenting.DocComment.ParamGroup"/>
86+
<!-- WP prefers no empty line between @param tags and @return -->
87+
<exclude name="Generic.Commenting.DocComment.NonParamGroup"/>
88+
<!-- Excluded to allow param documentation for arrays -->
89+
<exclude name="Generic.Commenting.DocComment.TagsNotGrouped"/>
90+
<!-- Exclude to allow duplicate hooks to be documented -->
91+
<exclude name="Generic.Commenting.DocComment.ContentAfterOpen"/>
92+
<!-- Exclude to allow duplicate hooks to be documented -->
93+
<exclude name="Generic.Commenting.DocComment.SpacingBeforeShort"/>
94+
<!-- Exclude to allow duplicate hooks to be documented -->
95+
<exclude name="Generic.Commenting.DocComment.ContentBeforeClose"/>
96+
97+
<!-- WP allows @todo's in comments -->
98+
<exclude name="Generic.Commenting.Todo.CommentFound"/>
99+
<!-- WP allows @todo's in comments -->
100+
<exclude name="Generic.Commenting.Todo.TaskFound"/>
101+
</rule>
102+
</ruleset>

WordPress-Extra/ruleset.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,35 @@
22
<ruleset name="WordPress Extra">
33
<description>Best practices beyond core WordPress Coding Standards</description>
44

5+
<rule ref="Generic.PHP.DeprecatedFunctions"/>
6+
<rule ref="Generic.PHP.ForbiddenFunctions"/>
7+
<rule ref="Generic.Functions.CallTimePassByReference"/>
8+
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
9+
<rule ref="Generic.CodeAnalysis.EmptyStatement" />
10+
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
11+
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
12+
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
13+
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
14+
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
15+
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
16+
<rule ref="Generic.Classes.DuplicateClassName"/>
17+
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
18+
19+
<!-- This sniff is not refined enough for general use -->
20+
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/382#discussion_r29970107 -->
21+
<!--<rule ref="Generic.Formatting.MultipleStatementAlignment"/>-->
22+
23+
<!-- Hook callbacks may not use all params -->
24+
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/382#discussion_r29981655 -->
25+
<!--<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>-->
26+
527
<rule ref="WordPress-Core"/>
628

729
<rule ref="WordPress.XSS.EscapeOutput"/>
30+
<rule ref="WordPress.CSRF.NonceVerification" />
831
<rule ref="WordPress.PHP.DiscouragedFunctions"/>
932
<rule ref="WordPress.WP.EnqueuedResources"/>
1033
<rule ref="WordPress.Variables.GlobalVariables"/>
34+
<rule ref="WordPress.PHP.StrictComparisons" />
1135

1236
</ruleset>

WordPress-VIP/ruleset.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
<rule ref="WordPress.VIP"/>
1212

1313
<rule ref="WordPress.XSS.EscapeOutput"/>
14+
<rule ref="WordPress.CSRF.NonceVerification" />
15+
<rule ref="WordPress.PHP.StrictComparisons" />
1416

1517
</ruleset>

0 commit comments

Comments
 (0)