Repository navigation
Expand file tree
/
Copy pathphpcs.xml.dist
More file actions
156 lines (141 loc) · 7.04 KB
/
Copy pathphpcs.xml.dist
File metadata and controls
156 lines (141 loc) · 7.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?xml version="1.0"?>
<ruleset name="plugin-tracker-sdk">
<description>Coding standards for the Plugin Tracker SDK (codexpertio/plugin-tracker-sdk).</description>
<file>.</file>
<exclude-pattern>/vendor/*</exclude-pattern>
<!-- PHPStan's result cache. Generated PHP, inside the package because a shared default
tmpDir made two packages collide and phpstan runs nondeterministic. Not ours to style. -->
<exclude-pattern>*/.phpstan-cache/*</exclude-pattern>
<exclude-pattern>/dist/*</exclude-pattern>
<exclude-pattern>/tests/*/fixtures/*</exclude-pattern>
<!--
bin/ holds standalone CLI utilities that run under `php bin/…`, not inside WordPress. WPCS rules
about global-variable prefixes and wrapping filesystem calls in WP_Filesystem exist to protect a
WordPress request; neither applies to a build script whose whole job is to read composer.json and
write to STDERR. The shipped library is src/, and that is linted in full.
-->
<exclude-pattern>/bin/*</exclude-pattern>
<!--
tests/php/utils/ holds deliberately un-namespaced global helper classes, following the house
convention (wc-affiliate tests/php/utils/). They are NOT carved out of
WordPress.NamingConventions.PrefixAllGlobals: that sniff already reports every file in this
package (19 findings, all pre-existing), because `prefixes` below is configured as
cx_tracker/CX_TRACKER while the shipped namespace is Codexpert\PluginTracker. Exempting one
test file would suppress a single instance of a systemic mismatch and hide the real issue.
Either widen `prefixes` to cover the namespace, or leave all 19 visible, but do
it package-wide, not per-file.
-->
<exclude-pattern>*.dist</exclude-pattern>
<arg name="extensions" value="php"/>
<arg name="colors"/>
<arg value="ps"/>
<!--
PHPCompatibility with testVersion 7.2- catches a SUBSET of 7.3+ syntax, not all of it.
Measured against the locked phpcompatibility/php-compatibility 9.3.5 (a 2019 release):
caught: typed properties, ??=, trailing comma in calls, array unpacking, array_key_first
NOT caught: fn() =>, match, ?->, str_contains / str_starts_with / str_ends_with
So this ruleset is a useful first line but it is NOT the guarantee. The 7.2 floor is actually
held by `composer analyze`: PHPStan with phpVersion 70200 reports arrow functions and match
as syntax errors and the PHP 8 string functions as not found. Both commands matter, and a
change that passes lint alone has not been checked against the floor.
-->
<config name="testVersion" value="7.2-"/>
<config name="minimum_wp_version" value="5.0"/>
<!--
Only phpcompatibility/php-compatibility is a declared dependency (see composer.json). The
"WordPress" flavour of this ruleset (PHPCompatibilityWP) additionally checks WP-specific
deprecations, but that package (phpcompatibility/phpcompatibility-wp) is not installed here;
referencing it would make phpcs fail to load the ruleset at all. Plain PHPCompatibility is
the correct choice for what is actually required.
-->
<rule ref="PHPCompatibility"/>
<rule ref="WordPress">
<!--
This package autoloads via PSR-4 (Config.php, Consent/Gate.php, Storage/Queue.php, ...),
which is required by Composer and is fundamentally incompatible with WP core's
"class-name-with-dashes.php" file-naming convention. Excluded rather than fought.
-->
<exclude name="WordPress.Files.FileName"/>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array">
<element value="cx_tracker"/>
<element value="CX_TRACKER"/>
</property>
</properties>
</rule>
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="plugin-tracker-sdk"/>
</property>
</properties>
</rule>
<!--
PrefixAllGlobals exists to stop procedural WordPress code from colliding in the global
namespace: prefix your functions, constants and globals, or two plugins will fight. This
package declares nothing in the global namespace at all. Every class lives under
Codexpert\PluginTracker, so the sniff has nothing to protect and reports every file purely
because the namespace does not begin with "cx_tracker".
Collision safety, which is the sniff's actual concern, is handled here twice over and by a
stronger mechanism: PSR-4 namespacing under a vendor-specific root. Per-version namespace
rewriting used to back this up as well; it was dropped, so two consumers bundling different
versions now share whichever copy loads first. autoload.php says so plainly.
Excluded rather than silenced file by file, because it is a systemic mismatch between the
sniff and a namespaced library, not 19 individual defects.
-->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound"/>
</rule>
<!--
Test files are held to the source rules for correctness sniffs but not for the
documentation and WordPress-wrapper sniffs. Two reasons, both specific rather than blanket:
1. Tests legitimately call raw json_encode() to build fixtures and expected payloads. They
are constructing test data, not calling into WordPress, so wp_json_encode() is not the
right function there.
2. The option-store helper in tests/php/utils/ is intentionally an un-namespaced global
class, following the house tests/php/utils/ convention, so the global-prefix sniffs
report it by design.
Per-sniff and scoped to tests/ so nothing here relaxes a rule for src/.
-->
<rule ref="WordPress.WP.AlternativeFunctions.json_encode_json_encode">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_fwrite">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.unlink_unlink">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Generic.Commenting.DocComment">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.FunctionComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<!--
Two more test-only relaxations. The escaping sniff fires where a test deliberately asserts on
RAW output in order to prove the SOURCE escapes it; escaping inside the test would defeat the
test. mt_rand() appears only in the wp_rand() stub, which exists precisely to stand in for
wp_rand().
-->
<rule ref="WordPress.Security.EscapeOutput">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.rand_mt_rand">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
</ruleset>