mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-01-10 23:01:04 +01:00
Add unit tests for implicit fallthrough lint rule
Summary: The perf fix actually catches some real problems. I didn't find anything in libphutil, Arcanist and Phabricator though. Also bump version. Also allow configuring the hook. Test Plan: Added a test, saw it fail with the old code. Repeat for hook. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D5097
This commit is contained in:
parent
8ec038291a
commit
0b120bd04b
4 changed files with 28 additions and 2 deletions
|
@ -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',
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class ArcanistXHPASTLintTestSwitchHook
|
||||
extends ArcanistXHPASTLintSwitchHook {
|
||||
|
||||
public function checkSwitchToken(XHPASTToken $token) {
|
||||
if ($token->getTypeName() == 'T_STRING') {
|
||||
switch (strtolower($token->getValue())) {
|
||||
case 'throw_exception':
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
warning:75:3
|
||||
~~~~~~~~~~
|
||||
~~~~~~~~~~
|
||||
{"config":{"switchhook":"ArcanistXHPASTLintTestSwitchHook"}}
|
||||
|
|
Loading…
Reference in a new issue