diff --git a/docs/checkstyle.md b/docs/checkstyle.md deleted file mode 100644 index 95c3d059429f..000000000000 --- a/docs/checkstyle.md +++ /dev/null @@ -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 -``` diff --git a/packages/changes-reporting/src/Output/CheckstyleOutputFormatter.php b/packages/changes-reporting/src/Output/CheckstyleOutputFormatter.php deleted file mode 100644 index 82181f85dec0..000000000000 --- a/packages/changes-reporting/src/Output/CheckstyleOutputFormatter.php +++ /dev/null @@ -1,48 +0,0 @@ -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(); - } -} diff --git a/packages/changes-reporting/src/Xml/CheckstyleDOMElementFactory.php b/packages/changes-reporting/src/Xml/CheckstyleDOMElementFactory.php deleted file mode 100644 index 95e7c38ba2f9..000000000000 --- a/packages/changes-reporting/src/Xml/CheckstyleDOMElementFactory.php +++ /dev/null @@ -1,105 +0,0 @@ -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; - } -} diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index c93f11659173..e1ef709e4dec 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -5,7 +5,7 @@ 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 @@ public function validateConfigParameters(): void 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 @@ private function canShowProgressBar(InputInterface $input): bool 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 diff --git a/src/Console/ConsoleApplication.php b/src/Console/ConsoleApplication.php index d6e19e8f4dd0..56abed6330bd 100644 --- a/src/Console/ConsoleApplication.php +++ b/src/Console/ConsoleApplication.php @@ -6,7 +6,7 @@ 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 @@ private function shouldPrintMetaInformation(InputInterface $input): bool } $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