DX: add env for easier finding which fixer break a PHP syntax#9356
Conversation
|
Eh, PHPMD is complaining that "The method fixFile() contains an exit expression." which is what I want to be... |
|
i was doing sth similar from time to time. maybe let me reopen and brainstorm |
| } catch (LintingException $e) { | ||
| echo "\n\nFixer {$fixer->getName()} introduced linting issue:\n\n{$tokens->generateCode()}\n"; | ||
|
|
||
| exit(1); |
There was a problem hiding this comment.
what if we mimic code from "after-all-rules" validation?
sth similar to:
try {
$this->linter->lintSource(...)->check();
} catch (LintingException $e) {
$this->dispatchEvent(FileProcessed::NAME, new FileProcessed(FileProcessed::STATUS_LINT));
$this->errorsManager->report(new Error(Error::TYPE_LINT, $filePathname, $e, $fixInfo['appliedFixers'], $fixInfo['diff']));
break;
}
then, last applied is the issue maker.
(i wouldn't always lint rule after rule, it will slow down the process heavily if file requires changes from multiple rules)
There was a problem hiding this comment.
i wouldn't always lint rule after rule
That is exactly the point: to pinpoint exactly which rule has broken the syntax. It would slow down the process heavily if run on the whole codebase.
| $tokens->clearEmptyTokens(); | ||
| $tokens->clearChanged(); | ||
| $appliedFixers[] = $fixer->getName(); | ||
| if (filter_var(getenv('PHP_CS_FIXER_DEBUG'), \FILTER_VALIDATE_BOOL)) { |
There was a problem hiding this comment.
filter_...(getenv(...
i guess we can move outside of loop
There was a problem hiding this comment.
I made it initially as private property of Runner class, but got rid of it to keep all this "debug" in one place.
|
nice addition, @kubawerlos |
It happened to me many times before, most recently when debugging #9349. The new env variable could also be used to ask the bug reporter for more details.
For the code:
trying to check it resulted in a regular way:
wrongly gives the impression that
ClassAttributesSeparationFixeris a problem. The fact is, the fixer already got tokens with invalid syntax: