You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/rules_exceptions.rst
+35-1Lines changed: 35 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,17 +21,51 @@ Sometimes you may want to ignore/modify certain rule for specific files or direc
21
21
Sets provided by PHP CS Fixer are a living standards, and as such their definition is NOT covered with Backward Compatibility promise.
22
22
That means any upgrade of PHP CS Fixer may add or remove fixers from the sets (or change their configuration).
23
23
This already means that after upgrade of PHP CS Fixer, your project will start applying different rules, simply due to fact of upgrade.
24
-
This may come from adding a new rules to the set, but also removed the rule or replace the deprecated rule by it's successor.
24
+
This may come from adding a new rules to the set, but also removed the rule or replace the deprecated rule by its successor.
25
25
26
26
Now, when you use exceptions for the rules, this may lead to situation where, after PHP CS Fixer upgrade,
27
27
your exception refers to a rule that is no longer part of the set you use.
28
28
29
29
For such cases, PHP CS Fixer will check that all the rules configured as exceptions are actually configured in set and raise error if some of them are not used.
30
30
This will prevent accidental breaking of rules exceptions due to upgrade of PHP CS Fixer.
31
31
32
+
Configuring exceptions via ``@php-cs-fixer-ignore`` annotation
Sometimes, simple annotation usage for ignoring the rule in-file is not enough.
68
+
35
69
If you need to **ignore** or **reconfigure** a rule for specific files, you can inject ``RuleCustomisationPolicyInterface`` via ``Config::setRuleCustomisationPolicy()`` method:
/** @TODO v3.999 check if rule is deprecated and show the replacement rules as well */
188
-
$missingFixerNames = implode("\n- ", array_map(
189
-
staticfunction (string$name): string {
190
-
$extra = '';
191
-
if ('' === $name) { // @phpstan-ignore-line identical.alwaysFalse future-ready
192
-
$extra = '(no name provided)';
193
-
} elseif ('@' === $name[0]) {
194
-
$extra = ' (can exclude only rules, not sets)';
195
-
}
196
-
// @TODO v3.999 handle "unknown rules"
197
-
198
-
return$name.$extra;
199
-
},
200
-
$missingFixerNames
201
-
));
202
-
203
-
thrownew \RuntimeException(
204
-
<<<EOT
205
-
Rule Customisation Policy contains customisers for fixers that are not in the current set of enabled fixers:
206
-
- {$missingFixerNames}
207
-
208
-
Please check your configuration to ensure that these fixers are included, or update your Rule Customisation Policy if they have been replaced by other fixers in the version of PHP CS Fixer you are using.
Rule Customisation Policy contains customisers for rules that are not in the current set of enabled rules:
196
+
%s
197
+
198
+
Please check your configuration to ensure that these rules are included, or update your Rule Customisation Policy if they have been replaced by other rules in the version of PHP CS Fixer you are using.
199
+
EOT
200
+
);
201
+
218
202
// @TODO 4.0: Remove condition and its body, as no longer needed when param will be required in the constructor.
219
203
// This is a fallback only in case someone calls `new Runner()` in a custom repo and does not provide v4-ready params in v3-codebase.
220
204
if (null === $this->input) {
@@ -231,6 +215,46 @@ static function (string $name): string {
@php-cs-fixer-ignore annotation(s) used for rules that are not in the current set of enabled rules:
557
+
%s
558
+
559
+
Please check your annotation(s) usage in {$filePathname} to ensure that these rules are included, or update your annotation(s) usage if they have been replaced by other rules in the version of PHP CS Fixer you are using.
560
+
EOT
561
+
);
513
562
514
563
try {
515
564
foreach ($this->fixersas$fixer) {
565
+
if (\in_array($fixer->getName(), $rulesIgnoredByAnnotations, true)) {
0 commit comments