Changeset View
Changeset View
Standalone View
Standalone View
arcanist/linter/IncludeGuardLinter.php
<?php | <?php | ||||
/** | /** | ||||
* Check the include guard matches the rules from the developer notes. | * Check the include guard matches the rules from the developer notes. | ||||
*/ | */ | ||||
final class IncludeGuardLinter extends ArcanistLinter { | final class IncludeGuardLinter extends ArcanistLinter { | ||||
const GUARD_PREFIX = 'BITCOIN_'; | const GUARD_PREFIX = 'BITCOIN_'; | ||||
const GUARD_SUFFIX = '_H'; | const GUARD_SUFFIX = '_H'; | ||||
const INCLUDE_GUARD_INVALID = 1; | const INCLUDE_GUARD_INVALID = 1; | ||||
const EXCEPTIONS = array( | |||||
// none yet | |||||
); | |||||
public function getInfoName() { | public function getInfoName() { | ||||
return 'lint-include-guard'; | return 'lint-include-guard'; | ||||
} | } | ||||
public function getInfoDescription() { | public function getInfoDescription() { | ||||
return pht('Check the include guard matches the rules from the developer '. | return pht('Check the include guard matches the rules from the developer '. | ||||
'notes. '); | 'notes. '); | ||||
} | } | ||||
Show All 14 Lines | final class IncludeGuardLinter extends ArcanistLinter { | ||||
public function getLintNameMap() { | public function getLintNameMap() { | ||||
return array( | return array( | ||||
self::INCLUDE_GUARD_INVALID => pht('Include guard malformed or missing.'), | self::INCLUDE_GUARD_INVALID => pht('Include guard malformed or missing.'), | ||||
); | ); | ||||
} | } | ||||
public function lintPath($path) { | public function lintPath($path) { | ||||
// If file is in list of exceptions, let it go | |||||
if (in_array($path, self::EXCEPTIONS)) { | |||||
return; | |||||
} | |||||
$abspath = Filesystem::resolvePath($path, $this->getProjectRoot()); | $abspath = Filesystem::resolvePath($path, $this->getProjectRoot()); | ||||
$fileContent = Filesystem::readFile($abspath); | $fileContent = Filesystem::readFile($abspath); | ||||
$pathInfo = pathinfo($path); | $pathInfo = pathinfo($path); | ||||
// Get the path components. They are relative to project root. | // Get the path components. They are relative to project root. | ||||
$guard = explode('/', $pathInfo['dirname']); | $guard = explode('/', $pathInfo['dirname']); | ||||
// Add the file name (without extension) to the path components. | // Add the file name (without extension) to the path components. | ||||
Show All 22 Lines |