Troubleshooting
A clean result that should not be clean, a message about rules that never settle, an editor that undoes on save what DressCode fixed: here are the cause and the remedy for each.
Why It Is Clean When It Shouldn't Be
The run ended with OK and you know it shouldn't have. The answer is in the header and in the summary:
OK 36 violations in the baseline: the violations are there, but the baseline already lists them. Generate it again, or remove it from the configuration.- The file is not in the scope of the check. The header says how many files are checked. What is excluded by default and
how
excludePathsworks is described in Configuration. Note that exclusions only accumulate: once a path is excluded, no layer can include it again. - A decision does not apply.
dresscode configprints the value of every decision and the layer that set it, and for a decision that does not apply, the reason:no effect: phpwhen it needs a newer PHP than the target version,no effect: typeswhen it needs types the configuration does not have, and so on. A decision that no standard, set or configuration sets iskeepand requires nothing;dresscode explain <path>tells you which values it takes and what value each standard gives it. - A rule was skipped because of the PHP version. A rule for newer syntax turns itself off when the project's target
version is lower, and if your configuration names its decision, the run prints a warning about it. The header shows the target
version, for example
Target PHP 8.2 from `composer.json`. If it saysPHP 8.0 by default, `composer.json` names no PHP version in `require`even though you have acomposer.json, the lowest version could not be read from itsrequire.php, for example because the constraint has no lower bound (<8.4,*). In that case, set the version with the keytargets: {php: '8.2'}; see PHP and Package Versions. - The fix is risky. The summary says, for example,
1 risky fix waits, the type is unknown: set `typeAnalysis: phpstan`: this is a risky fix, one that could change the behavior of the code, sofixonly reported it. The sentence in the summary says what would decide the fix, and the link after it leads to a guide. What decides a risky fix and how to allow it is described in Warnings and Risky Fixes. - The rule only warns. The
severitykey softened it towarning(thepsr12andperCsstandards do this forfile.longLines), so its findings carry the labelwarningand do not change the exit code;--max-warningssets a threshold.dresscode configmarks such a decision with the noteonly warns. - The cache. A file with the same path, the same content and the same configuration is skipped. The configuration, the baseline and the files of the project's own rules are all part of the cache key, so changing them invalidates the cache automatically.
- A suppression in the code.
dresscode:ignoreandphpcs:ignoreapply to fixing too, and adresscode:disablewithout anenablelasts until the end of the file. In the comment, name a decision by its whole path, as in the configuration (mistakes.strictArgument), or by its section alone, which suppresses everything under it. DressCode does not recognize any other form, such asstrict-calls, and such a comment suppresses nothing.
Messages Worth Explaining
No `dresscode.neon` or `dresscode.php` found in `/var/www/shop` or above it, so there is no dress code to check against. Run `dresscode init` to have one made to measure from the code, or name a standard with `--use`.
DressCode wears no style of its own, so without a configuration it neither checks nor fixes anything. The command dresscode init measures a configuration from your code; to
try DressCode out, it is enough to choose a standard with the --use option, for example --use perCs.
When DressCode says so even though the project has a configuration, check where you run it from: it searches for the configuration
from the working directory upward, not from the location of the checked files, so it cannot find it when you run it outside the
project. Run it from the root of the project, or pass the path to the configuration with the --config option.
No paths given and none configured. Without a configuration file, you must give the paths on the command
line; with a file, the paths key is enough.
Key `no_unused_imports` is unknown. It is the name of a rule of another tool, covered by `imports.unused`; `dresscode migrate config` translates a configuration of another tool.
The configuration and the command line accept DressCode decision paths; names from other tools are valid only in suppression
comments. The message translates the other tool's name for you, and the command migrate config converts a whole configuration file of
another tool.
Key `imports.unsed` is unknown; write `imports.unused`. A typo in the path; the message offers the closest
known one. When the path belongs to a plugin's section, such as acme.debugCalls, and the message does not recognize
it, the plugin is missing from the use key: neither its class nor the name of the package that brings it is
listed there.
Package `acme/code-style` brings the plugin `Acme\CodeStyle\Plugin`, which loads only where `use` names the package or the plugin; skipped.
An installed package carries a plugin, but the project did not let it in. A plugin brings code that runs on every check, so it is
loaded only when you write the name of the package or the class of the plugin into the use key; see Plugins.
Name `types` is both a section of decisions and the preset `dresscode/types`; write `types.*` for the section or `dresscode/types` for the preset.
A name in --only, fixRisky or severity is both a section and a set, and DressCode does not
know which one you mean. Say which one you mean: types.* for the section, dresscode/types for the set.
No other section shares its name with a set; the sections that match the sets cleanup and correctness
are named hygiene and mistakes.
Decision `classes.overridingMethod.signature` needs the types of the code; set `typeAnalysis: phpstan` in the configuration and install `phpstan/phpstan` beside DressCode.
Your configuration names a decision whose rule needs the types of the code, but the configuration has no types. If it came from a
standard or a set, such a decision would silently not apply, but a decision in the configuration is one you asked for explicitly,
so this is a configuration error with exit code 3. Set typeAnalysis: phpstan, as the message advises, or
remove the decision from the configuration; see Types from PHPStan.
Key `file.lineLength` does not take `abc`; write a count from `1` or `none`. A value outside the range the
decision accepts; the message says what it accepts. dresscode explain file.lineLength prints the whole range, with
the meaning of every word.
The file changed while it was being fixed, so it was not written; run `fix` again. An editor or another
tool saved the file in the meantime. Right before writing, DressCode checks that the file still contains the text it was fixing,
and if it does not, it writes nothing, so as not to overwrite your changes. The file is reported as a failure (exit code
2); just run fix again.
A file with a syntax error is listed with its line number, and the exit code is 1, the same as for
violations. DressCode does not fix it, but it does not silently skip it either: you cannot measure style on code that PHP does not
accept.
Warning: 3 entries of the baseline no longer match a violation; regenerate it with `dresscode baseline`.
means that a violation listed in the baseline is no longer in the code: someone fixed it by hand, or fix did once it
became fixable. Nothing is wrong; just generate the baseline again, see the baseline.
Baseline file `/var/www/shop/dresscode-baseline.neon` is not of the version this DressCode writes; generate it again with `dresscode baseline`.
The baseline file does not start with version: 2, the form DressCode reads, and the run ends with exit code
3. Delete the old file, run fix, and then run dresscode baseline to write it again.
Messages of Your Own Rules and Plugins
You meet these messages only when the project uses rules of its own or rules from a plugin.
Rule `Acme\CodeStyle\NoDebugCallsRule` declares no decision. A rule from the rules key or
from a plugin returns no decision from getDecisions(). Every violation is reported under a decision, so a rule must
have at least one; see A Rule in
Detail.
Rules `Acme\CodeStyle\OneRule` and `Acme\CodeStyle\TwoRule` do not converge in `src/Cart.php`.
Two rules are fighting: one changes the code, the other changes it back, until the tree returns to a state it has already been in.
The engine detects this, reports the file as a failure (exit code 2) and writes nothing into it. The built-in rules
do not conflict with each other, so the message points to your own rule or a plugin, and it names both sides of the conflict.
Below it, there is usually a diff of the two states showing what the rules disagree about. Until you resolve the conflict, set the
decision of one of them to keep. If the message names two built-in rules, it is a bug in DressCode; report it, together with that diff.
Rule `Acme\CodeStyle\NoDebugCallsRule` is faulty: it changed the file without reporting a violation. (or
after a suppressed report) means that the rule broke the contract: every change of the tree must come only after a
call to report() that returned true. RuleTester checks this for the built-in rules; in your
own rule, it means a bug in that rule. The --strict-rules option turns such a warning into an error, so that it
cannot go unnoticed in the tests.
A configuration error about two rules that want to decide the same gap. Two whitespace rules claim the same place; the engine refuses this, because otherwise the result would depend on their order. Claims fixed in advance are compared as soon as the first file is processed; when a rule decides its claim only from the code, the conflict is reported at the place where the two claims meet. This can happen only with a rule from a plugin or with the project's own rule.
The cache does not notice a change in a file a rule factory reads. The files of your own rules are part of the cache
key, but a rule built by a factory that reads some other file than the configuration is an exception: when that file changes, use
--no-cache.
The Editor Undoes the Fixes
When your editor reformats a file on save and undoes what dresscode fix did, two formatters are fighting over it:
DressCode and the editor's built-in formatter. Turn off the built-in PHP formatting in PhpStorm or the default PHP formatter in
VS Code, or at least turn off format on save. How to set DressCode up as the formatter of your editor is described in Editors and IDEs.
Line Endings
The message Expected LF line endings, CRLF found. means that the configuration or a preset requires a specific
line ending (file.lineEnding: LF) and the file has a different one; it is reported once for the whole file.
A project that wants to keep line endings as they are, and only make them consistent within each file, sets
file.lineEnding: majority, and so do all five standards. A project on Windows where Git converts line endings should
leave the conversion to Git and stay with majority: the file in the working tree has CRLF, and DressCode leaves it
that way.