-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Clickable rule names in TextReporter
pointing to official documentation
#8003
Changes from all commits
773b0b0
c846f61
d0920ee
b0516bd
3ccb518
8919afb
175e8a2
48b82ca
0199bab
18091f5
87734b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
|
||
namespace PhpCsFixer\Console\Report\FixReport; | ||
|
||
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; | ||
|
||
/** | ||
* @author Dariusz Rumiński <[email protected]> | ||
* | ||
|
@@ -22,7 +24,11 @@ | |
final class ReportSummary | ||
{ | ||
/** | ||
* @var array<string, array{appliedFixers: list<string>, diff: string}> | ||
* @var array<string, array{ | ||
* appliedFixers: list<string>, | ||
* diff: string, | ||
* extraInfoFixers: array<string, array{"helpUri"?: string, "definition"?: FixerDefinitionInterface, "risky"?: bool}> | ||
* }> | ||
*/ | ||
private array $changed; | ||
|
||
|
@@ -39,9 +45,11 @@ final class ReportSummary | |
private bool $isDecoratedOutput; | ||
|
||
/** | ||
* @param array<string, array{appliedFixers: list<string>, diff: string}> $changed | ||
* @param int $time duration in milliseconds | ||
* @param int $memory memory usage in bytes | ||
* @param array<string, array{ | ||
* appliedFixers: list<string>, | ||
* diff: string, | ||
* extraInfoFixers: array<string, array{"helpUri"?: string, "definition"?: FixerDefinitionInterface, "risky"?: bool}> | ||
* }> $changed | ||
*/ | ||
public function __construct( | ||
array $changed, | ||
|
@@ -72,7 +80,11 @@ public function isDryRun(): bool | |
} | ||
|
||
/** | ||
* @return array<string, array{appliedFixers: list<string>, diff: string}> | ||
* @return array<string, array{ | ||
* appliedFixers: list<string>, | ||
* diff: string, | ||
* extraInfoFixers: array<string, array{"helpUri"?: string, "definition"?: FixerDefinitionInterface, "risky"?: bool}> | ||
* }> | ||
*/ | ||
public function getChanged(): array | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
namespace PhpCsFixer\Console\Report\FixReport; | ||
|
||
use PhpCsFixer\Differ\DiffConsoleFormatter; | ||
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; | ||
use Symfony\Component\Console\Formatter\OutputFormatter; | ||
|
||
/** | ||
* @author Boris Gorbylev <[email protected]> | ||
|
@@ -41,6 +43,7 @@ | |
$output .= $this->getAppliedFixers( | ||
$reportSummary->isDecoratedOutput(), | ||
$fixResult['appliedFixers'], | ||
$fixResult['extraInfoFixers'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really wonder if we need to change the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will let you think again then ... |
||
); | ||
} | ||
|
||
|
@@ -58,13 +61,25 @@ | |
} | ||
|
||
/** | ||
* @param list<string> $appliedFixers | ||
* @param list<string> $appliedFixers | ||
* @param array<string, array{"helpUri"?: string, "definition"?: FixerDefinitionInterface, "risky"?: bool}> $extraInfoFixers | ||
*/ | ||
private function getAppliedFixers(bool $isDecoratedOutput, array $appliedFixers): string | ||
private function getAppliedFixers(bool $isDecoratedOutput, array $appliedFixers, array $extraInfoFixers = []): string | ||
{ | ||
$fixers = []; | ||
|
||
foreach ($appliedFixers as $appliedFixer) { | ||
$url = $extraInfoFixers[$appliedFixer]['helpUri'] ?? ''; | ||
Check warning on line 72 in src/Console/Report/FixReport/TextReporter.php GitHub Actions / PHP 8.3 mutation tests
|
||
if ($isDecoratedOutput && '' !== $url) { | ||
Check warning on line 73 in src/Console/Report/FixReport/TextReporter.php GitHub Actions / PHP 8.3 mutation tests
|
||
$fixers[] = sprintf('<href=%s;fg=yellow>%s</>', OutputFormatter::escape($url), $appliedFixer); | ||
} else { | ||
$fixers[] = $appliedFixer; | ||
} | ||
} | ||
|
||
return sprintf( | ||
$isDecoratedOutput ? ' (<comment>%s</comment>)' : ' (%s)', | ||
implode(', ', $appliedFixers) | ||
implode(', ', $fixers) | ||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* Dariusz Rumiński <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpCsFixer\Fixer; | ||
|
||
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; | ||
|
||
/** | ||
* @author Laurent Laville | ||
*/ | ||
interface FixerReportInterface | ||
{ | ||
/** | ||
* - "helpUri" identify the absolute URI [RFC3986](http://www.rfc-editor.org/info/rfc3986) | ||
* * of the primary documentation for the fixer. | ||
* | ||
* @return array{"helpUri"?: string, "definition"?: FixerDefinitionInterface, "risky"?: bool} | ||
*/ | ||
public function getExtraInfoFixers(): array; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh? no proxy methods please
we already have
isRisky()
andgetDefinition()
, no need for method that is duplicating this knowledgeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't want to have external SARIF output format to your project I understand. Otherwise, consider that, as
helpUri
the extra info that missed fromReportSummary
class, to generate full (validated) SARIF results which identify complety all rules/fixers applied !I know that is not in context of this PR, but as we try to add an additional info (
helpUri
) here I took advange of the situation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should focus on minimal changes required for achieving clickable URLs in the output - nothing more, nothing less. That would make this PR much easier to process and finish. Then, it could be extender or/and refactored to achieve SARIF reporting - for now I don't even have the context what it is, what it needs and I don't want to dig into that at this point. Having said that, I agree with @keradus' comment, and I would prefer first option from this comment. Let's don't model stuff for things that will or won't land later.
That's why I don't like
FixerReportInterface
because we don't need to focus here on reporting (clickable URL can be also added todescribe
CLI command), I would prefer something more atomic, focused on docs URI.ProvidesDocumentationUriInterface
or something like that, that would allow adding only this particular feature to fixers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: If you wan't to know what is SARIF, consider to take time to read this page https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning.
It's a good intro !