]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add a linter rule for newlines after PHP open tags
authorJoshua Spence <josh@joshuaspence.com>
Sun, 30 Aug 2015 20:49:29 +0000 (06:49 +1000)
committerJoshua Spence <josh@freelancer.com>
Sun, 30 Aug 2015 20:49:29 +0000 (06:49 +1000)
Summary: `<?php\n\n...` is much easier to read than `<?php\n...`. Depends on D13889 and D13890.

Test Plan: Added unit tests.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D13534

58 files changed:
src/__phutil_library_map__.php
src/lint/linter/__tests__/xhpast/array-comma.lint-test
src/lint/linter/__tests__/xhpast/array-index.lint-test
src/lint/linter/__tests__/xhpast/blacklisted.lint-test
src/lint/linter/__tests__/xhpast/call-time-pass-by-reference.lint-test
src/lint/linter/__tests__/xhpast/cast-spacing.lint-test
src/lint/linter/__tests__/xhpast/class-name-literal.lint-test
src/lint/linter/__tests__/xhpast/constant-case.lint-test
src/lint/linter/__tests__/xhpast/constructor-parentheses.lint-test
src/lint/linter/__tests__/xhpast/default-parameters.lint-test
src/lint/linter/__tests__/xhpast/double-quote.lint-test
src/lint/linter/__tests__/xhpast/duplicate-key-in-array.lint-test
src/lint/linter/__tests__/xhpast/duplicate-switch-case.lint-test
src/lint/linter/__tests__/xhpast/dynamic-define.lint-test
src/lint/linter/__tests__/xhpast/elseif.lint-test
src/lint/linter/__tests__/xhpast/empty-block-statement.lint-test
src/lint/linter/__tests__/xhpast/empty-statement.lint-test
src/lint/linter/__tests__/xhpast/exit-expression.lint-test
src/lint/linter/__tests__/xhpast/formatted-string.lint-test
src/lint/linter/__tests__/xhpast/global-variables.lint-test
src/lint/linter/__tests__/xhpast/hash-comments.lint-test
src/lint/linter/__tests__/xhpast/implicit-visibility.lint-test
src/lint/linter/__tests__/xhpast/index-function.lint-test
src/lint/linter/__tests__/xhpast/instanceof-operator.lint-test
src/lint/linter/__tests__/xhpast/invalid-default-parameter.lint-test [moved from src/lint/linter/__tests__/xhpast/invalid-default-paramter.lint-test with 91% similarity]
src/lint/linter/__tests__/xhpast/invalid-modifiers.lint-test
src/lint/linter/__tests__/xhpast/lamba-func-function.lint-test
src/lint/linter/__tests__/xhpast/language-construct-parentheses.lint-test
src/lint/linter/__tests__/xhpast/list-assignment.lint-test
src/lint/linter/__tests__/xhpast/lowercase-functions.lint-test
src/lint/linter/__tests__/xhpast/modifier-ordering.lint-test
src/lint/linter/__tests__/xhpast/naming-conventions.lint-test
src/lint/linter/__tests__/xhpast/newline-after-open-tag.lint-test [new file with mode: 0644]
src/lint/linter/__tests__/xhpast/no-segfault-on-abstract.lint-test
src/lint/linter/__tests__/xhpast/no-segfault-on-exit.lint-test
src/lint/linter/__tests__/xhpast/nowdoc.lint-test
src/lint/linter/__tests__/xhpast/object-operating-spacing.lint-test
src/lint/linter/__tests__/xhpast/parens-hug-contents.lint-test
src/lint/linter/__tests__/xhpast/php54-incompat.lint-test
src/lint/linter/__tests__/xhpast/preg-quote.lint-test
src/lint/linter/__tests__/xhpast/reused-iterator-reference.lint-test
src/lint/linter/__tests__/xhpast/reused-local.lint-test
src/lint/linter/__tests__/xhpast/semicolon-spacing.lint-test
src/lint/linter/__tests__/xhpast/single-pass-adjacent-patches.lint-test
src/lint/linter/__tests__/xhpast/space-after-control-keywords.lint-test
src/lint/linter/__tests__/xhpast/space-around-more-operators.lint-test
src/lint/linter/__tests__/xhpast/space-around-operators.lint-test
src/lint/linter/__tests__/xhpast/surprising-constructors.lint-test
src/lint/linter/__tests__/xhpast/tautological-expressions.lint-test
src/lint/linter/__tests__/xhpast/tostring-exception.lint-test
src/lint/linter/__tests__/xhpast/unary-postfix-expression-spacing.lint-test
src/lint/linter/__tests__/xhpast/unary-prefix-expression-spacing.lint-test
src/lint/linter/__tests__/xhpast/unnecessary-final-modifier.lint-test
src/lint/linter/__tests__/xhpast/unreasonably-deep-nesting.lint-test
src/lint/linter/__tests__/xhpast/use-of-this-in-static-method.lint-test
src/lint/linter/__tests__/xhpast/variable-variables.lint-test
src/lint/linter/__tests__/xhpast/wrong-concat-operator.lint-test
src/lint/linter/xhpast/rules/ArcanistNewlineAfterOpenTagXHPASTLinterRule.php [new file with mode: 0644]

