Skip to content

Commit de29fb5

Browse files
authored
Merge pull request #49 from wptrainingteam/add/phpcs-config
Add root phpcs.xml.dist for project PHP standards
2 parents 8cb1a35 + 5a8d032 commit de29fb5

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "wptrainingteam/developer-showcase",
3+
"description": "PHP development tooling for the Developer Showcase project",
4+
"license": "GPL-3.0-or-later",
5+
"scripts": {
6+
"lint:php": "./vendor/bin/phpcs -d error_reporting=E_ALL^E_DEPRECATED -s --colors ."
7+
},
8+
"require-dev": {
9+
"wp-coding-standards/wpcs": "^3.0",
10+
"phpcompatibility/phpcompatibility-wp": "*",
11+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0"
12+
},
13+
"minimum-stability": "stable",
14+
"prefer-stable": true,
15+
"config": {
16+
"allow-plugins": {
17+
"dealerdirect/phpcodesniffer-composer-installer": true
18+
}
19+
}
20+
}

phpcs.xml.dist

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Developer Showcase">
3+
<description>PSR-12 naming/structure with WordPress whitespace conventions.</description>
4+
5+
<!-- Scan paths -->
6+
<file>./plugins</file>
7+
<file>./themes</file>
8+
9+
<!-- Excluded directories -->
10+
<exclude-pattern>*/vendor/*</exclude-pattern>
11+
<exclude-pattern>*/node_modules/*</exclude-pattern>
12+
<exclude-pattern>*/build/*</exclude-pattern>
13+
14+
<!-- Only check PHP files -->
15+
<arg name="extensions" value="php"/>
16+
<arg name="colors"/>
17+
<arg value="s"/>
18+
19+
<!--
20+
Base: PSR-12
21+
Override indentation and control-structure spacing below.
22+
-->
23+
<rule ref="PSR12">
24+
<!-- Exclude space-indentation — we use tabs -->
25+
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
26+
<!-- Exclude PSR-12 control structure spacing — replaced by WP rule below -->
27+
<exclude name="PSR12.ControlStructures.ControlStructureSpacing"/>
28+
</rule>
29+
30+
<!-- Enforce tab indentation -->
31+
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
32+
33+
<!--
34+
WordPress whitespace rules:
35+
Spaces inside parentheses for control structures: if ( $foo )
36+
-->
37+
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing"/>
38+
<rule ref="WordPress.WhiteSpace.CastStructureSpacing"/>
39+
<rule ref="WordPress.WhiteSpace.OperatorSpacing"/>
40+
<rule ref="WordPress.Arrays.ArrayDeclarationSpacing"/>
41+
42+
<!-- WordPress security and best-practice sniffs -->
43+
<rule ref="WordPress.Security"/>
44+
<rule ref="WordPress.DB.PreparedSQL"/>
45+
<rule ref="WordPress.WP.EnqueuedResources"/>
46+
<rule ref="WordPress.PHP.NoSilencedErrors"/>
47+
<rule ref="WordPress.WP.DeprecatedFunctions"/>
48+
49+
<!-- Disable Yoda conditions (team agreement) -->
50+
<rule ref="WordPress.PHP.YodaConditions">
51+
<severity>0</severity>
52+
</rule>
53+
54+
<!-- PHP Compatibility -->
55+
<rule ref="PHPCompatibilityWP"/>
56+
<config name="testVersion" value="8.1-"/>
57+
58+
<!-- Pattern folder exclusions -->
59+
<rule ref="WordPress.WP.GlobalVariablesOverride">
60+
<exclude-pattern>*/patterns/*</exclude-pattern>
61+
</rule>
62+
<rule ref="Generic.WhiteSpace.ScopeIndent.Incorrect">
63+
<exclude-pattern>*/patterns/*</exclude-pattern>
64+
</rule>
65+
</ruleset>

0 commit comments

Comments
 (0)