Skip to content
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

add option to hide files with 100% type coverage #33

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -164,14 +173,16 @@ function (Result $result) use (&$totals): void {

$totals[] = $percentage = $result->totalCoverage;

renderUsing($this->output);
render(<<<HTML
<div class="flex mx-2">
<span class="truncate-{$truncateAt}">{$path}</span>
<span class="flex-1 content-repeat-[.] text-gray mx-1"></span>
<span class="text-{$color}">$uncoveredLines{$uncoveredLinesIgnored} {$percentage}%</span>
</div>
HTML);
if ($this->terse === false || $percentage < 100) {
renderUsing($this->output);
render(<<<HTML
<div class="flex mx-2">
<span class="truncate-{$truncateAt}">{$path}</span>
<span class="flex-1 content-repeat-[.] text-gray mx-1"></span>
<span class="text-{$color}">$uncoveredLines{$uncoveredLinesIgnored} {$percentage}%</span>
</div>
HTML);
}
},
);

Expand Down
19 changes: 19 additions & 0 deletions tests/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down