1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 16:22:42 +01:00

Minor tidying of ArcanistPhutilLibraryLinter

Summary: Self-explanatory.

Test Plan: Eyeball it.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D11330
This commit is contained in:
Joshua Spence 2015-01-15 21:51:26 +11:00
parent 272f737110
commit 6694834f29

View file

@ -20,24 +20,30 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
public function getInfoDescription() { public function getInfoDescription() {
return pht( return pht(
'Make sure all the symbols use in a libphutil library are defined and '. 'Make sure all the symbols used in a %s library are defined and known. '.
'known. This linter is specific to PHP source in libphutil libraries.'); 'This linter is specific to PHP source in %s libraries.',
'libphutil',
'libphutil');
}
public function getLinterName() {
return 'PHL';
} }
public function getLinterConfigurationName() { public function getLinterConfigurationName() {
return 'phutil-library'; return 'phutil-library';
} }
public function getLintNameMap() { public function getCacheGranularity() {
return array( return self::GRANULARITY_GLOBAL;
self::LINT_UNKNOWN_SYMBOL => pht('Unknown Symbol'),
self::LINT_DUPLICATE_SYMBOL => pht('Duplicate Symbol'),
self::LINT_ONE_CLASS_PER_FILE => pht('One Class Per File'),
);
} }
public function getLinterName() { public function getLintNameMap() {
return 'PHL'; return array(
self::LINT_UNKNOWN_SYMBOL => pht('Unknown Symbol'),
self::LINT_DUPLICATE_SYMBOL => pht('Duplicate Symbol'),
self::LINT_ONE_CLASS_PER_FILE => pht('One Class Per File'),
);
} }
public function getLinterPriority() { public function getLinterPriority() {
@ -55,18 +61,19 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
// caches. // caches.
$bootloader = PhutilBootloader::getInstance(); $bootloader = PhutilBootloader::getInstance();
$libs = $bootloader->getAllLibraries(); $libraries = $bootloader->getAllLibraries();
// Load the up-to-date map for each library, without loading the library // Load the up-to-date map for each library, without loading the library
// itself. This means lint results will accurately reflect the state of // itself. This means lint results will accurately reflect the state of
// the working copy. // the working copy.
$symbols = array(); $symbols = array();
foreach ($libs as $lib) {
$root = phutil_get_library_root($lib); foreach ($libraries as $library) {
$root = phutil_get_library_root($library);
try { try {
$symbols[$lib] = id(new PhutilLibraryMapBuilder($root)) $symbols[$library] = id(new PhutilLibraryMapBuilder($root))
->buildFileSymbolMap(); ->buildFileSymbolMap();
} catch (XHPASTSyntaxErrorException $ex) { } catch (XHPASTSyntaxErrorException $ex) {
// If the library contains a syntax error then there isn't much that we // If the library contains a syntax error then there isn't much that we
@ -97,10 +104,13 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
$file, $file,
end($have_functions), end($have_functions),
self::LINT_ONE_CLASS_PER_FILE, self::LINT_ONE_CLASS_PER_FILE,
"File '{$file}' mixes function ({$function_list}) and ". pht(
"class/interface ({$class_list}) definitions in the same file. ". "File '%s' mixes function (%s) and class/interface (%s) ".
"A file which declares a class or an interface MUST ". "definitions in the same file. A file which declares a class ".
"declare nothing else."); "or an interface MUST declare nothing else.",
$file,
$function_list,
$class_list));
} else if (count($have_classes) > 1) { } else if (count($have_classes) > 1) {
$class_list = implode(', ', array_keys($have_classes)); $class_list = implode(', ', array_keys($have_classes));
$this->raiseLintInLibrary( $this->raiseLintInLibrary(
@ -108,9 +118,12 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
$file, $file,
end($have_classes), end($have_classes),
self::LINT_ONE_CLASS_PER_FILE, self::LINT_ONE_CLASS_PER_FILE,
"File '{$file}' declares more than one class or interface ". pht(
"({$class_list}). A file which declares a class or interface MUST ". "File '%s' declares more than one class or interface (%s). ".
"declare nothing else."); "A file which declares a class or interface MUST declare ".
"nothing else.",
$file,
$class_list));
} }
} }
@ -138,9 +151,15 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
$file, $file,
$offset, $offset,
self::LINT_DUPLICATE_SYMBOL, self::LINT_DUPLICATE_SYMBOL,
"Definition of {$type} '{$symbol}' in '{$file}' in library ". pht(
"'{$library}' duplicates prior definition in '{$osrc}' in ". "Definition of %s '%s' in '%s' in library '%s' duplicates ".
"library '{$olib}'."); "prior definition in '%s' in library '%s'.",
$type,
$symbol,
$file,
$library,
$osrc,
$olib));
} }
} }
} }
@ -171,26 +190,29 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
$file, $file,
$offset, $offset,
self::LINT_UNKNOWN_SYMBOL, self::LINT_UNKNOWN_SYMBOL,
"Use of unknown {$type} '{$symbol}'. Common causes are:\n\n". pht(
" - Your libphutil/ is out of date.\n". "Use of unknown %s '%s'. Common causes are:\n\n".
" This is the most common cause.\n". " - Your %s is out of date.\n".
" Update this copy of libphutil: {$libphutil_root}\n". " This is the most common cause.\n".
"\n". " Update this copy of libphutil: %s\n\n".
" - Some other library is out of date.\n". " - Some other library is out of date.\n".
" Update the library this symbol appears in.\n". " Update the library this symbol appears in.\n\n".
"\n". " - This symbol is misspelled.\n".
" - This symbol is misspelled.\n". " Spell the symbol name correctly.\n".
" Spell the symbol name correctly.\n". " Symbol name spelling is case-sensitive.\n\n".
" Symbol name spelling is case-sensitive.\n". " - This symbol was added recently.\n".
"\n". " Run `%s` on the library it was added to.\n\n".
" - This symbol was added recently.\n". " - This symbol is external. Use `%s`.\n".
" Run `arc liberate` on the library it was added to.\n". " Use `%s` to find usage examples of this directive.\n\n".
"\n". "*** ALTHOUGH USUALLY EASY TO FIX, THIS IS A SERIOUS ERROR.\n".
" - This symbol is external. Use `@phutil-external-symbol`.\n". "*** THIS ERROR IS YOUR FAULT. YOU MUST RESOLVE IT.",
" Use `grep` to find usage examples of this directive.\n". $type,
"\n". $symbol,
"*** ALTHOUGH USUALLY EASY TO FIX, THIS IS A SERIOUS ERROR.\n". 'libphutil/',
"*** THIS ERROR IS YOUR FAULT. YOU MUST RESOLVE IT."); $libphutil_root,
'arc liberate',
'@phutil-external-symbol',
'grep'));
} }
} }
} }
@ -208,8 +230,4 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
return; return;
} }
public function getCacheGranularity() {
return self::GRANULARITY_GLOBAL;
}
} }