'ArcanistWorkingCopyIdentity' => 'workingcopyidentity/ArcanistWorkingCopyIdentity.php',
'ArcanistXHPASTLintNamingHook' => 'lint/linter/xhpast/ArcanistXHPASTLintNamingHook.php',
'ArcanistXHPASTLintNamingHookTestCase' => 'lint/linter/xhpast/__tests__/ArcanistXHPASTLintNamingHookTestCase.php',
+ 'ArcanistXHPASTLintSwitchHook' => 'lint/linter/xhpast/ArcanistXHPASTLintSwitchHook.php',
'ArcanistXHPASTLinter' => 'lint/linter/ArcanistXHPASTLinter.php',
'ArcanistXHPASTLinterTestCase' => 'lint/linter/__tests__/ArcanistXHPASTLinterTestCase.php',
'ComprehensiveLintEngine' => 'lint/engine/ComprehensiveLintEngine.php',
}
private function lintImplicitFallthrough($root) {
+ $hook_obj = null;
+ $working_copy = $this->getEngine()->getWorkingCopy();
+ if ($working_copy) {
+ $hook_class = $working_copy->getConfig('lint.xhpast.switchhook');
+ if ($hook_class) {
+ $hook_obj = newv($hook_class, array());
+ assert_instances_of(array($hook_obj), 'ArcanistXHPASTLintSwitchHook');
+ }
+ }
+
$switches = $root->selectDescendantsOfType('n_SWITCH');
foreach ($switches as $switch) {
$blocks = array();
if ($tok_type == 'T_RETURN' ||
$tok_type == 'T_THROW' ||
- $tok_type == 'T_EXIT') {
+ $tok_type == 'T_EXIT' ||
+ ($hook_obj && $hook_obj->checkSwitchToken($token))) {
if (empty($different_scope_tokens[$token_id])) {
$statement_ok = true;
$block_ok = true;
--- /dev/null
+<?php
+
+/**
+ * You can extend this class and set `lint.xhpast.switchhook` in your
+ * `.arcconfig` to have an opportunity to override results for linting `switch`
+ * statements.
+ *
+ * @group lint
+ */
+abstract class ArcanistXHPASTLintSwitchHook {
+
+ /**
+ * @return bool True if token safely ends the block.
+ */
+ abstract public function checkSwitchToken(XHPASTToken $token);
+
+}