1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 06:42:41 +01:00

Minor change to ArcanistXHPASTLinter

Summary: Change `==` to `===`. This is a little bit cleaner because we shouldn't need type coercion here.

Test Plan: Ran `arc unit`.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9893
This commit is contained in:
Joshua Spence 2014-07-12 01:21:21 +10:00
parent 0be983a7a3
commit 806f21315a

View file

@ -277,34 +277,34 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$operator = $expression->getChildOfType(1, 'n_OPERATOR'); $operator = $expression->getChildOfType(1, 'n_OPERATOR');
$operator = $operator->getConcreteString(); $operator = $operator->getConcreteString();
if ($operator != '===' && $operator != '!==') { if ($operator !== '===' && $operator !== '!==') {
continue; continue;
} }
$false = $expression->getChildByIndex(0); $false = $expression->getChildByIndex(0);
if ($false->getTypeName() == 'n_SYMBOL_NAME' && if ($false->getTypeName() === 'n_SYMBOL_NAME' &&
$false->getConcreteString() == 'false') { $false->getConcreteString() === 'false') {
$strstr = $expression->getChildByIndex(2); $strstr = $expression->getChildByIndex(2);
} else { } else {
$strstr = $false; $strstr = $false;
$false = $expression->getChildByIndex(2); $false = $expression->getChildByIndex(2);
if ($false->getTypeName() != 'n_SYMBOL_NAME' || if ($false->getTypeName() !== 'n_SYMBOL_NAME' ||
$false->getConcreteString() != 'false') { $false->getConcreteString() !== 'false') {
continue; continue;
} }
} }
if ($strstr->getTypeName() != 'n_FUNCTION_CALL') { if ($strstr->getTypeName() !== 'n_FUNCTION_CALL') {
continue; continue;
} }
$name = strtolower($strstr->getChildByIndex(0)->getConcreteString()); $name = strtolower($strstr->getChildByIndex(0)->getConcreteString());
if ($name == 'strstr' || $name == 'strchr') { if ($name === 'strstr' || $name === 'strchr') {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$strstr, $strstr,
self::LINT_SLOWNESS, self::LINT_SLOWNESS,
'Use strpos() for checking if the string contains something.'); 'Use strpos() for checking if the string contains something.');
} else if ($name == 'stristr') { } else if ($name === 'stristr') {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$strstr, $strstr,
self::LINT_SLOWNESS, self::LINT_SLOWNESS,
@ -319,34 +319,34 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$operator = $expression->getChildOfType(1, 'n_OPERATOR'); $operator = $expression->getChildOfType(1, 'n_OPERATOR');
$operator = $operator->getConcreteString(); $operator = $operator->getConcreteString();
if ($operator != '===' && $operator != '!==') { if ($operator !== '===' && $operator !== '!==') {
continue; continue;
} }
$zero = $expression->getChildByIndex(0); $zero = $expression->getChildByIndex(0);
if ($zero->getTypeName() == 'n_NUMERIC_SCALAR' && if ($zero->getTypeName() === 'n_NUMERIC_SCALAR' &&
$zero->getConcreteString() == '0') { $zero->getConcreteString() === '0') {
$strpos = $expression->getChildByIndex(2); $strpos = $expression->getChildByIndex(2);
} else { } else {
$strpos = $zero; $strpos = $zero;
$zero = $expression->getChildByIndex(2); $zero = $expression->getChildByIndex(2);
if ($zero->getTypeName() != 'n_NUMERIC_SCALAR' || if ($zero->getTypeName() !== 'n_NUMERIC_SCALAR' ||
$zero->getConcreteString() != '0') { $zero->getConcreteString() !== '0') {
continue; continue;
} }
} }
if ($strpos->getTypeName() != 'n_FUNCTION_CALL') { if ($strpos->getTypeName() !== 'n_FUNCTION_CALL') {
continue; continue;
} }
$name = strtolower($strpos->getChildByIndex(0)->getConcreteString()); $name = strtolower($strpos->getChildByIndex(0)->getConcreteString());
if ($name == 'strpos') { if ($name === 'strpos') {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$strpos, $strpos,
self::LINT_SLOWNESS, self::LINT_SLOWNESS,
'Use strncmp() for checking if the string starts with something.'); 'Use strncmp() for checking if the string starts with something.');
} else if ($name == 'stripos') { } else if ($name === 'stripos') {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$strpos, $strpos,
self::LINT_SLOWNESS, self::LINT_SLOWNESS,
@ -463,7 +463,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
} }
if ($next) { if ($next) {
if ($next->getTypeName() == '(') { if ($next->getTypeName() === '(') {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$function, $function,
self::LINT_PHP_COMPATIBILITY, self::LINT_PHP_COMPATIBILITY,
@ -503,7 +503,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
if ($name->getTypeName() != 'n_CLASS_NAME') { if ($name->getTypeName() != 'n_CLASS_NAME') {
continue; continue;
} }
if ($name->getConcreteString() == 'static') { if ($name->getConcreteString() === 'static') {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$name, $name,
self::LINT_PHP_COMPATIBILITY, self::LINT_PHP_COMPATIBILITY,
@ -515,7 +515,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$ternaries = $root->selectDescendantsOfType('n_TERNARY_EXPRESSION'); $ternaries = $root->selectDescendantsOfType('n_TERNARY_EXPRESSION');
foreach ($ternaries as $ternary) { foreach ($ternaries as $ternary) {
$yes = $ternary->getChildByIndex(1); $yes = $ternary->getChildByIndex(1);
if ($yes->getTypeName() == 'n_EMPTY') { if ($yes->getTypeName() === 'n_EMPTY') {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$ternary, $ternary,
self::LINT_PHP_COMPATIBILITY, self::LINT_PHP_COMPATIBILITY,
@ -662,15 +662,15 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$tok_type = $token->getTypeName(); $tok_type = $token->getTypeName();
if ($tok_type == 'T_FUNCTION' || if ($tok_type === 'T_FUNCTION' ||
$tok_type == 'T_CLASS' || $tok_type === 'T_CLASS' ||
$tok_type == 'T_INTERFACE') { $tok_type === 'T_INTERFACE') {
// These aren't statements, but mark the block as nonempty anyway. // These aren't statements, but mark the block as nonempty anyway.
$block_ok = false; $block_ok = false;
continue; continue;
} }
if ($tok_type == ';') { if ($tok_type === ';') {
if ($statement_ok) { if ($statement_ok) {
$statment_ok = false; $statment_ok = false;
} else { } else {
@ -679,8 +679,8 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
continue; continue;
} }
if ($tok_type == 'T_BREAK' || if ($tok_type === 'T_BREAK' ||
$tok_type == 'T_CONTINUE') { $tok_type === 'T_CONTINUE') {
if (empty($lower_level_tokens[$token_id])) { if (empty($lower_level_tokens[$token_id])) {
$statement_ok = true; $statement_ok = true;
$block_ok = true; $block_ok = true;
@ -688,9 +688,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
continue; continue;
} }
if ($tok_type == 'T_RETURN' || if ($tok_type === 'T_RETURN' ||
$tok_type == 'T_THROW' || $tok_type === 'T_THROW' ||
$tok_type == 'T_EXIT' || $tok_type === 'T_EXIT' ||
($hook_obj && $hook_obj->checkSwitchToken($token))) { ($hook_obj && $hook_obj->checkSwitchToken($token))) {
if (empty($different_scope_tokens[$token_id])) { if (empty($different_scope_tokens[$token_id])) {
$statement_ok = true; $statement_ok = true;
@ -727,7 +727,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
// we're in a construct like "else{}", other rules will insert space // we're in a construct like "else{}", other rules will insert space
// after the 'else' correctly. // after the 'else' correctly.
$prev = $first->getPrevToken(); $prev = $first->getPrevToken();
if (!$prev || $prev->getValue() != ')') { if (!$prev || $prev->getValue() !== ')') {
continue; continue;
} }
@ -737,9 +737,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
'Put opening braces on the same line as control statements and '. 'Put opening braces on the same line as control statements and '.
'declarations, with a single space before them.', 'declarations, with a single space before them.',
' '.$first->getValue()); ' '.$first->getValue());
} else if (count($before) == 1) { } else if (count($before) === 1) {
$before = reset($before); $before = reset($before);
if ($before->getValue() != ' ') { if ($before->getValue() !== ' ') {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$before, $before,
self::LINT_BRACE_FORMATTING, self::LINT_BRACE_FORMATTING,
@ -780,7 +780,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$left = $expr->getChildByIndex(0)->getSemanticString(); $left = $expr->getChildByIndex(0)->getSemanticString();
$right = $expr->getChildByIndex(2)->getSemanticString(); $right = $expr->getChildByIndex(2)->getSemanticString();
if ($left == $right) { if ($left === $right) {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$expr, $expr,
self::LINT_TAUTOLOGICAL_EXPRESSION, self::LINT_TAUTOLOGICAL_EXPRESSION,
@ -797,8 +797,8 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$left = $this->evaluateStaticBoolean($left); $left = $this->evaluateStaticBoolean($left);
$right = $this->evaluateStaticBoolean($right); $right = $this->evaluateStaticBoolean($right);
if (($operator == '||' && ($left === true || $right === true)) || if (($operator === '||' && ($left === true || $right === true)) ||
($operator == '&&' && ($left === false || $right === false))) { ($operator === '&&' && ($left === false || $right === false))) {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$expr, $expr,
self::LINT_TAUTOLOGICAL_EXPRESSION, self::LINT_TAUTOLOGICAL_EXPRESSION,
@ -835,7 +835,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
protected function lintCommentSpaces(XHPASTNode $root) { protected function lintCommentSpaces(XHPASTNode $root) {
foreach ($root->selectTokensOfType('T_COMMENT') as $comment) { foreach ($root->selectTokensOfType('T_COMMENT') as $comment) {
$value = $comment->getValue(); $value = $comment->getValue();
if ($value[0] != '#') { if ($value[0] !== '#') {
$match = null; $match = null;
if (preg_match('@^(/[/*]+)[^/*\s]@', $value, $match)) { if (preg_match('@^(/[/*]+)[^/*\s]@', $value, $match)) {
$this->raiseLintAtOffset( $this->raiseLintAtOffset(
@ -853,7 +853,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
protected function lintHashComments(XHPASTNode $root) { protected function lintHashComments(XHPASTNode $root) {
foreach ($root->selectTokensOfType('T_COMMENT') as $comment) { foreach ($root->selectTokensOfType('T_COMMENT') as $comment) {
$value = $comment->getValue(); $value = $comment->getValue();
if ($value[0] != '#') { if ($value[0] !== '#') {
continue; continue;
} }
@ -889,7 +889,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$for_expr = $for_loop->getChildOfType(0, 'n_FOR_EXPRESSION'); $for_expr = $for_loop->getChildOfType(0, 'n_FOR_EXPRESSION');
$bin_exprs = $for_expr->selectDescendantsOfType('n_BINARY_EXPRESSION'); $bin_exprs = $for_expr->selectDescendantsOfType('n_BINARY_EXPRESSION');
foreach ($bin_exprs as $bin_expr) { foreach ($bin_exprs as $bin_expr) {
if ($bin_expr->getChildByIndex(1)->getConcreteString() == '=') { if ($bin_expr->getChildByIndex(1)->getConcreteString() === '=') {
$var = $bin_expr->getChildByIndex(0); $var = $bin_expr->getChildByIndex(0);
$var_map[$var->getConcreteString()] = $var; $var_map[$var->getConcreteString()] = $var;
} }
@ -911,7 +911,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$foreach_expr->getChildByIndex(2), $foreach_expr->getChildByIndex(2),
); );
foreach ($possible_used_vars as $var) { foreach ($possible_used_vars as $var) {
if ($var->getTypeName() == 'n_EMPTY') { if ($var->getTypeName() === 'n_EMPTY') {
continue; continue;
} }
$name = $var->getConcreteString(); $name = $var->getConcreteString();
@ -973,7 +973,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
foreach ($defs as $def) { foreach ($defs as $def) {
$body = $def->getChildByIndex(5); $body = $def->getChildByIndex(5);
if ($body->getTypeName() == 'n_EMPTY') { if ($body->getTypeName() === 'n_EMPTY') {
// Abstract method declaration. // Abstract method declaration.
continue; continue;
} }
@ -1026,12 +1026,12 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$foreach_expr = $foreach->getChildOfType(0, 'n_FOREACH_EXPRESSION'); $foreach_expr = $foreach->getChildOfType(0, 'n_FOREACH_EXPRESSION');
$var = $foreach_expr->getChildByIndex(2); $var = $foreach_expr->getChildByIndex(2);
if ($var->getTypeName() != 'n_VARIABLE_REFERENCE') { if ($var->getTypeName() !== 'n_VARIABLE_REFERENCE') {
continue; continue;
} }
$reference = $var->getChildByIndex(0); $reference = $var->getChildByIndex(0);
if ($reference->getTypeName() != 'n_VARIABLE') { if ($reference->getTypeName() !== 'n_VARIABLE') {
continue; continue;
} }
@ -1043,7 +1043,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$foreach_vars = $foreach->selectDescendantsOfType('n_VARIABLE'); $foreach_vars = $foreach->selectDescendantsOfType('n_VARIABLE');
foreach ($foreach_vars as $var) { foreach ($foreach_vars as $var) {
$name = $this->getConcreteVariableString($var); $name = $this->getConcreteVariableString($var);
if ($name == $reference_name) { if ($name === $reference_name) {
$exclude[$var->getID()] = true; $exclude[$var->getID()] = true;
} }
} }
@ -1053,15 +1053,15 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
// reference variable // reference variable
$binary = $body->selectDescendantsOfType('n_BINARY_EXPRESSION'); $binary = $body->selectDescendantsOfType('n_BINARY_EXPRESSION');
foreach ($binary as $expr) { foreach ($binary as $expr) {
if ($expr->getChildByIndex(1)->getConcreteString() != '=') { if ($expr->getChildByIndex(1)->getConcreteString() !== '=') {
continue; continue;
} }
$lval = $expr->getChildByIndex(0); $lval = $expr->getChildByIndex(0);
if ($lval->getTypeName() != 'n_VARIABLE') { if ($lval->getTypeName() !== 'n_VARIABLE') {
continue; continue;
} }
$rval = $expr->getChildByIndex(2); $rval = $expr->getChildByIndex(2);
if ($rval->getTypeName() != 'n_VARIABLE_REFERENCE') { if ($rval->getTypeName() !== 'n_VARIABLE_REFERENCE') {
continue; continue;
} }
@ -1209,7 +1209,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
} }
$body = $def->getChildByIndex(5); $body = $def->getChildByIndex(5);
if ($body->getTypeName() == 'n_EMPTY') { if ($body->getTypeName() === 'n_EMPTY') {
// Abstract method declaration. // Abstract method declaration.
continue; continue;
} }
@ -1226,7 +1226,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
->selectDescendantsOfType('n_GLOBAL_DECLARATION_LIST'); ->selectDescendantsOfType('n_GLOBAL_DECLARATION_LIST');
foreach ($global_vars as $var_list) { foreach ($global_vars as $var_list) {
foreach ($var_list->getChildren() as $var) { foreach ($var_list->getChildren() as $var) {
if ($var->getTypeName() == 'n_VARIABLE') { if ($var->getTypeName() === 'n_VARIABLE') {
$vars[] = $var; $vars[] = $var;
} else { } else {
// Dynamic global variable, i.e. "global $$x;". // Dynamic global variable, i.e. "global $$x;".
@ -1245,13 +1245,13 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$binary = $body->selectDescendantsOfType('n_BINARY_EXPRESSION'); $binary = $body->selectDescendantsOfType('n_BINARY_EXPRESSION');
foreach ($binary as $expr) { foreach ($binary as $expr) {
if ($expr->getChildByIndex(1)->getConcreteString() != '=') { if ($expr->getChildByIndex(1)->getConcreteString() !== '=') {
continue; continue;
} }
$lval = $expr->getChildByIndex(0); $lval = $expr->getChildByIndex(0);
if ($lval->getTypeName() == 'n_VARIABLE') { if ($lval->getTypeName() === 'n_VARIABLE') {
$vars[] = $lval; $vars[] = $lval;
} else if ($lval->getTypeName() == 'n_LIST') { } else if ($lval->getTypeName() === 'n_LIST') {
// Recursivey grab everything out of list(), since the grammar // Recursivey grab everything out of list(), since the grammar
// permits list() to be nested. Also note that list() is ONLY valid // permits list() to be nested. Also note that list() is ONLY valid
// as an lval assignments, so we could safely lift this out of the // as an lval assignments, so we could safely lift this out of the
@ -1262,7 +1262,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
} }
} }
if ($lval->getTypeName() == 'n_VARIABLE_VARIABLE') { if ($lval->getTypeName() === 'n_VARIABLE_VARIABLE') {
$scope_destroyed_at = min($scope_destroyed_at, $lval->getOffset()); $scope_destroyed_at = min($scope_destroyed_at, $lval->getOffset());
// No need to raise here since we raise an error elsewhere. // No need to raise here since we raise an error elsewhere.
} }
@ -1272,7 +1272,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
foreach ($calls as $call) { foreach ($calls as $call) {
$name = strtolower($call->getChildByIndex(0)->getConcreteString()); $name = strtolower($call->getChildByIndex(0)->getConcreteString());
if ($name == 'empty' || $name == 'isset') { if ($name === 'empty' || $name === 'isset') {
$params = $call $params = $call
->getChildOfType(1, 'n_CALL_PARAMETER_LIST') ->getChildOfType(1, 'n_CALL_PARAMETER_LIST')
->selectDescendantsOfType('n_VARIABLE'); ->selectDescendantsOfType('n_VARIABLE');
@ -1281,7 +1281,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
} }
continue; continue;
} }
if ($name != 'extract') { if ($name !== 'extract') {
continue; continue;
} }
$scope_destroyed_at = min($scope_destroyed_at, $call->getOffset()); $scope_destroyed_at = min($scope_destroyed_at, $call->getOffset());
@ -1370,12 +1370,12 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$foreach_end = $last_token->getOffset(); $foreach_end = $last_token->getOffset();
$key_var = $foreach_expr->getChildByIndex(1); $key_var = $foreach_expr->getChildByIndex(1);
if ($key_var->getTypeName() == 'n_VARIABLE') { if ($key_var->getTypeName() === 'n_VARIABLE') {
$foreach_vars[] = $key_var; $foreach_vars[] = $key_var;
} }
$value_var = $foreach_expr->getChildByIndex(2); $value_var = $foreach_expr->getChildByIndex(2);
if ($value_var->getTypeName() == 'n_VARIABLE') { if ($value_var->getTypeName() === 'n_VARIABLE') {
$foreach_vars[] = $value_var; $foreach_vars[] = $value_var;
} else { } else {
// The root-level token may be a reference, as in: // The root-level token may be a reference, as in:
@ -1383,7 +1383,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
// Reach into the n_VARIABLE_REFERENCE node to grab the n_VARIABLE // Reach into the n_VARIABLE_REFERENCE node to grab the n_VARIABLE
// node. // node.
$var = $value_var->getChildByIndex(0); $var = $value_var->getChildByIndex(0);
if ($var->getTypeName() == 'n_VARIABLE_VARIABLE') { if ($var->getTypeName() === 'n_VARIABLE_VARIABLE') {
$var = $var->getChildByIndex(0); $var = $var->getChildByIndex(0);
} }
$foreach_vars[] = $var; $foreach_vars[] = $var;
@ -1500,8 +1500,8 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
private function lintPHPTagUse(XHPASTNode $root) { private function lintPHPTagUse(XHPASTNode $root) {
$tokens = $root->getTokens(); $tokens = $root->getTokens();
foreach ($tokens as $token) { foreach ($tokens as $token) {
if ($token->getTypeName() == 'T_OPEN_TAG') { if ($token->getTypeName() === 'T_OPEN_TAG') {
if (trim($token->getValue()) == '<?') { if (trim($token->getValue()) === '<?') {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$token, $token,
self::LINT_PHP_SHORT_TAG, self::LINT_PHP_SHORT_TAG,
@ -1509,7 +1509,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
"<?php\n"); "<?php\n");
} }
break; break;
} else if ($token->getTypeName() == 'T_OPEN_TAG_WITH_ECHO') { } else if ($token->getTypeName() === 'T_OPEN_TAG_WITH_ECHO') {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$token, $token,
self::LINT_PHP_ECHO_TAG, self::LINT_PHP_ECHO_TAG,
@ -1576,7 +1576,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$functions = $root->selectDescendantsOfType('n_FUNCTION_DECLARATION'); $functions = $root->selectDescendantsOfType('n_FUNCTION_DECLARATION');
foreach ($functions as $function) { foreach ($functions as $function) {
$name_token = $function->getChildByIndex(2); $name_token = $function->getChildByIndex(2);
if ($name_token->getTypeName() == 'n_EMPTY') { if ($name_token->getTypeName() === 'n_EMPTY') {
// Unnamed closure. // Unnamed closure.
continue; continue;
} }
@ -1616,7 +1616,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
foreach ($params as $param_list) { foreach ($params as $param_list) {
foreach ($param_list->getChildren() as $param) { foreach ($param_list->getChildren() as $param) {
$name_token = $param->getChildByIndex(1); $name_token = $param->getChildByIndex(1);
if ($name_token->getTypeName() == 'n_VARIABLE_REFERENCE') { if ($name_token->getTypeName() === 'n_VARIABLE_REFERENCE') {
$name_token = $name_token->getChildOfType(0, 'n_VARIABLE'); $name_token = $name_token->getChildOfType(0, 'n_VARIABLE');
} }
$param_tokens[$name_token->getID()] = true; $param_tokens[$name_token->getID()] = true;
@ -1659,7 +1659,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$props = $root->selectDescendantsOfType('n_CLASS_MEMBER_DECLARATION_LIST'); $props = $root->selectDescendantsOfType('n_CLASS_MEMBER_DECLARATION_LIST');
foreach ($props as $prop_list) { foreach ($props as $prop_list) {
foreach ($prop_list->getChildren() as $token_id => $prop) { foreach ($prop_list->getChildren() as $token_id => $prop) {
if ($prop->getTypeName() == 'n_CLASS_MEMBER_MODIFIER_LIST') { if ($prop->getTypeName() === 'n_CLASS_MEMBER_MODIFIER_LIST') {
continue; continue;
} }
@ -1797,7 +1797,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
foreach ($methods as $method) { foreach ($methods as $method) {
$method_name_token = $method->getChildByIndex(2); $method_name_token = $method->getChildByIndex(2);
$method_name = $method_name_token->getConcreteString(); $method_name = $method_name_token->getConcreteString();
if (strtolower($class_name) == strtolower($method_name)) { if (strtolower($class_name) === strtolower($method_name)) {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$method_name_token, $method_name_token,
self::LINT_IMPLICIT_CONSTRUCTOR, self::LINT_IMPLICIT_CONSTRUCTOR,
@ -1826,10 +1826,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$token_o = array_shift($tokens); $token_o = array_shift($tokens);
$token_c = array_pop($tokens); $token_c = array_pop($tokens);
if ($token_o->getTypeName() != '(') { if ($token_o->getTypeName() !== '(') {
throw new Exception('Expected open paren!'); throw new Exception('Expected open paren!');
} }
if ($token_c->getTypeName() != ')') { if ($token_c->getTypeName() !== ')') {
throw new Exception('Expected close paren!'); throw new Exception('Expected close paren!');
} }
@ -1883,7 +1883,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
self::LINT_CONTROL_STATEMENT_SPACING, self::LINT_CONTROL_STATEMENT_SPACING,
'Convention: put a space after control statements.', 'Convention: put a space after control statements.',
$token->getValue().' '); $token->getValue().' ');
} else if (count($after) == 1) { } else if (count($after) === 1) {
$space = head($after); $space = head($after);
// If we have an else clause with braces, $space may not be // If we have an else clause with braces, $space may not be
@ -1895,12 +1895,12 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
// echo 'bar' // echo 'bar'
// //
// We just require it starts with either a whitespace or a newline. // We just require it starts with either a whitespace or a newline.
if ($token->getTypeName() == 'T_ELSE' || if ($token->getTypeName() === 'T_ELSE' ||
$token->getTypeName() == 'T_DO') { $token->getTypeName() === 'T_DO') {
break; break;
} }
if ($space->isAnyWhitespace() && $space->getValue() != ' ') { if ($space->isAnyWhitespace() && $space->getValue() !== ' ') {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$space, $space,
self::LINT_CONTROL_STATEMENT_SPACING, self::LINT_CONTROL_STATEMENT_SPACING,
@ -1964,8 +1964,8 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$prev_type = $prev->getTypeName(); $prev_type = $prev->getTypeName();
$next_type = $next->getTypeName(); $next_type = $next->getTypeName();
$prev_space = ($prev_type == 'T_WHITESPACE'); $prev_space = ($prev_type === 'T_WHITESPACE');
$next_space = ($next_type == 'T_WHITESPACE'); $next_space = ($next_type === 'T_WHITESPACE');
$replace = null; $replace = null;
if (!$prev_space && !$next_space) { if (!$prev_space && !$next_space) {
@ -1996,7 +1996,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$next = $token->getNextToken(); $next = $token->getNextToken();
foreach (array('prev' => $prev, 'next' => $next) as $wtoken) { foreach (array('prev' => $prev, 'next' => $next) as $wtoken) {
if ($wtoken->getTypeName() != 'T_WHITESPACE') { if ($wtoken->getTypeName() !== 'T_WHITESPACE') {
continue; continue;
} }
@ -2007,7 +2007,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
} }
$next = $wtoken->getNextToken(); $next = $wtoken->getNextToken();
if ($next && $next->getTypeName() == 'T_COMMENT') { if ($next && $next->getTypeName() === 'T_COMMENT') {
continue; continue;
} }
@ -2024,7 +2024,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$calls = $root->selectDescendantsOfType('n_FUNCTION_CALL'); $calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
foreach ($calls as $call) { foreach ($calls as $call) {
$name = $call->getChildByIndex(0)->getConcreteString(); $name = $call->getChildByIndex(0)->getConcreteString();
if (strtolower($name) == 'define') { if (strtolower($name) === 'define') {
$parameter_list = $call->getChildOfType(1, 'n_CALL_PARAMETER_LIST'); $parameter_list = $call->getChildOfType(1, 'n_CALL_PARAMETER_LIST');
$defined = $parameter_list->getChildByIndex(0); $defined = $parameter_list->getChildByIndex(0);
if (!$defined->isStaticScalar()) { if (!$defined->isStaticScalar()) {
@ -2050,10 +2050,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$method_is_static = false; $method_is_static = false;
$method_is_abstract = false; $method_is_abstract = false;
foreach ($attributes as $attribute) { foreach ($attributes as $attribute) {
if (strtolower($attribute->getConcreteString()) == 'static') { if (strtolower($attribute->getConcreteString()) === 'static') {
$method_is_static = true; $method_is_static = true;
} }
if (strtolower($attribute->getConcreteString()) == 'abstract') { if (strtolower($attribute->getConcreteString()) === 'abstract') {
$method_is_abstract = true; $method_is_abstract = true;
} }
} }
@ -2071,7 +2071,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$variables = $body->selectDescendantsOfType('n_VARIABLE'); $variables = $body->selectDescendantsOfType('n_VARIABLE');
foreach ($variables as $variable) { foreach ($variables as $variable) {
if ($method_is_static && if ($method_is_static &&
strtolower($variable->getConcreteString()) == '$this') { strtolower($variable->getConcreteString()) === '$this') {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$variable, $variable,
self::LINT_STATIC_THIS, self::LINT_STATIC_THIS,
@ -2125,8 +2125,8 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$unaries = $root->selectDescendantsOfType('n_UNARY_PREFIX_EXPRESSION'); $unaries = $root->selectDescendantsOfType('n_UNARY_PREFIX_EXPRESSION');
foreach ($unaries as $unary) { foreach ($unaries as $unary) {
$operator = $unary->getChildByIndex(0)->getConcreteString(); $operator = $unary->getChildByIndex(0)->getConcreteString();
if (strtolower($operator) == 'exit') { if (strtolower($operator) === 'exit') {
if ($unary->getParentNode()->getTypeName() != 'n_STATEMENT') { if ($unary->getParentNode()->getTypeName() !== 'n_STATEMENT') {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$unary, $unary,
self::LINT_EXIT_EXPRESSION, self::LINT_EXIT_EXPRESSION,
@ -2193,7 +2193,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$classes = $root->selectDescendantsOfType('n_CLASS_DECLARATION'); $classes = $root->selectDescendantsOfType('n_CLASS_DECLARATION');
$interfaces = $root->selectDescendantsOfType('n_INTERFACE_DECLARATION'); $interfaces = $root->selectDescendantsOfType('n_INTERFACE_DECLARATION');
if (count($classes) + count($interfaces) != 1) { if (count($classes) + count($interfaces) !== 1) {
return; return;
} }
@ -2214,7 +2214,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$path = $this->getActivePath(); $path = $this->getActivePath();
$filename = basename($path); $filename = basename($path);
if ($rename == $filename) { if ($rename === $filename) {
return; return;
} }
@ -2229,14 +2229,14 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$binops = $root->selectDescendantsOfType('n_BINARY_EXPRESSION'); $binops = $root->selectDescendantsOfType('n_BINARY_EXPRESSION');
foreach ($binops as $binop) { foreach ($binops as $binop) {
$op = $binop->getChildByIndex(1); $op = $binop->getChildByIndex(1);
if ($op->getConcreteString() != '+') { if ($op->getConcreteString() !== '+') {
continue; continue;
} }
$left = $binop->getChildByIndex(0); $left = $binop->getChildByIndex(0);
$right = $binop->getChildByIndex(2); $right = $binop->getChildByIndex(2);
if (($left->getTypeName() == 'n_STRING_SCALAR') || if (($left->getTypeName() === 'n_STRING_SCALAR') ||
($right->getTypeName() == 'n_STRING_SCALAR')) { ($right->getTypeName() === 'n_STRING_SCALAR')) {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$binop, $binop,
self::LINT_PLUS_OPERATOR_ON_STRINGS, self::LINT_PLUS_OPERATOR_ON_STRINGS,
@ -2318,7 +2318,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
if ($params) { if ($params) {
$last_param = last($params); $last_param = last($params);
if ($last_param->getTypeName() == 'n_HEREDOC') { if ($last_param->getTypeName() === 'n_HEREDOC') {
continue; continue;
} }
} }