Changeset View
Changeset View
Standalone View
Standalone View
arcanist/linter/IncludeGuardLinter.php
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | public function lintPath($path) { | ||||
$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); | ||||
// Transform the whole string to uppercase. | // Transform the whole string to uppercase. | ||||
$guard = strtoupper($guard); | $guard = strtoupper($guard); | ||||
// Surround with prefix and suffix. | // Surround with prefix and suffix. | ||||
$guard = self::GUARD_PREFIX.$guard.self::GUARD_SUFFIX; | $guard = self::GUARD_PREFIX.$guard.self::GUARD_SUFFIX; | ||||
if (preg_match_all('/#(?:ifndef|define) '.$guard.'/', $fileContent) != 2) { | if (preg_match_all('@#(?:ifndef|define|endif //) '.$guard.'@', | ||||
$fileContent) != 3) { | |||||
return $this->raiseLintAtPath( | return $this->raiseLintAtPath( | ||||
self::INCLUDE_GUARD_INVALID, | self::INCLUDE_GUARD_INVALID, | ||||
pht("Include guard is malformed or missing. Expected format:\n". | pht("Include guard is malformed or missing. Expected format:\n". | ||||
"\t#ifndef %s\n". | "\t#ifndef %s\n". | ||||
"\t#define %s\n". | "\t#define %s\n". | ||||
"\t...\n". | "\t...\n". | ||||
"\t#endif // %s", $guard, $guard, $guard)); | "\t#endif // %s", $guard, $guard, $guard)); | ||||
} | } | ||||
} | } | ||||
} | } |