Skip to content

Commit 77d06ca

Browse files
committed
feat - improve auto semicolon - #92
1 parent 74d6b27 commit 77d06ca

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

fmt.stub.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8304,6 +8304,8 @@ public function format($source) {
83048304
$isAttribute = false;
83058305
$quote_stack = false;
83068306

8307+
$max = count($this->tkns);
8308+
83078309
while (list($index, $token) = $this->each($this->tkns)) {
83088310
list($id, $text) = $this->getToken($token);
83098311
$this->ptr = $index;;
@@ -8326,9 +8328,19 @@ public function format($source) {
83268328
if ($this->hasLnAfter() && $this->rightTokenIs(ST_CURLY_CLOSE) && ! $isMatch) {
83278329
$this->appendCode(ST_SEMI_COLON);
83288330
}
8331+
else
83298332
if ($this->hasLnAfter() && $this->rightTokenIs([T_COMMENT, T_DOC_COMMENT]) && ! $isMatch) {
83308333
$this->appendCode(ST_SEMI_COLON);
83318334
}
8335+
else
8336+
if ($this->rightUsefulTokenIs(T_VARIABLE) && $this->rightTokenIs([T_COMMENT, T_DOC_COMMENT])) {
8337+
$this->appendCode(ST_SEMI_COLON);
8338+
}
8339+
else
8340+
if ($this->ptr === $max - 2 && $this->rightTokenIs([T_COMMENT, T_DOC_COMMENT])) {
8341+
$this->appendCode(ST_SEMI_COLON);
8342+
}
8343+
83328344
break;
83338345

83348346
case T_ATTRIBUTE:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
//passes:AutoSemicolon
3+
4+
$a = 1//
5+
$B = 2;
6+
7+
$a = 1
8+
//
9+
$B = 2;
10+
11+
$a = 1
12+
//
13+
/** other comment */
14+
$B = 2;
15+
16+
$a = 1// $b=2
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
//passes:AutoSemicolon
3+
4+
$a = 1; //
5+
$B = 2;
6+
7+
$a = 1;
8+
//
9+
$B = 2;
10+
11+
$a = 1;
12+
//
13+
/** other comment */
14+
$B = 2;
15+
16+
$a = 1; // $b=2

0 commit comments

Comments
 (0)