From: vrana Date: Mon, 23 Apr 2012 17:49:23 +0000 (-0700) Subject: Lint libraries without __init__ X-Git-Tag: conduit-4~39 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=cc1e4d467600c5ad6de6fb25e5db8b424dd401e2;p=arcanist.git 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 --- diff --git a/src/lint/linter/phutilmodule/ArcanistPhutilModuleLinter.php b/src/lint/linter/phutilmodule/ArcanistPhutilModuleLinter.php index b7c30665..747f21e7 100644 --- a/src/lint/linter/phutilmodule/ArcanistPhutilModuleLinter.php +++ b/src/lint/linter/phutilmodule/ArcanistPhutilModuleLinter.php @@ -86,6 +86,11 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter { return $info['module']; } + private function isModuleStandalone($key) { + $info = $this->moduleInfo[$key]; + return $info['standalone']; + } + private function isPhutilLibraryMetadata($path) { $file = basename($path); return !strncmp('__phutil_library_', $file, strlen('__phutil_library_')); @@ -123,14 +128,16 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter { if ($path == $library_root) { continue; } + $map = PhutilBootloader::getInstance()->getLibraryMap($library_name); $module_name = Filesystem::readablePath($path, $library_root); $module_key = $library_name.':'.$module_name; if (empty($modules[$module_key])) { $modules[$module_key] = $module_key; $this->setModuleInfo($module_key, array( - 'library' => $library_name, - 'root' => $library_root, - 'module' => $module_name, + 'library' => $library_name, + 'root' => $library_root, + 'module' => $module_name, + 'standalone' => !empty($map['standalone']), )); } } @@ -169,6 +176,10 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter { foreach ($requirements as $key => $requirement) { foreach ($requirement['messages'] as $message) { list($where, $text, $code, $description) = $message; + if ($this->isModuleStandalone($key) && + $code == self::LINT_ANALYZER_NO_INIT) { + continue; + } if ($where) { $where = array($where); } @@ -186,10 +197,12 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter { } else { list($library_name, $module_name) = explode(':', $req_module); $library_root = phutil_get_library_root($library_name); + $map = PhutilBootloader::getInstance()->getLibraryMap($library_name); $this->setModuleInfo($req_module, array( - 'library' => $library_name, - 'root' => $library_root, - 'module' => $module_name, + 'library' => $library_name, + 'root' => $library_root, + 'module' => $module_name, + 'standalone' => !empty($map['standalone']), )); $disk_path = $this->getModulePathOnDisk($req_module); if (Filesystem::pathExists($disk_path)) { @@ -235,13 +248,15 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter { $name, $deps); if (!$declared) { - $module = $this->getModuleDisplayName($key); - $message = $this->raiseLintInModule( - $key, - $lint_code, - "Module '{$module}' uses {$type} '{$name}' but does not include ". - "any module which declares it.", - $places); + if (!$this->isModuleStandalone($key)) { + $module = $this->getModuleDisplayName($key); + $message = $this->raiseLintInModule( + $key, + $lint_code, + "Module '{$module}' uses {$type} '{$name}' but does not include ". + "any module which declares it.", + $places); + } if ($type == 'class' || $type == 'interface') { $loader = new PhutilSymbolLoader(); @@ -259,8 +274,10 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter { $loaded = false; } if ($loaded) { - $resolvable[] = $message; - $need_classes[$name] = $class_spec; + if (!$this->isModuleStandalone($key)) { + $resolvable[] = $message; + $need_classes[$name] = $class_spec; + } } else { if (empty($this->unknownClasses[$name])) { $this->unknownClasses[$name] = true; @@ -302,8 +319,12 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter { $loaded = false; } if ($loaded) { - $resolvable[] = $message; - $need_functions[$name] = $func_spec; + // TODO: Check if the function is loaded in + // __phutil_library_init__.php for standalone modules. + if (!$this->isModuleStandalone($key)) { + $resolvable[] = $message; + $need_functions[$name] = $func_spec; + } } else { if (empty($this->unknownFunctions[$name])) { $this->unknownFunctions[$name] = true; @@ -360,14 +381,16 @@ final class ArcanistPhutilModuleLinter extends ArcanistLinter { } } - foreach ($spec['declares']['source'] as $file => $ignored) { - if (empty($spec['requires']['source'][$file])) { - $module = $this->getModuleDisplayName($key); - $resolvable[] = $this->raiseLintInModule( - $key, - self::LINT_UNUSED_SOURCE, - "Module '{$module}' does not include source file '{$file}'.", - null); + if (!$this->isModuleStandalone($key)) { + foreach ($spec['declares']['source'] as $file => $ignored) { + if (empty($spec['requires']['source'][$file])) { + $module = $this->getModuleDisplayName($key); + $resolvable[] = $this->raiseLintInModule( + $key, + self::LINT_UNUSED_SOURCE, + "Module '{$module}' does not include source file '{$file}'.", + null); + } } }