From 2c143e947410e2d0404b9189be30ca227662e788 Mon Sep 17 00:00:00 2001 From: Kay Strobach Date: Fri, 10 Jan 2020 12:11:14 +0100 Subject: [PATCH 1/3] [FEATURE] add codeclimate iteration zero https://github.com/martin-helmich/typo3-typoscript-lint/issues/92 #92 --- .../CodeClimateReportPrinter.php | 80 +++++++++++++++++++ src/Logging/LinterLoggerBuilder.php | 6 +- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/Linter/ReportPrinter/CodeClimateReportPrinter.php diff --git a/src/Linter/ReportPrinter/CodeClimateReportPrinter.php b/src/Linter/ReportPrinter/CodeClimateReportPrinter.php new file mode 100644 index 0000000..e93f54b --- /dev/null +++ b/src/Linter/ReportPrinter/CodeClimateReportPrinter.php @@ -0,0 +1,80 @@ +output = $output; + } + + /** + * Writes a report in checkstyle XML format. + * + * @param Report $report The report to print. + * @return void + */ + public function writeReport(Report $report): void + { + $issues = []; + + foreach ($report->getFiles() as $file) { + foreach ($file->getIssues() as $issue) { + $issueData = [ + 'type' => 'issue', + 'check_name' => $issue->getSource(), + 'description' => $issue->getMessage(), + 'categories' => ['Style'], + 'location' => [ + 'path' => $file->getFilename(), + 'lines' => [ + 'begin' => $issue->getLine() ? ((string) $issue->getLine()) : 0 + ] + ] + ]; + + $column = $issue->getColumn(); + if ($column !== null) { + $issueData['location']['lines']['column'] = $column; + } + + $issueData['fingerprint'] = $this->fingerprint($issueData); + + $issues[] = $issueData; + } + } + + $this->output->write(json_encode($issues)); + } + + protected function fingerprint(array $issue) + { + return md5(json_encode($issue)); + } +} diff --git a/src/Logging/LinterLoggerBuilder.php b/src/Logging/LinterLoggerBuilder.php index 47583ec..e07d1c9 100644 --- a/src/Logging/LinterLoggerBuilder.php +++ b/src/Logging/LinterLoggerBuilder.php @@ -3,6 +3,7 @@ use Helmich\TypoScriptLint\Linter\ReportPrinter\CheckstyleReportPrinter; +use Helmich\TypoScriptLint\Linter\ReportPrinter\CodeClimateReportPrinter; use Helmich\TypoScriptLint\Linter\ReportPrinter\ConsoleReportPrinter; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -34,6 +35,9 @@ public function createLogger(string $outputFormat, OutputInterface $reportOutput : $consoleOutput; switch ($outputFormat) { + case 'json': + case 'codeclimate': + return new CompactConsoleLogger(new CodeClimateReportPrinter($reportOutput), $errorOutput); case 'checkstyle': case 'xml': return new CompactConsoleLogger(new CheckstyleReportPrinter($reportOutput), $errorOutput); @@ -46,4 +50,4 @@ public function createLogger(string $outputFormat, OutputInterface $reportOutput throw new \InvalidArgumentException('Invalid report printer "' . $outputFormat . '"!'); } } -} \ No newline at end of file +} From 1b25d4d4ea3078e5d3ac0330050f3f5c50fef9be Mon Sep 17 00:00:00 2001 From: Kay Strobach Date: Mon, 13 Jan 2020 08:43:02 +0100 Subject: [PATCH 2/3] Update src/Linter/ReportPrinter/CodeClimateReportPrinter.php Co-Authored-By: Martin Helmich --- src/Linter/ReportPrinter/CodeClimateReportPrinter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Linter/ReportPrinter/CodeClimateReportPrinter.php b/src/Linter/ReportPrinter/CodeClimateReportPrinter.php index e93f54b..8cd9671 100644 --- a/src/Linter/ReportPrinter/CodeClimateReportPrinter.php +++ b/src/Linter/ReportPrinter/CodeClimateReportPrinter.php @@ -73,7 +73,7 @@ public function writeReport(Report $report): void $this->output->write(json_encode($issues)); } - protected function fingerprint(array $issue) + protected function fingerprint(array $issue): string { return md5(json_encode($issue)); } From d0ae9934a4f1aba0d6c8400607710ab6f3b0af8c Mon Sep 17 00:00:00 2001 From: Kay Strobach Date: Mon, 13 Jan 2020 08:48:51 +0100 Subject: [PATCH 3/3] Update CodeClimateReportPrinter.php --- src/Linter/ReportPrinter/CodeClimateReportPrinter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Linter/ReportPrinter/CodeClimateReportPrinter.php b/src/Linter/ReportPrinter/CodeClimateReportPrinter.php index 8cd9671..db16985 100644 --- a/src/Linter/ReportPrinter/CodeClimateReportPrinter.php +++ b/src/Linter/ReportPrinter/CodeClimateReportPrinter.php @@ -54,7 +54,7 @@ public function writeReport(Report $report): void 'location' => [ 'path' => $file->getFilename(), 'lines' => [ - 'begin' => $issue->getLine() ? ((string) $issue->getLine()) : 0 + 'begin' => $issue->getLine() ? ((int) $issue->getLine()) : 0 ] ] ]; @@ -73,7 +73,7 @@ public function writeReport(Report $report): void $this->output->write(json_encode($issues)); } - protected function fingerprint(array $issue): string + protected function fingerprint(array $issue) { return md5(json_encode($issue)); }