mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-02-23 12:09:09 +01:00
Lint libraries without __init__
Summary: After D2207. Test Plan: `arc lint` on D2208. `arc lint` on mistyped class name. Reviewers: epriestley Reviewed By: epriestley CC: aran, Koolvin Maniphest Tasks: T1103 Differential Revision: https://secure.phabricator.com/D2306
This commit is contained in:
parent
9c4c1de512
commit
cc1e4d4676
1 changed files with 48 additions and 25 deletions
|
@ -86,6 +86,11 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
|
||||||
return $info['module'];
|
return $info['module'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isModuleStandalone($key) {
|
||||||
|
$info = $this->moduleInfo[$key];
|
||||||
|
return $info['standalone'];
|
||||||
|
}
|
||||||
|
|
||||||
private function isPhutilLibraryMetadata($path) {
|
private function isPhutilLibraryMetadata($path) {
|
||||||
$file = basename($path);
|
$file = basename($path);
|
||||||
return !strncmp('__phutil_library_', $file, strlen('__phutil_library_'));
|
return !strncmp('__phutil_library_', $file, strlen('__phutil_library_'));
|
||||||
|
@ -123,6 +128,7 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
|
||||||
if ($path == $library_root) {
|
if ($path == $library_root) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$map = PhutilBootloader::getInstance()->getLibraryMap($library_name);
|
||||||
$module_name = Filesystem::readablePath($path, $library_root);
|
$module_name = Filesystem::readablePath($path, $library_root);
|
||||||
$module_key = $library_name.':'.$module_name;
|
$module_key = $library_name.':'.$module_name;
|
||||||
if (empty($modules[$module_key])) {
|
if (empty($modules[$module_key])) {
|
||||||
|
@ -131,6 +137,7 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
|
||||||
'library' => $library_name,
|
'library' => $library_name,
|
||||||
'root' => $library_root,
|
'root' => $library_root,
|
||||||
'module' => $module_name,
|
'module' => $module_name,
|
||||||
|
'standalone' => !empty($map['standalone']),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +176,10 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
|
||||||
foreach ($requirements as $key => $requirement) {
|
foreach ($requirements as $key => $requirement) {
|
||||||
foreach ($requirement['messages'] as $message) {
|
foreach ($requirement['messages'] as $message) {
|
||||||
list($where, $text, $code, $description) = $message;
|
list($where, $text, $code, $description) = $message;
|
||||||
|
if ($this->isModuleStandalone($key) &&
|
||||||
|
$code == self::LINT_ANALYZER_NO_INIT) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ($where) {
|
if ($where) {
|
||||||
$where = array($where);
|
$where = array($where);
|
||||||
}
|
}
|
||||||
|
@ -186,10 +197,12 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
|
||||||
} else {
|
} else {
|
||||||
list($library_name, $module_name) = explode(':', $req_module);
|
list($library_name, $module_name) = explode(':', $req_module);
|
||||||
$library_root = phutil_get_library_root($library_name);
|
$library_root = phutil_get_library_root($library_name);
|
||||||
|
$map = PhutilBootloader::getInstance()->getLibraryMap($library_name);
|
||||||
$this->setModuleInfo($req_module, array(
|
$this->setModuleInfo($req_module, array(
|
||||||
'library' => $library_name,
|
'library' => $library_name,
|
||||||
'root' => $library_root,
|
'root' => $library_root,
|
||||||
'module' => $module_name,
|
'module' => $module_name,
|
||||||
|
'standalone' => !empty($map['standalone']),
|
||||||
));
|
));
|
||||||
$disk_path = $this->getModulePathOnDisk($req_module);
|
$disk_path = $this->getModulePathOnDisk($req_module);
|
||||||
if (Filesystem::pathExists($disk_path)) {
|
if (Filesystem::pathExists($disk_path)) {
|
||||||
|
@ -235,6 +248,7 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
|
||||||
$name,
|
$name,
|
||||||
$deps);
|
$deps);
|
||||||
if (!$declared) {
|
if (!$declared) {
|
||||||
|
if (!$this->isModuleStandalone($key)) {
|
||||||
$module = $this->getModuleDisplayName($key);
|
$module = $this->getModuleDisplayName($key);
|
||||||
$message = $this->raiseLintInModule(
|
$message = $this->raiseLintInModule(
|
||||||
$key,
|
$key,
|
||||||
|
@ -242,6 +256,7 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
|
||||||
"Module '{$module}' uses {$type} '{$name}' but does not include ".
|
"Module '{$module}' uses {$type} '{$name}' but does not include ".
|
||||||
"any module which declares it.",
|
"any module which declares it.",
|
||||||
$places);
|
$places);
|
||||||
|
}
|
||||||
|
|
||||||
if ($type == 'class' || $type == 'interface') {
|
if ($type == 'class' || $type == 'interface') {
|
||||||
$loader = new PhutilSymbolLoader();
|
$loader = new PhutilSymbolLoader();
|
||||||
|
@ -259,8 +274,10 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
|
||||||
$loaded = false;
|
$loaded = false;
|
||||||
}
|
}
|
||||||
if ($loaded) {
|
if ($loaded) {
|
||||||
|
if (!$this->isModuleStandalone($key)) {
|
||||||
$resolvable[] = $message;
|
$resolvable[] = $message;
|
||||||
$need_classes[$name] = $class_spec;
|
$need_classes[$name] = $class_spec;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (empty($this->unknownClasses[$name])) {
|
if (empty($this->unknownClasses[$name])) {
|
||||||
$this->unknownClasses[$name] = true;
|
$this->unknownClasses[$name] = true;
|
||||||
|
@ -302,8 +319,12 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
|
||||||
$loaded = false;
|
$loaded = false;
|
||||||
}
|
}
|
||||||
if ($loaded) {
|
if ($loaded) {
|
||||||
|
// TODO: Check if the function is loaded in
|
||||||
|
// __phutil_library_init__.php for standalone modules.
|
||||||
|
if (!$this->isModuleStandalone($key)) {
|
||||||
$resolvable[] = $message;
|
$resolvable[] = $message;
|
||||||
$need_functions[$name] = $func_spec;
|
$need_functions[$name] = $func_spec;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (empty($this->unknownFunctions[$name])) {
|
if (empty($this->unknownFunctions[$name])) {
|
||||||
$this->unknownFunctions[$name] = true;
|
$this->unknownFunctions[$name] = true;
|
||||||
|
@ -360,6 +381,7 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->isModuleStandalone($key)) {
|
||||||
foreach ($spec['declares']['source'] as $file => $ignored) {
|
foreach ($spec['declares']['source'] as $file => $ignored) {
|
||||||
if (empty($spec['requires']['source'][$file])) {
|
if (empty($spec['requires']['source'][$file])) {
|
||||||
$module = $this->getModuleDisplayName($key);
|
$module = $this->getModuleDisplayName($key);
|
||||||
|
@ -370,6 +392,7 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter {
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($resolvable) {
|
if ($resolvable) {
|
||||||
$new_file = $this->buildNewModuleInit(
|
$new_file = $this->buildNewModuleInit(
|
||||||
|
|
Loading…
Add table
Reference in a new issue