From 432f020933016f92b9910dcda6d42b077bbe88ab Mon Sep 17 00:00:00 2001 From: Nate Crawford Date: Tue, 1 Oct 2024 13:51:33 -0500 Subject: [PATCH] add option to hide files with 100% type coverage --- src/Plugin.php | 27 +++++++++++++++++++-------- tests/Plugin.php | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 402101c..2439ec5 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -33,6 +33,11 @@ class Plugin implements HandlesArguments */ private float $coverageMin = 0.0; + /** + * Hide files with complete type coverage from output + */ + private bool $terse = false; + /** * The logger used to output type coverage to a file. */ @@ -106,6 +111,10 @@ public function handleArguments(array $arguments): array $this->coverageLogger = new JsonLogger(explode('=', $argument)[1], $this->coverageMin); } + + if ($argument == '--terse') { + $this->terse = true; + } } $source = ConfigurationSourceDetector::detect(); @@ -164,14 +173,16 @@ function (Result $result) use (&$totals): void { $totals[] = $percentage = $result->totalCoverage; - renderUsing($this->output); - render(<< - {$path} - - $uncoveredLines{$uncoveredLinesIgnored} {$percentage}% - - HTML); + if ($this->terse === false || $percentage < 100) { + renderUsing($this->output); + render(<< + {$path} + + $uncoveredLines{$uncoveredLinesIgnored} {$percentage}% + + HTML); + } }, ); diff --git a/tests/Plugin.php b/tests/Plugin.php index 27a76c9..26ed676 100644 --- a/tests/Plugin.php +++ b/tests/Plugin.php @@ -24,6 +24,25 @@ public function exit(int $code): never ); }); +test('it only outputs files under 100% coverage', function () { + $output = new BufferedOutput(); + $plugin = new class($output) extends Plugin + { + public function exit(int $code): never + { + throw new Exception($code); + } + }; + + expect(fn () => $plugin->handleArguments(['--type-coverage', '--terse']))->toThrow(Exception::class, 0) + ->and($output->fetch())->toContain( + '.. pr12 83', + '.. pr12, pa14, pa14, rt14 0', + '.. rt12 67', + '.. pa12 83', + )->not->ToContain('.. 100%'); +}); + test('it can output to json', function () { $output = new BufferedOutput; $plugin = new class($output) extends Plugin