Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7862229
ArcanistControlStatementSpacingXHPASTLinterRule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
ArcanistControlStatementSpacingXHPASTLinterRule.php
View Options
<?php
final
class
ArcanistControlStatementSpacingXHPASTLinterRule
extends
ArcanistXHPASTLinterRule
{
const
ID
=
26
;
public
function
getLintName
()
{
return
pht
(
'Space After Control Statement'
);
}
public
function
getLintSeverity
()
{
return
ArcanistLintSeverity
::
SEVERITY_WARNING
;
}
public
function
process
(
XHPASTNode
$root
)
{
foreach
(
$root
->
getTokens
()
as
$id
=>
$token
)
{
switch
(
$token
->
getTypeName
())
{
case
'T_IF'
:
case
'T_ELSE'
:
case
'T_FOR'
:
case
'T_FOREACH'
:
case
'T_WHILE'
:
case
'T_DO'
:
case
'T_SWITCH'
:
case
'T_CATCH'
:
$after
=
$token
->
getNonsemanticTokensAfter
();
if
(
empty
(
$after
))
{
$this
->
raiseLintAtToken
(
$token
,
pht
(
'Convention: put a space after control statements.'
),
$token
->
getValue
().
' '
);
}
else
if
(
count
(
$after
)
===
1
)
{
$space
=
head
(
$after
);
// If we have an else clause with braces, $space may not be
// a single white space. e.g.,
//
// if ($x)
// echo 'foo'
// else // <- $space is not " " but "\n ".
// echo 'bar'
//
// We just require it starts with either a whitespace or a newline.
if
(
$token
->
getTypeName
()
===
'T_ELSE'
||
$token
->
getTypeName
()
===
'T_DO'
)
{
break
;
}
if
(
$space
->
isAnyWhitespace
()
&&
$space
->
getValue
()
!==
' '
)
{
$this
->
raiseLintAtToken
(
$space
,
pht
(
'Convention: put a single space after control statements.'
),
' '
);
}
}
break
;
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 13, 20:16 (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
876934
Default Alt Text
ArcanistControlStatementSpacingXHPASTLinterRule.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment