Changeset View
Changeset View
Standalone View
Standalone View
arcanist/linter/LogLinter.php
<?php | <?php | ||||
/** | /** | ||||
* Ensure the calls to LogPrint() and LogPrintf() end with a newline. | * Ensure the calls to (Wallet)LogPrint() and (Wallet)LogPrintf() end with a | ||||
* newline. | |||||
*/ | */ | ||||
final class LogLinter extends ArcanistLinter { | final class LogLinter extends ArcanistLinter { | ||||
const MISSING_NEWLINE = 1; | const MISSING_NEWLINE = 1; | ||||
public function getInfoName() { | public function getInfoName() { | ||||
return 'lint-logs'; | return 'lint-logs'; | ||||
} | } | ||||
Show All 23 Lines | public function getLintNameMap() { | ||||
); | ); | ||||
} | } | ||||
public function lintPath($path) { | public function lintPath($path) { | ||||
$absPath = Filesystem::resolvePath($path, $this->getProjectRoot()); | $absPath = Filesystem::resolvePath($path, $this->getProjectRoot()); | ||||
$fileContent = Filesystem::readFile($absPath); | $fileContent = Filesystem::readFile($absPath); | ||||
/* Recursive patterns to match balanced parenthesis and quotes content. */ | /* Recursive patterns to match balanced parenthesis and quotes content. */ | ||||
$logPrintPattern = '/LogPrintf?(\((?>[^()]|(?1))*\));/'; | $logPrintPattern = '/(?:Wallet)?LogPrintf?(\((?>[^()]|(?1))*\));/'; | ||||
$logPrintContentPattern = '/("(?>[^"]|(?1))*")(?:,|\))/U'; | $logPrintContentPattern = '/("(?>[^"]|(?1))*")(?:,|\))/U'; | ||||
if (preg_match_all($logPrintPattern, $fileContent, $logPrints, | if (preg_match_all($logPrintPattern, $fileContent, $logPrints, | ||||
PREG_OFFSET_CAPTURE)) { | PREG_OFFSET_CAPTURE)) { | ||||
foreach ($logPrints[1] as $logPrint) { | foreach ($logPrints[1] as $logPrint) { | ||||
/* This is the whole content of the print function. */ | /* This is the whole content of the print function. */ | ||||
list($logPrintContent, $offsetPrint) = $logPrint; | list($logPrintContent, $offsetPrint) = $logPrint; | ||||
if (preg_match_all($logPrintContentPattern, $logPrintContent, | if (preg_match_all($logPrintContentPattern, $logPrintContent, | ||||
$logPrintMessage, PREG_OFFSET_CAPTURE)) { | $logPrintMessage, PREG_OFFSET_CAPTURE)) { | ||||
/* This is the full log message, even if split in multiple lines. */ | /* This is the full log message, even if split in multiple lines. */ | ||||
list($message, $offsetMessage) = $logPrintMessage[1][0]; | list($message, $offsetMessage) = $logPrintMessage[1][0]; | ||||
if (!(substr($message, -3) == '\n"')) { | if (!(substr($message, -3) == '\n"')) { | ||||
$this->raiseLintAtOffset( | $this->raiseLintAtOffset( | ||||
$offsetPrint + $offsetMessage, | $offsetPrint + $offsetMessage, | ||||
self::MISSING_NEWLINE, | self::MISSING_NEWLINE, | ||||
pht('If this is deliberate, please use the '. | pht('If this is deliberate, please use the '. | ||||
'`LogPrint*ToBeContinued()` method instead.'), | '`(Wallet)LogPrint*ToBeContinued()` method instead.'), | ||||
$message, | $message, | ||||
null); | null); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |