From 16a8935ead82851944ebc9042e0d2e408634dd7e Mon Sep 17 00:00:00 2001 From: Tomas Pospisil Date: Sun, 17 Mar 2019 20:38:24 +0100 Subject: [PATCH] Properly format ignore string --- src/FileOutput.php | 24 +++++++++++++++++++++--- src/table.phtml | 10 ++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/FileOutput.php b/src/FileOutput.php index 9da642e..dda48b0 100644 --- a/src/FileOutput.php +++ b/src/FileOutput.php @@ -5,7 +5,6 @@ namespace noximo; use Nette\IOException; -use Nette\Neon\Neon; use Nette\Utils\FileSystem; use Nette\Utils\RegexpException; use Nette\Utils\Strings; @@ -61,7 +60,7 @@ public function __construct(string $outputFile, ?ErrorFormatter $defaultFormatte $this->defaultFormatter = $defaultFormatterClass; $cwd = \Safe\getcwd() . DIRECTORY_SEPARATOR; try { - $outputFile = Strings::replace($outputFile, '{time}', (string) time()); + $outputFile = Strings::replace($outputFile, '{time}', (string)time()); } catch (RegexpException $e) { } @@ -127,7 +126,7 @@ private function generateFile(AnalysisResult $analysisResult): void self::ERROR => self::formatMessage($fileSpecificError->getMessage()), self::LINK => $link, self::LINE => $line, - self::IGNORE => Neon::encode($fileSpecificError->getMessage()), + self::IGNORE => self::formatRegex($fileSpecificError->getMessage()), ]; } @@ -155,4 +154,23 @@ private static function formatMessage(string $message): string return implode(' ', $words); } + + /** + * @param string $message + * @return string + * @throws RegexpException + */ + private static function formatRegex(string $message): string + { + $quotes = "'"; + $message = rtrim($message, '.'); + $message = preg_quote($message, '#'); + + if (Strings::contains($message, "'")) { + $quotes = '"'; + $message = Strings::replace($message, '/\\\\/', '\\\\\\'); + } + + return "- $quotes#" . $message . "#$quotes"; + } } diff --git a/src/table.phtml b/src/table.phtml index 29b1170..5940fd9 100644 --- a/src/table.phtml +++ b/src/table.phtml @@ -62,6 +62,10 @@ namespace noximo; background: #374d63 } + .regex { + color: #00000085; + } + #thanks { margin-top: 50px; font-size: 0.65em; @@ -111,12 +115,10 @@ namespace noximo; +
+ - - - -