Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2896842
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
16 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test b/src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test
index 6aacffdb..0f03a774 100644
--- a/src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test
+++ b/src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test
@@ -1,33 +1,33 @@
<?php
class MyClass {
- public function myfunc($var) {
- echo $var;
- }
+ public function myfunc($var) {
+ echo $var;
+ }
}
$myvar = true;
myfunc(&$myvar);
myfunc($myvar);
$this->myfunc(&$myvar);
$this->myfunc($myvar);
MyClass::myfunc(&$myvar);
MyClass::myfunc($myvar);
while (testfunc($var1, &$var2, $var3, &$var4) === false) {}
sprintf('0%o', 0777 & $p);
$foo(&$myvar);
-array_walk(array(), function() use (&$x) {});
+array_walk(array(), function () use (&$x) {});
MyClass::myfunc(array(&$x, &$y));
~~~~~~~~~~
error:2:7 XHP19
error:9:8
error:12:15
error:15:17
error:18:24
error:18:39
error:22:6
diff --git a/src/lint/linter/__tests__/xhpast/decl-parens-hug-closing.lint-test b/src/lint/linter/__tests__/xhpast/decl-parens-hug-closing.lint-test
index c6accb15..be9438e3 100644
--- a/src/lint/linter/__tests__/xhpast/decl-parens-hug-closing.lint-test
+++ b/src/lint/linter/__tests__/xhpast/decl-parens-hug-closing.lint-test
@@ -1,61 +1,65 @@
<?php
function f($x) {}
function g($x ) {}
function h ($x) {}
function &i($x) {}
function &j($x ) {}
final class X {
public function a($x) {}
public function b($x ) {}
public static function &c($x) {}
public static function &d($x ) {}
abstract private function e($x);
abstract private function f($x );
}
-f(function($x) {});
-f(function($x ) {});
-f(function($x ) use ($z) {});
+f(function ($x) {});
+f(function ($x ) {});
+f(function ($x ) use ($z) {});
+f(function ($x)use($z) {});
~~~~~~~~~~
warning:4:14
warning:5:11
warning:8:15
error:10:13
warning:13:23
warning:16:31
warning:19:33
-warning:24:14
-warning:25:14
+warning:24:15
+warning:25:15
+warning:26:16
+warning:26:19
~~~~~~~~~~
<?php
function f($x) {}
function g($x) {}
function h($x) {}
function &i($x) {}
function &j($x) {}
final class X {
public function a($x) {}
public function b($x) {}
public static function &c($x) {}
public static function &d($x) {}
abstract private function e($x);
abstract private function f($x);
}
-f(function($x) {});
-f(function($x) {});
-f(function($x) use ($z) {});
+f(function ($x) {});
+f(function ($x) {});
+f(function ($x) use ($z) {});
+f(function ($x) use ($z) {});
diff --git a/src/lint/linter/__tests__/xhpast/inner-function.lint-test b/src/lint/linter/__tests__/xhpast/inner-function.lint-test
index 38d0ca15..6294eb0a 100644
--- a/src/lint/linter/__tests__/xhpast/inner-function.lint-test
+++ b/src/lint/linter/__tests__/xhpast/inner-function.lint-test
@@ -1,14 +1,14 @@
<?php
function outer() {
if (!function_exists('inner')) {
function inner() {}
}
}
// Closures are allowed.
function my_func($foo) {
- function() {};
+ function () {};
}
~~~~~~~~~~
warning:5:5
diff --git a/src/lint/linter/__tests__/xhpast/naming-conventions.lint-test b/src/lint/linter/__tests__/xhpast/naming-conventions.lint-test
index 3bf1a71a..cc78e403 100644
--- a/src/lint/linter/__tests__/xhpast/naming-conventions.lint-test
+++ b/src/lint/linter/__tests__/xhpast/naming-conventions.lint-test
@@ -1,75 +1,75 @@
<?php
final class a {
const b = 1, c = d;
protected $E, $H;
public function F($G, $GG) {}
}
interface i {}
function YY($ZZ) {}
final class Quack {
const R = 1, S = 2;
protected $tX, $uY;
public function vV($w_w) {}
}
-function() use ($this_is_a_closure) {};
+function () use ($this_is_a_closure) {};
function f(&$YY) {}
function g() {
$lowerCamelCase = 0;
$UpperCamelCase = 0;
$UPPERCASE_WITH_UNDERSCORES = 0;
$lowercase_with_underscores = 0;
$mIxEd_CaSe = 0;
}
function h() {
global $mIxEd_CaSe;
$mIxEd_CaSe = 2;
$GLOBALS[0] = 2;
$_ENV[0] = 1;
}
function i() {
self::$X_x;
Other::$Y_y;
parent::$Z_z;
self::$X_x[0];
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
warning:3:16
warning:4:13
warning:4:17
warning:5:19
warning:5:21
warning:5:25
warning:8:11
warning:12:10
warning:12:13
warning:26:13
warning:29:3
warning:30:3
warning:31:3
warning:33:3
warning:55:3
diff --git a/src/lint/linter/__tests__/xhpast/php53-features.lint-test b/src/lint/linter/__tests__/xhpast/php53-features.lint-test
index 6417a56d..a2237293 100644
--- a/src/lint/linter/__tests__/xhpast/php53-features.lint-test
+++ b/src/lint/linter/__tests__/xhpast/php53-features.lint-test
@@ -1,29 +1,27 @@
<?php
namespace a;
use b, c;
-f(function() {});
-g(function() use ($c) {});
-h(function /* ! */ () use ($c) {});
+f(function () {});
+g(function () use ($c) {});
static::m();
1 ? 1 : 2;
1 ?: 2;
$a = 'stdClass';
$a::m();
echo __DIR__;
~~~~~~~~~~
error:3:1
error:4:5
error:5:3
error:6:3
-error:7:3
-error:8:1
-error:10:1
-error:13:6
+error:7:1
+error:9:1
+error:12:6
~~~~~~~~~~
~~~~~~~~~~
{
"config": {
"xhpast.php-version": "5.2.3"
}
}
diff --git a/src/lint/linter/__tests__/xhpast/reused-iterator-reference.lint-test b/src/lint/linter/__tests__/xhpast/reused-iterator-reference.lint-test
index cbfa13b1..ac65ff57 100644
--- a/src/lint/linter/__tests__/xhpast/reused-iterator-reference.lint-test
+++ b/src/lint/linter/__tests__/xhpast/reused-iterator-reference.lint-test
@@ -1,133 +1,133 @@
<?php
function assign() {
$ar = array();
foreach ($ar as &$a) {}
$a = 1; // Reuse of $a.
}
function expr() {
$ar = array();
foreach ($ar as &$a) {}
$b = $a; // Reuse of $a.
}
function func_call() {
$ar = array();
foreach ($ar as &$a) {}
$b = x($a); // Reuse of $a.
}
function x($b) {}
function iterator_reuse() {
$ar1 = array();
$ar2 = array();
foreach ($ar1 as &$a) {}
foreach ($ar2 as $a) {} // Reuse of $a
}
function key_value() {
$ar = array();
foreach ($ar as $k => &$v) {}
$v++; // Reuse of $v
}
function key_value2() {
$ar = array();
foreach ($ar as $k => $v) {}
$v++;
}
function unset() {
$ar = array();
foreach ($ar as &$a) {}
unset($a);
$a++;
}
function unset2() {
$ar = array();
foreach ($ar as &$a) {}
$a++; // Reuse of $a
unset($a);
}
function twice_ref() {
$ar1 = array();
$ar2 = array();
foreach ($ar1 as &$b) {}
foreach ($ar2 as &$b) {}
}
function assign_ref(&$a) {
$ar = array();
foreach ($ar as &$b) {}
$b = &$a;
}
function assign_ref2(&$a) {
$ar = array();
foreach ($ar as &$b) {}
$b = &$a;
$c = $b;
}
function use_inside() {
$ar = array();
foreach ($ar as &$a) {
$a++;
}
}
function variable_variable() {
$ar = array();
foreach ($ar as &$$a) {}
$a++;
$$a++;
}
function closure1() {
$ar = array();
foreach ($ar as &$a) {}
- function($a) {
+ function ($a) {
$a++;
};
}
function closure2() {
- function() {
+ function () {
$ar = array();
foreach ($ar as &$a) {}
};
$a++;
}
function closure3() {
- function() {
+ function () {
$ar = array();
foreach ($ar as &$a) {}
$a++; // Reuse of $a
};
}
function closure4() {
$ar = array();
foreach ($ar as &$a) {}
- function($a) {
+ function ($a) {
unset($a);
};
$a++; // Reuse of $a
}
~~~~~~~~~~
warning:6:3
warning:12:8
warning:18:10
warning:27:20
warning:33:3
warning:52:3
error:85:20
error:87:3
warning:110:5
warning:120:3
diff --git a/src/lint/linter/__tests__/xhpast/switches.lint-test b/src/lint/linter/__tests__/xhpast/switches.lint-test
index 89e97069..6c6fa944 100644
--- a/src/lint/linter/__tests__/xhpast/switches.lint-test
+++ b/src/lint/linter/__tests__/xhpast/switches.lint-test
@@ -1,100 +1,100 @@
<?php
$x = 0;
$y = 0;
switch ($x) {
case 1:
$x++;
continue;
case 2:
$x++;
break;
case 3:
$x++;
return;
case 4:
$x++;
throw new Exception('!');
case 5:
break 2;
case 6:
continue 2;
case 7:
case 8:
$x++;
break;
case 9:
$x++;
/* fallthrough */
case 10:
$x++;
break;
case 11:
$x++;
exit(1);
default:
break;
}
switch ($x) {
case 1:
$x++;
case 2:
break;
}
switch ($x) {
default:
$x++;
}
switch ($x) {
case 1:
while (true) {
break;
}
case 2:
switch ($y) {
case 1:
break;
}
case 3:
while (true) {
return;
}
case 4:
function f() { throw new Exception(); }
- g(function() { return; });
+ g(function () { return; });
final class C { public function m() { return; } }
interface I {}
case 5:
do {
break;
} while (true);
case 6:
// We accept this "false" positive because the construction is bizarre and
// the author can easily add an unreachable "break;" for clarity.
do {
break 2;
} while (true);
case 7:
/* fallthrough */
case 8:
throw_exception();
}
~~~~~~~~~~
warning:41:3
warning:48:3
warning:53:3
warning:57:3
warning:66:3
warning:71:3
warning:75:3
~~~~~~~~~~
~~~~~~~~~~
{
"config":{
"xhpast.switchhook":"ArcanistTestXHPASTLintSwitchHook"
}
}
diff --git a/src/lint/linter/__tests__/xhpast/undeclared-variables.lint-test b/src/lint/linter/__tests__/xhpast/undeclared-variables.lint-test
index 903e620a..c6cd1b40 100644
--- a/src/lint/linter/__tests__/xhpast/undeclared-variables.lint-test
+++ b/src/lint/linter/__tests__/xhpast/undeclared-variables.lint-test
@@ -1,201 +1,201 @@
<?php
-function() use ($c) {
+function () use ($c) {
$c++;
};
function f($a, $b) {
static $c, $d;
global $e, $f;
$g = $h = x();
list($i, list($j, $k)) = y();
foreach (q() as $l => $m) {}
$a++;
$b++;
$c++;
$d++;
$e++;
$f++;
$g++;
$h++;
$i++;
$j++;
$k++;
$l++;
$m++;
$this++;
$n++; // Only one that isn't declared.
extract(z());
$o++;
}
function g($q) {
$$q = x();
$r = y();
}
final class C {
public function m() {
$a++;
x($b);
$c[] = 3;
$d->v = 4;
$a = $f;
}
}
function worst() {
global $$x;
$y++;
}
function superglobals() {
$GLOBALS[$_FILES[$_POST[$this]]]++;
}
function ref_foreach($x) {
foreach ($x as &$z) {}
$z++;
}
function has_default($x = 0) {
$x++;
}
function declparse(
$a,
Q $b,
Q &$c,
Q $d = null,
Q &$e = null,
$f = null,
$g = null,
&$h = null,
&$i = null) {
$a++;
$b++;
$c++;
$d++;
$e++;
$f++;
$g++;
$h++;
$i++;
$j++;
}
function declparse_a(Q $a) { $a++; }
function declparse_b(Q &$a) { $a++; }
function declparse_c(Q $a = null) { $a++; }
function declparse_d(Q &$a = null) { $a++; }
function declparse_e($a) { $a++; }
function declparse_f(&$a) { $a++; }
function declparse_g($a = null) { $a++; }
function declparse_h(&$a = null) { $a++; }
function static_class() {
SomeClass::$x;
}
function instance_class() {
$a = $this->$x;
}
function exception_vars() {
try {
// This is intentionally left blank.
} catch (Exception $y) {
$y++;
}
}
function nonuse() {
isset($x);
empty($y);
$x++;
}
function twice() {
$y++;
$y++;
}
function more_exceptions() {
try {
// This is intentionally left blank.
} catch (Exception $a) {
$a++;
} catch (Exception $b) {
$b++;
}
}
abstract class P {
abstract public function q();
}
function x() {
$lib = $_SERVER['PHP_ROOT'].'/lib/titan/display/read/init.php';
require_once $lib;
f(((($lib)))); // Tests for paren expressions.
f(((($lub))));
}
final class A {
public function foo($a) {
$im_service = foo($a);
if ($im_servce === false) {
return 1;
}
return 2;
}
}
function arrow($o, $x) {
echo $o->{$x->{$x->{$x.$x->{$x}}.$x}};
}
function strings() {
$a = 1;
echo "$a";
echo "$b";
}
function catchy() {
try {
dangerous();
} catch (Exception $ex) {
$y->z();
}
}
function some_func($x, $y) {
- $func = function($z) use ($x) {
+ $func = function ($z) use ($x) {
echo $x;
echo $y;
echo $z;
};
}
~~~~~~~~~~
error:28:3
error:30:3
error:36:3
error:42:5
error:43:7
error:44:5
error:45:5
error:46:10
error:51:10 worst ever
warning:61:3
error:87:3 This stuff is basically testing the lexer/parser for function decls.
error:104:15 Variables in instance derefs should be checked, static should not.
error:118:3 isset() and empty() should not trigger errors.
error:122:3 Should only warn once in this function.
error:144:8
error:150:9
error:164:9
error:171:5
error:178:10
diff --git a/src/lint/linter/xhpast/rules/ArcanistDeclarationParenthesesXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistDeclarationParenthesesXHPASTLinterRule.php
index 357ac77f..6606b0b3 100644
--- a/src/lint/linter/xhpast/rules/ArcanistDeclarationParenthesesXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistDeclarationParenthesesXHPASTLinterRule.php
@@ -1,57 +1,97 @@
<?php
final class ArcanistDeclarationParenthesesXHPASTLinterRule
extends ArcanistXHPASTLinterRule {
const ID = 38;
public function getLintName() {
return pht('Declaration Formatting');
}
public function getLintSeverity() {
return ArcanistLintSeverity::SEVERITY_WARNING;
}
public function process(XHPASTNode $root) {
$decs = $root->selectDescendantsOfTypes(array(
'n_FUNCTION_DECLARATION',
'n_METHOD_DECLARATION',
));
foreach ($decs as $dec) {
$params = $dec->getChildOfType(3, 'n_DECLARATION_PARAMETER_LIST');
$tokens = $params->getTokens();
$first = head($tokens);
- $last = last($tokens);
+ $last = last($tokens);
$leading = $first->getNonsemanticTokensBefore();
$leading_text = implode('', mpull($leading, 'getValue'));
$trailing = $last->getNonsemanticTokensBefore();
$trailing_text = implode('', mpull($trailing, 'getValue'));
- if (preg_match('/^\s+$/', $leading_text)) {
- $this->raiseLintAtOffset(
- $first->getOffset() - strlen($leading_text),
- pht(
- 'Convention: no spaces before opening parenthesis in '.
- 'function and method declarations.'),
- $leading_text,
- '');
+ if ($dec->getChildByIndex(2)->getTypeName() == 'n_EMPTY') {
+ // Anonymous functions.
+ if ($leading_text != ' ') {
+ $this->raiseLintAtOffset(
+ $first->getOffset() - strlen($leading_text),
+ pht(
+ 'Convention: space before opening parenthesis in '.
+ 'anonymous function declarations.'),
+ $leading_text,
+ ' ');
+ }
+ } else {
+ if (preg_match('/^\s+$/', $leading_text)) {
+ $this->raiseLintAtOffset(
+ $first->getOffset() - strlen($leading_text),
+ pht(
+ 'Convention: no spaces before opening parenthesis in '.
+ 'function and method declarations.'),
+ $leading_text,
+ '');
+ }
}
if (preg_match('/^\s+$/', $trailing_text)) {
$this->raiseLintAtOffset(
$last->getOffset() - strlen($trailing_text),
pht(
'Convention: no spaces before closing parenthesis in '.
'function and method declarations.'),
$trailing_text,
'');
}
+
+ $use_list = $dec->getChildByIndex(4);
+ if ($use_list->getTypeName() == 'n_EMPTY') {
+ continue;
+ }
+ $use_token = $use_list->selectTokensOfType('T_USE');
+
+ foreach ($use_token as $use) {
+ $before = $use->getNonsemanticTokensBefore();
+ $after = $use->getNonsemanticTokensAfter();
+
+ if (!$before) {
+ $this->raiseLintAtOffset(
+ $use->getOffset(),
+ pht('Convention: space before `%s` token.', 'use'),
+ '',
+ ' ');
+ }
+
+ if (!$after) {
+ $this->raiseLintAtOffset(
+ $use->getOffset() + strlen($use->getValue()),
+ pht('Convention: space after `%s` token.', 'use'),
+ '',
+ ' ');
+ }
+ }
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Jan 19 2025, 23:39 (6 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1129989
Default Alt Text
(16 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment