Skip to content

Commit

Permalink
Properly format ignore string
Browse files Browse the repository at this point in the history
  • Loading branch information
noximo committed Mar 17, 2019
1 parent 1926b40 commit 16a8935
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
24 changes: 21 additions & 3 deletions src/FileOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
}

Expand Down Expand Up @@ -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()),
];
}

Expand Down Expand Up @@ -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";
}
}
10 changes: 6 additions & 4 deletions src/table.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ namespace noximo;
background: #374d63
}

.regex {
color: #00000085;
}

#thanks {
margin-top: 50px;
font-size: 0.65em;
Expand Down Expand Up @@ -111,12 +115,10 @@ namespace noximo;
</td>
<td>
<?= $error[FileOutput::ERROR] ?>
<br>
<small class="regex"><?= $error[FileOutput::IGNORE] ?></small>
</td>
</tr>
<tr>
<td></td>
<td><?= $error[FileOutput::IGNORE] ?></td>
</tr>
<?php endforeach ?>
<?php endforeach ?>
<?php endif ?>
Expand Down

0 comments on commit 16a8935

Please sign in to comment.