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 15 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) { | ||||
$abspath = Filesystem::resolvePath($path, $this->getProjectRoot()); | $abspath = Filesystem::resolvePath($path, $this->getProjectRoot()); | ||||
$fileContent = Filesystem::readFile($abspath); | |||||
$pathInfo = pathinfo($path); | $pathInfo = pathinfo($path); | ||||
// If file is in list of exceptions, let it go | |||||
if (in_array($path, self::EXCEPTIONS)) { | |||||
return; | |||||
} | |||||
Fabien: Dito | |||||
$fileContent = Filesystem::readFile($abspath); | |||||
// 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. | ||||
$guard[] = $pathInfo['filename']; | $guard[] = $pathInfo['filename']; | ||||
// Skip the upper 'src' directory | // Skip the upper 'src' directory | ||||
$guard = array_slice($guard, 1); | $guard = array_slice($guard, 1); | ||||
// Join to a string using an underscore ('_') as the delimiter. | // Join to a string using an underscore ('_') as the delimiter. | ||||
$guard = implode('_', $guard); | $guard = implode('_', $guard); | ||||
Show All 17 Lines |
Dito