index 722bea0adef5215fff064cd0ac9bfd94fc4aea66..f8b6a6853202187cd5f78e896b689b939b997e40 100644 (file)
@@ -171,6 +171,7 @@ phutil_register_library_map(array(
     'ArcanistMissingLinterException' => 'lint/linter/exception/ArcanistMissingLinterException.php',
     'ArcanistModifierOrderingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistModifierOrderingXHPASTLinterRule.php',
     'ArcanistNamingConventionsXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistNamingConventionsXHPASTLinterRule.php',
+    'ArcanistNewlineAfterOpenTagXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistNewlineAfterOpenTagXHPASTLinterRule.php',
     'ArcanistNoEffectException' => 'exception/usage/ArcanistNoEffectException.php',
     'ArcanistNoEngineException' => 'exception/usage/ArcanistNoEngineException.php',
     'ArcanistNoLintLinter' => 'lint/linter/ArcanistNoLintLinter.php',
@@ -455,6 +456,7 @@ phutil_register_library_map(array(
     'ArcanistMissingLinterException' => 'Exception',
     'ArcanistModifierOrderingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
     'ArcanistNamingConventionsXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
+    'ArcanistNewlineAfterOpenTagXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
     'ArcanistNoEffectException' => 'ArcanistUsageException',
     'ArcanistNoEngineException' => 'ArcanistUsageException',
     'ArcanistNoLintLinter' => 'ArcanistLinter',
index 6945002c8f69950ee71aae239eac7f37e0951496..51128f2e6d14d3ae2164838968f23e8b5225c5df 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 array(1, 2, 3);
 array(1, 2, 3,);
 array(
@@ -33,14 +34,15 @@ array(
   2,
   3, /* comment */ );
 ~~~~~~~~~~
-advice:3:14
-advice:12:3
-advice:16:3
-advice:26:3
-advice:30:3
-advice:34:20
+advice:4:14
+advice:13:3
+advice:17:3
+advice:27:3
+advice:31:3
+advice:35:20
 ~~~~~~~~~~
 <?php
+
 array(1, 2, 3);
 array(1, 2, 3);
 array(
index b2f7d548576ff992471293ac369f2e81d2d95221..1e38dea08fc5e78a38ef466eee43aae5d6bd7a5d 100644 (file)
@@ -1,15 +1,17 @@
 <?php
+
 $a []= 1;
 $a[] = 1;
 $a[]=1;
 $a [] = 1;
 ~~~~~~~~~~
-warning:2:3
-warning:2:6
-warning:4:5
-warning:5:3
+warning:3:3
+warning:3:6
+warning:5:5
+warning:6:3
 ~~~~~~~~~~
 <?php
+
 $a[] = 1;
 $a[] = 1;
 $a[] = 1;
index e4036ea5e10326b65ce6d7bbcc4d06a9021b3617..b727afc437d7e417202757c8b763a3ad7298abbf 100644 (file)
@@ -1,7 +1,8 @@
 <?php
+
 eval('evil code');
 ~~~~~~~~~~
-error:2:1
+error:3:1
 ~~~~~~~~~~
 ~~~~~~~~~~
 {
index 0f03a7742bd6630c310f6a4261109f2e6479a057..388f202016789703b5a955f646ad80470841952d 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 class MyClass {
   public function myfunc($var) {
     echo $var;
@@ -24,10 +25,10 @@ $foo(&$myvar);
 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
+error:3:7 XHP19
+error:10:8
+error:13:15
+error:16:17
+error:19:24
+error:19:39
+error:23:6
index a5611554f72b2ef139255a2db2cf631caf45ab01..bc70f302a71463c450608d92f1f75fdfb0b0d5f1 100644 (file)
@@ -1,12 +1,14 @@
 <?php
+
 echo (double)0;
 echo (int) 1;
 echo (string)  2;
 ~~~~~~~~~~
-advice:3:11
-advice:4:14
+advice:4:11
+advice:5:14
 ~~~~~~~~~~
 <?php
+
 echo (double)0;
 echo (int)1;
 echo (string)2;
index 7694bcb20763cfd9faa01b9b4f783e550742591c..6ec55746e058ae4bcb9ca20db78d26a5b580e0b5 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 class MyClass {
   public function someMethod() {
     return 'MyClass';
@@ -11,11 +12,12 @@ class MyClass {
   }
 }
 ~~~~~~~~~~
-error:2:7
-advice:4:12
-advice:8:10
+error:3:7
+advice:5:12
+advice:9:10
 ~~~~~~~~~~
 <?php
+
 class MyClass {
   public function someMethod() {
     return __CLASS__;
index 5933b662ac7acbee39b758900972d20c47a1f079..fd0659e1dcb7fb5d707f6f7fdbc061cff6226766 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 define('foo', 'bar');
 const bar = 'baz';
 
@@ -6,7 +7,7 @@ class Foo {
   const bar = 'baz';
 }
 ~~~~~~~~~~
-warning:2:8
-warning:3:7
-error:5:7
-warning:6:9
+warning:3:8
+warning:4:7
+error:6:7
+warning:7:9
index ad76cf4c9766fba574c79f0d0566fbc432860285..fa4ede7b740f0d382dd044c12076bff7fb26af3f 100644 (file)
@@ -1,12 +1,14 @@
 <?php
+
 new Foo;
 new Bar();
 new Foo\Bar;
 ~~~~~~~~~~
-advice:2:5
-advice:4:5
+advice:3:5
+advice:5:5
 ~~~~~~~~~~
 <?php
+
 new Foo();
 new Bar();
 new Foo\Bar();
index 3a0ab60192bdf53d99462a83b39a29323edbf50f..95fbc29385f9bec7ca2d15e7f136d2032f6c2f36 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 function foo($x, $y, $z) {}
 function bar($x, $y = null, $z) {}
 function baz($x = null, $y = null, $z = null) {}
@@ -7,6 +8,6 @@ class MyClass {
   public function myMethod($x, $y = null, $z) {}
 }
 ~~~~~~~~~~
-warning:3:13
-error:6:7
-warning:7:27
+warning:4:13
+error:7:7
+warning:8:27
index 0c9f619d6de8bbdbb8ccd0a4f0c10f60e65bee94..4559b32f87c999e1e5eafb8db293bf041276b3a1 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 'foobar';
 "foo\"bar";
 "foobar\n";
@@ -12,9 +13,10 @@ pht(
   "This string also requires \123\345 double quotes, but ".
   "this string does not. Here, they are used for consistency.");
 ~~~~~~~~~~
-advice:3:1
+advice:4:1
 ~~~~~~~~~~
 <?php
+
 'foobar';
 'foo"bar';
 "foobar\n";
index fab4a0a146cdbaf9c71a15f08577bd254aa45e1b..d2a7c4ce1d11600eb0f6cddf542ac5ec510cfe9b 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 $a = array(
   'a' => 'val1',
   $a => 'val2',
@@ -34,9 +35,9 @@ $f = array(
   $a => 'var2',
 );
 ~~~~~~~~~~
-error:5:3
-error:8:3
-error:15:3
-error:20:3
-error:25:3
-error:34:3
+error:6:3
+error:9:3
+error:16:3
+error:21:3
+error:26:3
+error:35:3
index 309e04d68c7fdc52c84c0f817ecd583f764efd40..2c8e5c5c9a4a795777d9f517e47af5117eac5afd 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 $x = null;
 $y = null;
 switch ($x) {}
@@ -24,5 +25,5 @@ switch ($x) {
     break;
 }
 ~~~~~~~~~~
-error:15:3
-error:22:7
+error:16:3
+error:23:7
index a7a995479c7ccaf90412240c7d4d930034ecd750..3ac083f3b215de81aab725c8d8e40054647ee4f4 100644 (file)
@@ -1,8 +1,9 @@
 <?php
+
 define('PONY', 'cute');
 define($pony, 'cute');
 define('PONY', $cute);
 define($pony, $cute);
 ~~~~~~~~~~
-error:3:8 dynamic define
-error:5:8 dynamic define
+error:4:8 dynamic define
+error:6:8 dynamic define
index bebe3d6c4d48efa57b2089cd658b18b08c2cdc04..d906f96da7dbbece15e8ab345cf0279d3103cb14 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 if (true) {
   echo 'foo';
 } elseif (false) {
@@ -7,9 +8,10 @@ if (true) {
   echo 'baz';
 }
 ~~~~~~~~~~
-advice:4:3
+advice:5:3
 ~~~~~~~~~~
 <?php
+
 if (true) {
   echo 'foo';
 } else if (false) {
index bf58f802fe35d7199c7376d2eead36fe20b89a1b..3d3520053d22477dc3a89077d9606a402f4e7f10 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 function w() {}
 function x() {
   // This is deliberately empty.
@@ -9,10 +10,11 @@ function z() {
 
 }
 ~~~~~~~~~~
-advice:6:14
 advice:7:14
+advice:8:14
 ~~~~~~~~~~
 <?php
+
 function w() {}
 function x() {
   // This is deliberately empty.
index a9ccd1793b18869abfdcff2a3f5e13caff1e296e..6cd225ad63b5cbb79bc8e8b488863d97c50516dd 100644 (file)
@@ -1,11 +1,13 @@
 <?php
+
 final class Foo {};
 $x = null;;
 ~~~~~~~~~~
-error:2:13 XHP19
-advice:2:19
-advice:3:11
+error:3:13 XHP19
+advice:3:19
+advice:4:11
 ~~~~~~~~~~
 <?php
+
 final class Foo {}
 $x = null;
index c9724096160ebc61583460d1bd8e7781c03e7893..b7a4f4f9751e451b38393f0621376992e465d9c4 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 exit(-1);
 exit -1;
 strtoupper(33 * exit - 6);
@@ -8,8 +9,8 @@ print '';
 $x = new stdClass();
 $y = clone $x;
 ~~~~~~~~~~
-error:3:1
-warning:3:5
-warning:3:6
-error:4:17
-warning:4:21
+error:4:1
+warning:4:5
+warning:4:6
+error:5:17
+warning:5:21
index 2a8e844309ea3cbb89cd694f805c6118d1b5053f..92ccd54ff8fd49dedb69e4ef4904cb6edece657e 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 printf();
 printf(null);
 printf('');
@@ -11,11 +12,11 @@ queryfx(null, 'x', 'y');
 
 foobar(null, null, '%s');
 ~~~~~~~~~~
-error:2:1
-error:6:1
+error:3:1
 error:7:1
-error:10:1
-error:12:1
+error:8:1
+error:11:1
+error:13:1
 ~~~~~~~~~~
 ~~~~~~~~~~
 {
index 863cf5fd00ebd9d03823e12549ad041cbfbddef6..11e7a2133b1a30904f597bf0f9afcd34af17fe52 100644 (file)
@@ -1,8 +1,9 @@
 <?php
+
 global $BASE_URL;
 function foo() {
   global $x, $y;
 }
 ~~~~~~~~~~
-warning:2:1
-warning:4:3
+warning:3:1
+warning:5:3
index c4853f5ad770dc662763e56bc739f7d7e87098cd..e4883802ec6bd33e1921e36c088ba1562c4d6e64 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 # no
 #no
 // yes
 /** yes */
 /**** yes ****/
 ~~~~~~~~~~
-error:2:1
 error:3:1
-error:5:1
-error:6:11
-advice:13:1
+error:4:1
+error:6:1
+error:7:11
 advice:14:1
-error:15:1
-advice:18:1
+advice:15:1
+error:16:1
 advice:19:1
+advice:20:1
 ~~~~~~~~~~
 <?php
+
 // no
 // no
 // yes
index 9f7a05078f752b1aa28b3d952308933923549d73..888b886f655253b4e5f19e5b221d873ffe25c7ae 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 final class Foo {
   public function bar() {}
   function baz() {}
@@ -10,13 +11,14 @@ final class Foo {
   private $z;
 }
 ~~~~~~~~~~
-error:2:13 XHP19
-advice:4:3
+error:3:13 XHP19
 advice:5:3
-advice:8:3
+advice:6:3
 advice:9:3
+advice:10:3
 ~~~~~~~~~~
 <?php
+
 final class Foo {
   public function bar() {}
   public function baz() {}
index 202baf3991625c8cbbab1438dfdcb49eeaeb0746..fd7b02a21fba1cf1260f56b0f20b9ca983a32fbd 100644 (file)
@@ -1,7 +1,8 @@
 <?php
+
 f()[0];
 ~~~~~~~~~~
-error:2:5
+error:3:5
 ~~~~~~~~~~
 ~~~~~~~~~~
 {
index ebf8423a3d207e3a6c954528eaa17a2859918eeb..62d6a867c79f9f81ff1f277d8bad427f0185d519 100644 (file)
@@ -1,9 +1,10 @@
 <?php
+
 var_dump('foobar' instanceof stdClass);
 var_dump(123 instanceof stdClass);
 var_dump(null instanceof stdClass);
 var_dump($x instanceof stdClass);
 ~~~~~~~~~~
-error:2:10
 error:3:10
 error:4:10
+error:5:10
similarity index 91%
rename from src/lint/linter/__tests__/xhpast/invalid-default-paramter.lint-test
rename to src/lint/linter/__tests__/xhpast/invalid-default-parameter.lint-test
index bac22ef859b38862374cf3dd6cb10ffc1c8d21a9..ecd63967d7b8d87292d96b486b7f4312ba103bba 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 function func_one(array $x) {}
 function func_two(array $x = null) {}
 function func_three(array $x = array()) {}
@@ -12,6 +13,6 @@ function func_eight(stdClass $x) {}
 function func_nine(stdClass $x = null) {}
 function func_ten(stdClass $x = array()) {}
 ~~~~~~~~~~
-error:5:31
-error:9:35
-error:13:33
+error:6:31
+error:10:35
+error:14:33
index a84ef23581c70878010a7282c79c823ff7376936..74712ac47c2f6b694635be2a97412ff8d0eb1571 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 class SomeClass {
   public $a;
   public public $b;
@@ -10,9 +11,9 @@ class SomeClass {
   abstract final public function baz() {}
 }
 ~~~~~~~~~~
-error:2:7 XHP19
-error:4:10
+error:3:7 XHP19
 error:5:10
-error:6:11
-error:9:10
-error:10:12
+error:6:10
+error:7:11
+error:10:10
+error:11:12
index a401b41fee0ba4535794df151e160728b2fbf1ad..554a40345d48cec6a57b040470f27c8f629272ed 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 function __lambda_func() {}
 ~~~~~~~~~~
-error:2:1
+error:3:1
index 90e6e215604f211793be80930b2b6ad0262373e7..b95f3c2028bd024465f0bd469fa3be2e0f8a93f1 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 include 'foo.php';
 include_once 'foo.php';
 require 'foo.php';
@@ -17,18 +18,19 @@ require ('baz.php');
 require_once ('baz.php');
 echo ('baz');
 ~~~~~~~~~~
-warning:8:8
-warning:9:13
-warning:10:8
-warning:11:13
-warning:12:5
-warning:14:9
-warning:15:14
-warning:16:9
-warning:17:14
-warning:18:6
+warning:9:8
+warning:10:13
+warning:11:8
+warning:12:13
+warning:13:5
+warning:15:9
+warning:16:14
+warning:17:9
+warning:18:14
+warning:19:6
 ~~~~~~~~~~
 <?php
+
 include 'foo.php';
 include_once 'foo.php';
 require 'foo.php';
index b9871b03a2604f9c74c281a3b95a463ae9b96111..769e95def2856d376ad74fab1a4b16add953cec9 100644 (file)
@@ -1,11 +1,13 @@
 <?php
+
 list($x, $y, , ,) = array();
 list($x, $y, , , $z) = array();
 ~~~~~~~~~~
-warning:2:12
-warning:2:14
-warning:2:16
+warning:3:12
+warning:3:14
+warning:3:16
 ~~~~~~~~~~
 <?php
+
 list($x, $y  ) = array();
 list($x, $y, , , $z) = array();
index d31bbd09502433d0438fd2f6f64100f4b19c1dd8..dc08b9d2c431b7a76d2b2b7b98428b66c6c0505e 100644 (file)
@@ -1,9 +1,11 @@
 <?php
+
 var_dump('');
 Var_Dump('');
 ~~~~~~~~~~
-advice:3:1
+advice:4:1
 ~~~~~~~~~~
 <?php
+
 var_dump('');
 var_dump('');
index dd0d176a2bde419e32e35fc63cc5d926c8803da7..408e8078ca2736fa48303e53845c3bebf41061a0 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 class Foo {
   public $x;
   static protected $y;
@@ -8,12 +9,13 @@ class Foo {
   static final public function foobar() {}
 }
 ~~~~~~~~~~
-error:2:7 XHP19
-advice:4:3
-advice:6:3
-advice:8:3
+error:3:7 XHP19
+advice:5:3
+advice:7:3
+advice:9:3
 ~~~~~~~~~~
 <?php
+
 class Foo {
   public $x;
   protected static $y;
index 2cd47e3633382f5c4857cea6358952b3043ea4ab..98f351b62509f0c89cfa62a7a8540cdeafccff76 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 final class a {
   const b = 1, c = d;
   protected $E, $H;
@@ -7,8 +8,6 @@ final class a {
 
 interface i {}
 
-
-
 function YY($ZZ) {}
 
 final class Quack {
@@ -17,10 +16,6 @@ final class Quack {
   public function vV($w_w) {}
 }
 
-
-
-
-
 function () use ($this_is_a_closure) {};
 
 function f(&$YY) {}
@@ -54,23 +49,24 @@ function j() {
   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:37:3
-warning:55:3
+warning:3:13
+warning:4:9
+warning:4:9
+warning:4:16
+warning:4:16
+warning:5:13
+warning:5:17
+warning:6:19
+warning:6:21
+warning:6:25
+warning:9:11
+warning:11:10
+warning:11:13
+warning:21:13
+warning:24:3
+warning:25:3
+warning:26:3
+warning:28:3
+warning:32:3
+warning:50:3
diff --git a/src/lint/linter/__tests__/xhpast/newline-after-open-tag.lint-test b/src/lint/linter/__tests__/xhpast/newline-after-open-tag.lint-test
new file mode 100644 (file)
index 0000000..4fc4964
--- /dev/null
@@ -0,0 +1,24 @@
+<?php phpinfo() ?>
+<?    phpinfo(); ?>
+
+<?php
+phpinfo();
+?>
+
+<?
+phpinfo();
+~~~~~~~~~~
+advice:4:6
+advice:8:3
+~~~~~~~~~~
+<?php phpinfo() ?>
+<?    phpinfo(); ?>
+
+<?php
+
+phpinfo();
+?>
+
+<?
+
+phpinfo();
index abb8bec5949de9ef9a4de464e0a7c835cf7c2921..6e68c2eb09621253233ff0962c123de693bb7fbc 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 abstract class A {}
 final class F {}
 ~~~~~~~~~~
index 5f3ade3388e4d55af0da44f2f51ea6498867ffd2..74e25ddcdb8e36459f49fa11bbb7623864cc8b8e 100644 (file)
@@ -1,9 +1,10 @@
 <?php
+
 echo <<<'EOT'
 Hello World!
 EOT;
 ~~~~~~~~~~
-error:2:6
+error:3:6
 ~~~~~~~~~~
 ~~~~~~~~~~
 {
index fd20b2315028591fa714078caa77d90e8a854aac..462f4d42956c264b3cb4e077a22d6d6601466cb1 100644 (file)
@@ -1,12 +1,14 @@
 <?php
+
 $x -> doSomething();
 id(new Something())
   ->doSomething();
 ~~~~~~~~~~
-warning:2:3
-warning:2:6
+warning:3:3
+warning:3:6
 ~~~~~~~~~~
 <?php
+
 $x->doSomething();
 id(new Something())
   ->doSomething();
index c0058bc0198821fc38da3d1ad0348af4fbcdf792..d6a38e8850026a521bf48aba51503c652fe69a45 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 if ( $x ) {}
 f( );
 q(                      );
@@ -20,25 +21,26 @@ some_call( /* respect authorial intent */ $b,
   $a // if comments are present
   );
 ~~~~~~~~~~
-warning:2:5
-warning:2:8
-warning:3:3
+warning:3:5
+warning:3:8
 warning:4:3
-warning:6:21
-warning:6:24
-warning:12:6
-warning:12:30
-warning:13:10
-warning:13:19
-warning:14:12
-warning:14:15
-error:15:13 XHP19 Class-Filename Mismatch
-warning:16:21
-warning:16:24
-warning:18:10
-warning:18:25
+warning:5:3
+warning:7:21
+warning:7:24
+warning:13:6
+warning:13:30
+warning:14:10
+warning:14:19
+warning:15:12
+warning:15:15
+error:16:13 XHP19 Class-Filename Mismatch
+warning:17:21
+warning:17:24
+warning:19:10
+warning:19:25
 ~~~~~~~~~~
 <?php
+
 if ($x) {}
 f();
 q();
index 40364598937a71933ef09c848af4ad5d272d480d..fb6e3ac644c78ed186106565f2a379159538c222 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 break;
 break 0;
 break 1;
@@ -8,10 +9,10 @@ continue 0;
 continue 1;
 continue 1 + foo() * $bar;
 ~~~~~~~~~~
-error:3:7
-error:5:7
-error:7:10
-error:9:10
+error:4:7
+error:6:7
+error:8:10
+error:10:10
 ~~~~~~~~~~
 ~~~~~~~~~~
 {"config": {"xhpast.php-version": "5.4.0"}}
index fe0f81e5d17000b0abd89e7c44da6ad747766d02..11672af460a17bd2893584d8c706d882f3f64f71 100644 (file)
@@ -6,7 +6,6 @@ function foo($bar) {
   preg_Quote('moo');
   preg_quote('moo', '/');
 }
-
 ~~~~~~~~~~
 advice:4:3 Wrong number of arguments to preg_quote()
 advice:6:3 Wrong number of arguments to preg_quote()
index ac65ff57fa8a13b8174ebe2515acfa9a5789b124..924122b79d1de8669e7fed1f3c4e1a97f6745348 100644 (file)
@@ -119,7 +119,6 @@ function closure4() {
   };
   $a++; // Reuse of $a
 }
-
 ~~~~~~~~~~
 warning:6:3
 warning:12:8
index ac2c64c444dbad00fd5fd279cb283eefff9c2422..2e9c6ba47498293c3f91e6c977baa51c570dfdae 100644 (file)
@@ -62,7 +62,6 @@ function k($stuff, $thing) {
   $other = array();
   foreach ($other as $item) {}
 }
-
 ~~~~~~~~~~
 error:43:22
 error:53:22
index c8e587dd920e1fb13cbf139e39aa8f0cba56fcc8..64052864bc16bc022cd1bbc16a670f410f653e7a 100644 (file)
@@ -1,14 +1,16 @@
 <?php
+
 foo();
 bar() ;
 baz()
 
      ;
 ~~~~~~~~~~
-advice:3:6
 advice:4:6
+advice:5:6
 ~~~~~~~~~~
 <?php
+
 foo();
 bar();
 baz();
index 204f6567ea07f69b38e69ff6c8ce13df6dead05e..0e66f3f17541bd843365ffc4911ae411cd3309dc 100644 (file)
@@ -1,14 +1,16 @@
 <?php
+
 // This test is checking that the LintPatcher correctly applies adjacent patches
 // with large character delta effects.
 function f(                                                             ) {
   g( );
 }
 ~~~~~~~~~~
-warning:4:12
-warning:5:5
+warning:5:12
+warning:6:5
 ~~~~~~~~~~
 <?php
+
 // This test is checking that the LintPatcher correctly applies adjacent patches
 // with large character delta effects.
 function f() {
index 57cb4aaae94de2540b7d9abecb16bc81f034da94..a41e8842524066773723ba0aac9e1569c4648586 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 if($x) {}
 else{}
 for(;;) {}
@@ -25,23 +26,24 @@ do {
 
 try {} catch(Exception $ex) {}
 ~~~~~~~~~~
-warning:2:1
-warning:2:10
 warning:3:1
+warning:3:10
 warning:4:1
 warning:5:1
 warning:6:1
 warning:7:1
-warning:7:6
 warning:8:1
-warning:9:11
-warning:10:16
-warning:13:3
+warning:8:6
+warning:9:1
+warning:10:11
+warning:11:16
 warning:14:3
-warning:24:3
-warning:26:8
+warning:15:3
+warning:25:3
+warning:27:8
 ~~~~~~~~~~
 <?php
+
 if ($x) {} else {}
 for (;;) {}
 foreach ($x as $y) {}
index 7fe6108b3ea5b0302f8901eebb4a6d0f6a846e7f..5c39162fd65dfcb2b1a7caac9f6ff311a76a7125 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 $a.$b;
 $a . $b;
 $a. $b;
@@ -24,16 +25,17 @@ array(
   $x=>$y,
 );
 ~~~~~~~~~~
-warning:3:3
-warning:3:5
-warning:4:4
-warning:5:3
-warning:12:9
-warning:13:10
-warning:14:9
-warning:24:5
+warning:4:3
+warning:4:5
+warning:5:4
+warning:6:3
+warning:13:9
+warning:14:10
+warning:15:9
+warning:25:5
 ~~~~~~~~~~
 <?php
+
 $a.$b;
 $a.$b;
 $a.$b;
index 2f94003ee9f1f8a6f2cadbf05e1e479d3e5487c1..571a56485afc5a8f9d4a3cd9784948679bdf37d1 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 $a + $b;
 $a+$b;
 $a +$b;
@@ -23,21 +24,22 @@ if ($x instanceof z &&$w) {}
 if ($x instanceof z && $w) {}
 f(1,2);
 ~~~~~~~~~~
-warning:3:3
-warning:4:4
-warning:5:3
-warning:7:3
+warning:4:3
+warning:5:4
+warning:6:3
 warning:8:3
-warning:9:4
-warning:10:3
+warning:9:3
+warning:10:4
 warning:11:3
-warning:13:14
-warning:20:52
-warning:21:54
-warning:22:21
-warning:24:4
+warning:12:3
+warning:14:14
+warning:21:52
+warning:22:54
+warning:23:21
+warning:25:4
 ~~~~~~~~~~
 <?php
+
 $a + $b;
 $a + $b;
 $a + $b;
index 384787e628771046e19a8299f49c31a7e2901a28..03c1c26136f942d02b7c9193ea5c64a2a580ab00 100644 (file)
@@ -1,9 +1,10 @@
 <?php
+
 final class Platypus {
   public function platypus() {
     // This method must be renamed to __construct().
   }
 }
 ~~~~~~~~~~
-error:2:13 XHP19 Class-Filename Mismatch
-error:3:19
+error:3:13 XHP19 Class-Filename Mismatch
+error:4:19
index 4971f5a9730ce84aecc90b2448fd0371ca48cfdc..fa1a7d8e036b019784533145f3f6a1918a468e9d 100644 (file)
@@ -15,7 +15,6 @@ $skip_cache = true || $some_complicated_expression;
 $skip_cache = $a || $b;
 $skip_cache = false && something();
 $skip_cache = f();
-
 ~~~~~~~~~~
 error:3:5
 error:5:5
index 32913db79c175c8f6b5593f049d0514b12172718..5762682608825bae1d0916d9738a85ef04cad5c1 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 class MyClass {
   public function __toString() {
     if (some_function()) {
@@ -23,4 +24,4 @@ abstract class SomeAbstractClass {
   abstract public function __toString();
 }
 ~~~~~~~~~~
-error:5:7
+error:6:7
index 6e08218e62688b4d7d258261d54e69a00c69bf6e..d8cd5c24cc430d1a42b376282407a71d93a57b71 100644 (file)
@@ -1,9 +1,11 @@
 <?php
+
 $x ++;
 $y--;
 ~~~~~~~~~~
-warning:2:3
+warning:3:3
 ~~~~~~~~~~
 <?php
+
 $x++;
 $y--;
index 87b65c647c401fc95d10f7e948b364d6c76342cc..e30bbe0efe855ee71dc3a7c8b34cecd12e0d0e4a 100644 (file)
@@ -1,12 +1,14 @@
 <?php
+
 $f = @ fopen($path, 'rb');
 @fclose($f);
 exit ();
 ~~~~~~~~~~
-warning:2:7
-warning:4:5
+warning:3:7
+warning:5:5
 ~~~~~~~~~~
 <?php
+
 $f = @fopen($path, 'rb');
 @fclose($f);
 exit();
index a90e1054cdc5577a4241a8dac2fd16bd3b5a9ea1..a1e821b46b139ab97da7d769b0e40dec8cfa4931 100644 (file)
@@ -1,8 +1,9 @@
 <?php
+
 final class Foo {
   public function bar() {}
   final public function baz() {}
 }
 ~~~~~~~~~~
-error:2:13 XHP19
-advice:4:3
+error:3:13 XHP19
+advice:5:3
index 42a39c41eec5ff91957e31822ef83fd5b3e85455..20fe8f7041432a06d47b6a7333a9bc3cdce38339 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 // This test is just verifying the parseability of files with a large number
 // (>500) of string concatenations. We emit n_CONCATENATION_LIST instead of
 // n_BINARY_EXPRESSION to avoid various call-depth traps in PHP, HPHP, and the
@@ -43,6 +44,7 @@
 ~~~~~~~~~~
 ~~~~~~~~~~
 <?php
+
 // This test is just verifying the parseability of files with a large number
 // (>500) of string concatenations. We emit n_CONCATENATION_LIST instead of
 // n_BINARY_EXPRESSION to avoid various call-depth traps in PHP, HPHP, and the
index 3ae1214bd291045f532ff1d25b187a5a3b29a3cf..395939bb98f2ca583699acbca4163f12b1fd6299 100644 (file)
@@ -8,7 +8,6 @@ final class A {
     $this->f();
   }
 }
-
 ~~~~~~~~~~
 error:3:13 XHP19 Class-Filename Mismatch
 error:8:5 Use of $this in a static method.
index d3e9a2f111b17440cb3ef1435565bcd67a3fa968..60c06632530d4bf070d50f4063f192bfc7a5f4d4 100644 (file)
@@ -1,5 +1,6 @@
 <?php
+
 $$foo;
 $obj->$bar; // okay
 ~~~~~~~~~~
-error:2:1
+error:3:1
index 70f2450d4911f7be58ffdc4c21587539fd9fec7d..3910c597d57253631bf422c163c831d0fc1187a7 100644 (file)
@@ -1,9 +1,10 @@
 <?php
+
 'a'.'b';
 'a' + 'b';
 'a' + $x;
 $x + $y + $z + 'q' + 0;
 ~~~~~~~~~~
-error:3:1
 error:4:1
 error:5:1
+error:6:1
diff --git a/src/lint/linter/xhpast/rules/ArcanistNewlineAfterOpenTagXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistNewlineAfterOpenTagXHPASTLinterRule.php
new file mode 100644 (file)
index 0000000..63bed62
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+final class ArcanistNewlineAfterOpenTagXHPASTLinterRule
+  extends ArcanistXHPASTLinterRule {
+
+  const ID = 81;
+
+  public function getLintName() {
+    return pht('Newline After PHP Open Tag');
+  }
+
+  public function getLintSeverity() {
+    return ArcanistLintSeverity::SEVERITY_ADVICE;
+  }
+
+  public function process(XHPASTNode $root) {
+    $tokens = $root->selectTokensOfType('T_OPEN_TAG');
+
+    foreach ($tokens as $token) {
+      for ($next = $token->getNextToken();
+           $next;
+           $next = $next->getNextToken()) {
+
+        if ($next->getTypeName() == 'T_WHITESPACE' &&
+            preg_match('/\n\s*\n/', $next->getValue())) {
+          continue 2;
+        }
+
+        if ($token->getLineNumber() != $next->getLineNumber()) {
+          break;
+        }
+
+        if ($next->getTypeName() == 'T_CLOSE_TAG') {
+          continue 2;
+        }
+      }
+
+      $next = $token->getNextToken();
+      $this->raiseLintAtToken(
+        $next,
+        pht('`%s` should be separated from code by an empty line.', '<?php'),
+        "\n".$next->getValue());
+    }
+  }
+
+}