[Output] Drop checkstyle to avoid manual fixes in PRs (#5566)

This commit is contained in:
Tomas Votruba 2021-02-15 22:27:07 +01:00 committed by GitHub
parent 662fa900c5
commit f03cfa767a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 199 deletions

View File

@ -1,35 +0,0 @@
# How to Add Checkstyle to your CI?
[Checkstyle](https://github.com/staabm/annotate-pull-request-from-checkstyle) is feature for GitHub Actions to add comment right into your pull-request.
Save your time from looking into failed CI build, when you can see comment right in your pull-request.
## Add GitHub Actions Workflow
```yaml
# .github/workflows/rector_checkstyle.yaml
# see https://github.com/staabm/annotate-pull-request-from-checkstyle
name: Rector Checkstyle
on:
pull_request: null
push:
branches:
- master
jobs:
rector_checkstyle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 7.2
coverage: none
tools: cs2pr
- run: composer install --no-progress --ansi
- run: vendor/bin/rector process --ansi --dry-run --output-format=checkstyle | cs2pr
```

View File

@ -1,48 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\ChangesReporting\Output;
use DOMDocument;
use Rector\ChangesReporting\Application\ErrorAndDiffCollector;
use Rector\ChangesReporting\Contract\Output\OutputFormatterInterface;
use Rector\ChangesReporting\Xml\CheckstyleDOMElementFactory;
/**
* Inspired by https://github.com/phpstan/phpstan-src/commit/fa1f416981438b80e2f39eabd9f1b62fca9a6803#diff-7a7d635d9f9cf3388e34d414731dece3
*/
final class CheckstyleOutputFormatter implements OutputFormatterInterface
{
/**
* @var string
*/
public const NAME = 'checkstyle';
/**
* @var CheckstyleDOMElementFactory
*/
private $checkstyleDOMElementFactory;
public function __construct(CheckstyleDOMElementFactory $checkstyleDOMElementFactory)
{
$this->checkstyleDOMElementFactory = $checkstyleDOMElementFactory;
}
public function getName(): string
{
return self::NAME;
}
public function report(ErrorAndDiffCollector $errorAndDiffCollector): void
{
$domDocument = new DOMDocument('1.0', 'UTF-8');
$domElement = $this->checkstyleDOMElementFactory->create($domDocument, $errorAndDiffCollector);
$domDocument->appendChild($domElement);
// pretty print with spaces
$domDocument->formatOutput = true;
echo $domDocument->saveXML();
}
}

View File

@ -1,105 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\ChangesReporting\Xml;
use DOMDocument;
use DOMElement;
use Rector\ChangesReporting\Application\ErrorAndDiffCollector;
use Rector\ChangesReporting\ValueObject\RectorWithFileAndLineChange;
use Rector\Core\ValueObject\Reporting\FileDiff;
/**
* Inspiration in @see \Symfony\Component\Console\Descriptor\XmlDescriptor
*/
final class CheckstyleDOMElementFactory
{
/**
* @var string
*/
private const CHECKSTYLE = 'checkstyle';
/**
* @var string
*/
private const FILE = 'file';
/**
* @var string
*/
private const ERROR = 'error';
public function create(DOMDocument $domDocument, ErrorAndDiffCollector $errorAndDiffCollector): DOMElement
{
$domElement = $domDocument->createElement(self::CHECKSTYLE);
foreach ($errorAndDiffCollector->getFileDiffs() as $fileDiff) {
$fileDOMElement = $this->createFileDOMElement($domDocument, $fileDiff);
$domElement->appendChild($fileDOMElement);
}
$nonFileErrorDOMElement = $this->createNonFileErrorDOMElements($domDocument, $errorAndDiffCollector);
if ($nonFileErrorDOMElement !== null) {
$domElement->appendChild($nonFileErrorDOMElement);
}
return $domElement;
}
private function createFileDOMElement(DOMDocument $domDocument, FileDiff $fileDiff): DOMElement
{
$domElement = $domDocument->createElement(self::FILE);
$domElement->setAttribute('name', $this->escapeForXml($fileDiff->getRelativeFilePath()));
foreach ($fileDiff->getRectorChanges() as $rectorWithFileAndLineChange) {
$errorDOMElement = $this->createErrorDOMElement($rectorWithFileAndLineChange, $domDocument);
$domElement->appendChild($errorDOMElement);
}
return $domElement;
}
private function createNonFileErrorDOMElements(
DOMDocument $domDocument,
ErrorAndDiffCollector $errorAndDiffCollector
): ?DOMElement {
if ($errorAndDiffCollector->getErrors() === []) {
return null;
}
$domElement = $domDocument->createElement(self::FILE);
foreach ($errorAndDiffCollector->getErrors() as $rectorError) {
$errorDOMElement = $domDocument->createElement(self::ERROR);
$errorDOMElement->setAttribute('severity', self::ERROR);
$errorDOMElement->setAttribute('message', $this->escapeForXml($rectorError->getMessage()));
$domElement->appendChild($errorDOMElement);
}
return $domElement;
}
private function escapeForXml(string $string): string
{
return htmlspecialchars($string, ENT_XML1 | ENT_COMPAT);
}
private function createErrorDOMElement(
RectorWithFileAndLineChange $rectorWithFileAndLineChange,
DOMDocument $domDocument
): DOMElement {
$domElement = $domDocument->createElement(self::ERROR);
$domElement->setAttribute('line', $this->escapeForXml((string) $rectorWithFileAndLineChange->getLine()));
$domElement->setAttribute('column', '1');
$domElement->setAttribute('severity', self::ERROR);
$message = $rectorWithFileAndLineChange->
getRectorDefinitionsDescription() . ' (Reported by: ' . $rectorWithFileAndLineChange->getRectorClass() . ')';
$domElement->setAttribute('message', $this->escapeForXml($message));
return $domElement;
}
}

View File

@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Rector\Core\Configuration;
use Jean85\PrettyVersions;
use Rector\ChangesReporting\Output\CheckstyleOutputFormatter;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\ChangesReporting\Output\JsonOutputFormatter;
use Rector\Core\Exception\Configuration\InvalidConfigurationException;
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
@ -267,10 +267,7 @@ final class Configuration
public function shouldHideClutter(): bool
{
if ($this->outputFormat === JsonOutputFormatter::NAME) {
return true;
}
return $this->outputFormat === CheckstyleOutputFormatter::NAME;
return $this->outputFormat !== ConsoleOutputFormatter::NAME;
}
public function shouldShowDiffs(): bool
@ -284,11 +281,9 @@ final class Configuration
if ($noProgressBar) {
return false;
}
$optionOutputFormat = $input->getOption(Option::OPTION_OUTPUT_FORMAT);
if ($optionOutputFormat === JsonOutputFormatter::NAME) {
return false;
}
return $input->getOption(Option::OPTION_OUTPUT_FORMAT) !== CheckstyleOutputFormatter::NAME;
return $optionOutputFormat === ConsoleOutputFormatter::NAME;
}
private function sanitizeOutputFileValue(?string $outputFileOption): ?string

View File

@ -6,7 +6,7 @@ namespace Rector\Core\Console;
use Composer\XdebugHandler\XdebugHandler;
use OutOfBoundsException;
use Rector\ChangesReporting\Output\CheckstyleOutputFormatter;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\ChangesReporting\Output\JsonOutputFormatter;
use Rector\Core\Bootstrap\NoRectorsLoadedReporter;
use Rector\Core\Configuration\Configuration;
@ -153,7 +153,7 @@ final class ConsoleApplication extends Application
}
$outputFormat = $input->getParameterOption(['-o', '--output-format']);
return ! in_array($outputFormat, [JsonOutputFormatter::NAME, CheckstyleOutputFormatter::NAME], true);
return $outputFormat === ConsoleOutputFormatter::NAME;
}
private function removeUnusedOptions(InputDefinition $inputDefinition): void