diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index bdc96826..546cdac8 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -149,6 +149,7 @@ phutil_register_library_map(array( 'ArcanistXHPASTLintNamingHook' => 'lint/linter/xhpast/ArcanistXHPASTLintNamingHook.php', 'ArcanistXHPASTLintNamingHookTestCase' => 'lint/linter/xhpast/__tests__/ArcanistXHPASTLintNamingHookTestCase.php', 'ArcanistXHPASTLintSwitchHook' => 'lint/linter/xhpast/ArcanistXHPASTLintSwitchHook.php', + 'ArcanistXHPASTLintTestSwitchHook' => 'lint/linter/__tests__/ArcanistXHPASTLintTestSwitchHook.php', 'ArcanistXHPASTLinter' => 'lint/linter/ArcanistXHPASTLinter.php', 'ArcanistXHPASTLinterTestCase' => 'lint/linter/__tests__/ArcanistXHPASTLinterTestCase.php', 'ComprehensiveLintEngine' => 'lint/engine/ComprehensiveLintEngine.php', @@ -275,6 +276,7 @@ phutil_register_library_map(array( 'ArcanistUserAbortException' => 'ArcanistUsageException', 'ArcanistWhichWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistXHPASTLintNamingHookTestCase' => 'ArcanistTestCase', + 'ArcanistXHPASTLintTestSwitchHook' => 'ArcanistXHPASTLintSwitchHook', 'ArcanistXHPASTLinter' => 'ArcanistBaseXHPASTLinter', 'ArcanistXHPASTLinterTestCase' => 'ArcanistArcanistLinterTestCase', 'ComprehensiveLintEngine' => 'ArcanistLintEngine', diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index 886236be..5501cd1f 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -157,7 +157,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter { } public function getCacheVersion() { - $version = '3'; + $version = '4'; $path = xhpast_get_binary_path(); if (Filesystem::pathExists($path)) { $version .= '-'.md5_file($path); @@ -480,6 +480,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter { $working_copy = $this->getEngine()->getWorkingCopy(); if ($working_copy) { $hook_class = $working_copy->getConfig('lint.xhpast.switchhook'); + $hook_class = $this->getConfig('switchhook', $hook_class); if ($hook_class) { $hook_obj = newv($hook_class, array()); assert_instances_of(array($hook_obj), 'ArcanistXHPASTLintSwitchHook'); diff --git a/src/lint/linter/__tests__/ArcanistXHPASTLintTestSwitchHook.php b/src/lint/linter/__tests__/ArcanistXHPASTLintTestSwitchHook.php new file mode 100644 index 00000000..35997eb0 --- /dev/null +++ b/src/lint/linter/__tests__/ArcanistXHPASTLintTestSwitchHook.php @@ -0,0 +1,16 @@ +getTypeName() == 'T_STRING') { + switch (strtolower($token->getValue())) { + case 'throw_exception': + return true; + } + } + return false; + } + +} diff --git a/src/lint/linter/__tests__/xhpast/switches.lint-test b/src/lint/linter/__tests__/xhpast/switches.lint-test index 0e4aafed..b32d55cd 100644 --- a/src/lint/linter/__tests__/xhpast/switches.lint-test +++ b/src/lint/linter/__tests__/xhpast/switches.lint-test @@ -78,6 +78,10 @@ switch ($x) { do { break 2; } while (true); + case 7: + /* fallthrough */ + case 8: + throw_exception(); } ~~~~~~~~~~ warning:41:3 @@ -87,4 +91,7 @@ warning:57:3 warning:66:3 disabled:68:7 # PHP 5.3 features warning:71:3 -warning:75:3 \ No newline at end of file +warning:75:3 +~~~~~~~~~~ +~~~~~~~~~~ +{"config":{"switchhook":"ArcanistXHPASTLintTestSwitchHook"}}