From a3c3d23dd7701f332daf0bfb87b0c83fc9c4c6fe Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 30 Dec 2014 10:02:43 -0800 Subject: [PATCH] Fix two linter issues Summary: - The "exclude static variable access" branch in XHPAST incorrectly excluded all variables in a function or method which used any static access (we were selecting the wrong root node for exclusion). - The "PHPLinter" regexp did not work with 5.4.30. Make it more permissive in what it parses. Test Plan: - Added a failing unit test for the variable case and made it pass. - PHPLinter tests now pass under 5.4.30 Reviewers: joshuaspence, btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D11087 --- src/lint/linter/ArcanistPhpLinter.php | 4 ++-- src/lint/linter/ArcanistXHPASTLinter.php | 10 +++++++--- .../__tests__/xhpast/naming-conventions.lint-test | 8 ++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/lint/linter/ArcanistPhpLinter.php b/src/lint/linter/ArcanistPhpLinter.php index 7daf7553..e4851e83 100644 --- a/src/lint/linter/ArcanistPhpLinter.php +++ b/src/lint/linter/ArcanistPhpLinter.php @@ -63,8 +63,8 @@ final class ArcanistPhpLinter extends ArcanistExternalLinter { // Combine $stdout and $stderr for consistency $stdout = $stderr."\n".$stdout; $matches = array(); - $regex = '/PHP (?.+?) error:\s+(?.*?)\s+in\s+(?.*?)'. - '\s+on line\s+(?\d*)/'; + $regex = '/^(?.+?) error:\s+(?.*?)\s+in\s+(?.*?)'. + '\s+on line\s+(?\d*)$/m'; if (preg_match($regex, $stdout, $matches)) { $type = strtolower($matches['type']); $message = new ArcanistLintMessage(); diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index 74682cc7..b43edad6 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -1902,9 +1902,13 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter { $statics = $def->selectDescendantsOfType('n_CLASS_STATIC_ACCESS'); foreach ($statics as $static) { $rhs = $static->getChildByIndex(1); - $rhs_vars = $def->selectDescendantsOfType('n_VARIABLE'); - foreach ($rhs_vars as $var) { - $exclude_tokens[$var->getID()] = true; + if ($rhs->getTypeName() == 'n_VARIABLE') { + $exclude_tokens[$rhs->getID()] = true; + } else { + $rhs_vars = $rhs->selectDescendantsOfType('n_VARIABLE'); + foreach ($rhs_vars as $var) { + $exclude_tokens[$var->getID()] = true; + } } } diff --git a/src/lint/linter/__tests__/xhpast/naming-conventions.lint-test b/src/lint/linter/__tests__/xhpast/naming-conventions.lint-test index 892d6e36..cc78e403 100644 --- a/src/lint/linter/__tests__/xhpast/naming-conventions.lint-test +++ b/src/lint/linter/__tests__/xhpast/naming-conventions.lint-test @@ -48,6 +48,13 @@ function i() { Other::$Y_y[0]; parent::$Z_z[0]; } + +function j() { + // Test case for bug where any static access would shadow other variables. + Other::$y = 0; + $mIxEdCaSe = 1; +} + ~~~~~~~~~~ warning:2:13 warning:3:9 @@ -65,3 +72,4 @@ warning:29:3 warning:30:3 warning:31:3 warning:33:3 +warning:55:3 -- 2.43.0