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

phtize a bunch of strings

Summary: `pht`ize a bunch of strings in `ArcanistXHPASTLinter`.

Test Plan: Eyeball it.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D12392
This commit is contained in:
Joshua Spence 2015-04-14 06:30:13 +10:00
parent 51b5c70010
commit 58d8656696

View file

@ -77,60 +77,114 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
public function getLintNameMap() { public function getLintNameMap() {
return array( return array(
self::LINT_PHP_SYNTAX_ERROR => 'PHP Syntax Error!', self::LINT_PHP_SYNTAX_ERROR
self::LINT_UNABLE_TO_PARSE => 'Unable to Parse', => pht('PHP Syntax Error!'),
self::LINT_VARIABLE_VARIABLE => 'Use of Variable Variable', self::LINT_UNABLE_TO_PARSE
self::LINT_EXTRACT_USE => 'Use of extract()', => pht('Unable to Parse'),
self::LINT_UNDECLARED_VARIABLE => 'Use of Undeclared Variable', self::LINT_VARIABLE_VARIABLE
self::LINT_PHP_SHORT_TAG => 'Use of Short Tag "<?"', => pht('Use of Variable Variable'),
self::LINT_PHP_ECHO_TAG => 'Use of Echo Tag "<?="', self::LINT_EXTRACT_USE
self::LINT_PHP_CLOSE_TAG => 'Use of Close Tag "?>"', => pht('Use of %s', 'extract()'),
self::LINT_NAMING_CONVENTIONS => 'Naming Conventions', self::LINT_UNDECLARED_VARIABLE
self::LINT_IMPLICIT_CONSTRUCTOR => 'Implicit Constructor', => pht('Use of Undeclared Variable'),
self::LINT_DYNAMIC_DEFINE => 'Dynamic define()', self::LINT_PHP_SHORT_TAG
self::LINT_STATIC_THIS => 'Use of $this in Static Context', => pht('Use of Short Tag "%s"', '<?'),
self::LINT_PREG_QUOTE_MISUSE => 'Misuse of preg_quote()', self::LINT_PHP_ECHO_TAG
self::LINT_PHP_OPEN_TAG => 'Expected Open Tag', => pht('Use of Echo Tag "%s"', '<?='),
self::LINT_TODO_COMMENT => 'TODO Comment', self::LINT_PHP_CLOSE_TAG
self::LINT_EXIT_EXPRESSION => 'Exit Used as Expression', => pht('Use of Close Tag "%s"', '?>'),
self::LINT_COMMENT_STYLE => 'Comment Style', self::LINT_NAMING_CONVENTIONS
self::LINT_CLASS_FILENAME_MISMATCH => 'Class-Filename Mismatch', => pht('Naming Conventions'),
self::LINT_TAUTOLOGICAL_EXPRESSION => 'Tautological Expression', self::LINT_IMPLICIT_CONSTRUCTOR
self::LINT_PLUS_OPERATOR_ON_STRINGS => 'Not String Concatenation', => pht('Implicit Constructor'),
self::LINT_DUPLICATE_KEYS_IN_ARRAY => 'Duplicate Keys in Array', self::LINT_DYNAMIC_DEFINE
self::LINT_REUSED_ITERATORS => 'Reuse of Iterator Variable', => pht('Dynamic %s', 'define()'),
self::LINT_BRACE_FORMATTING => 'Brace placement', self::LINT_STATIC_THIS
self::LINT_PARENTHESES_SPACING => 'Spaces Inside Parentheses', => pht('Use of %s in Static Context', '$this'),
self::LINT_CONTROL_STATEMENT_SPACING => 'Space After Control Statement', self::LINT_PREG_QUOTE_MISUSE
self::LINT_BINARY_EXPRESSION_SPACING => 'Space Around Binary Operator', => pht('Misuse of %s', 'preg_quote()'),
self::LINT_ARRAY_INDEX_SPACING => 'Spacing Before Array Index', self::LINT_PHP_OPEN_TAG
self::LINT_IMPLICIT_FALLTHROUGH => 'Implicit Fallthrough', => pht('Expected Open Tag'),
self::LINT_REUSED_AS_ITERATOR => 'Variable Reused As Iterator', self::LINT_TODO_COMMENT
self::LINT_COMMENT_SPACING => 'Comment Spaces', => pht('TODO Comment'),
self::LINT_SLOWNESS => 'Slow Construct', self::LINT_EXIT_EXPRESSION
self::LINT_CLOSING_CALL_PAREN => 'Call Formatting', => pht('Exit Used as Expression'),
self::LINT_CLOSING_DECL_PAREN => 'Declaration Formatting', self::LINT_COMMENT_STYLE
self::LINT_REUSED_ITERATOR_REFERENCE => 'Reuse of Iterator References', => pht('Comment Style'),
self::LINT_KEYWORD_CASING => 'Keyword Conventions', self::LINT_CLASS_FILENAME_MISMATCH
self::LINT_DOUBLE_QUOTE => 'Unnecessary Double Quotes', => pht('Class-Filename Mismatch'),
self::LINT_ELSEIF_USAGE => 'ElseIf Usage', self::LINT_TAUTOLOGICAL_EXPRESSION
self::LINT_SEMICOLON_SPACING => 'Semicolon Spacing', => pht('Tautological Expression'),
self::LINT_CONCATENATION_OPERATOR => 'Concatenation Spacing', self::LINT_PLUS_OPERATOR_ON_STRINGS
self::LINT_PHP_COMPATIBILITY => 'PHP Compatibility', => pht('Not String Concatenation'),
self::LINT_LANGUAGE_CONSTRUCT_PAREN => 'Language Construct Parentheses', self::LINT_DUPLICATE_KEYS_IN_ARRAY
self::LINT_EMPTY_STATEMENT => 'Empty Block Statement', => pht('Duplicate Keys in Array'),
self::LINT_ARRAY_SEPARATOR => 'Array Separator', self::LINT_REUSED_ITERATORS
self::LINT_CONSTRUCTOR_PARENTHESES => 'Constructor Parentheses', => pht('Reuse of Iterator Variable'),
self::LINT_DUPLICATE_SWITCH_CASE => 'Duplicate Case Statements', self::LINT_BRACE_FORMATTING
self::LINT_BLACKLISTED_FUNCTION => 'Use of Blacklisted Function', => pht('Brace Placement'),
self::LINT_IMPLICIT_VISIBILITY => 'Implicit Method Visibility', self::LINT_PARENTHESES_SPACING
self::LINT_CALL_TIME_PASS_BY_REF => 'Call-Time Pass-By-Reference', => pht('Spaces Inside Parentheses'),
self::LINT_FORMATTED_STRING => 'Formatted String', self::LINT_CONTROL_STATEMENT_SPACING
self::LINT_UNNECESSARY_FINAL_MODIFIER => 'Unnecessary Final Modifier', => pht('Space After Control Statement'),
self::LINT_UNNECESSARY_SEMICOLON => 'Unnecessary Semicolon', self::LINT_BINARY_EXPRESSION_SPACING
self::LINT_SELF_MEMBER_REFERENCE => 'Self Member Reference', => pht('Space Around Binary Operator'),
self::LINT_LOGICAL_OPERATORS => 'Logical Operators', self::LINT_ARRAY_INDEX_SPACING
self::LINT_INNER_FUNCTION => 'Inner Functions', => pht('Spacing Before Array Index'),
self::LINT_IMPLICIT_FALLTHROUGH
=> pht('Implicit Fallthrough'),
self::LINT_REUSED_AS_ITERATOR
=> pht('Variable Reused As Iterator'),
self::LINT_COMMENT_SPACING
=> pht('Comment Spaces'),
self::LINT_SLOWNESS
=> pht('Slow Construct'),
self::LINT_CLOSING_CALL_PAREN
=> pht('Call Formatting'),
self::LINT_CLOSING_DECL_PAREN
=> pht('Declaration Formatting'),
self::LINT_REUSED_ITERATOR_REFERENCE
=> pht('Reuse of Iterator References'),
self::LINT_KEYWORD_CASING
=> pht('Keyword Conventions'),
self::LINT_DOUBLE_QUOTE
=> pht('Unnecessary Double Quotes'),
self::LINT_ELSEIF_USAGE
=> pht('ElseIf Usage'),
self::LINT_SEMICOLON_SPACING
=> pht('Semicolon Spacing'),
self::LINT_CONCATENATION_OPERATOR
=> pht('Concatenation Spacing'),
self::LINT_PHP_COMPATIBILITY
=> pht('PHP Compatibility'),
self::LINT_LANGUAGE_CONSTRUCT_PAREN
=> pht('Language Construct Parentheses'),
self::LINT_EMPTY_STATEMENT
=> pht('Empty Block Statement'),
self::LINT_ARRAY_SEPARATOR
=> pht('Array Separator'),
self::LINT_CONSTRUCTOR_PARENTHESES
=> pht('Constructor Parentheses'),
self::LINT_DUPLICATE_SWITCH_CASE
=> pht('Duplicate Case Statements'),
self::LINT_BLACKLISTED_FUNCTION
=> pht('Use of Blacklisted Function'),
self::LINT_IMPLICIT_VISIBILITY
=> pht('Implicit Method Visibility'),
self::LINT_CALL_TIME_PASS_BY_REF
=> pht('Call-Time Pass-By-Reference'),
self::LINT_FORMATTED_STRING
=> pht('Formatted String'),
self::LINT_UNNECESSARY_FINAL_MODIFIER
=> pht('Unnecessary Final Modifier'),
self::LINT_UNNECESSARY_SEMICOLON
=> pht('Unnecessary Semicolon'),
self::LINT_SELF_MEMBER_REFERENCE
=> pht('Self Member Reference'),
self::LINT_LOGICAL_OPERATORS
=> pht('Logical Operators'),
self::LINT_INNER_FUNCTION
=> pht('Inner Functions'),
); );
} }
@ -257,7 +311,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$ex->getErrorLine(), $ex->getErrorLine(),
1, 1,
self::LINT_PHP_SYNTAX_ERROR, self::LINT_PHP_SYNTAX_ERROR,
'This file contains a syntax error: '.$ex->getMessage()); pht(
'This file contains a syntax error: %s',
$ex->getMessage()));
} else if ($ex instanceof Exception) { } else if ($ex instanceof Exception) {
$this->raiseLintAtPath(self::LINT_UNABLE_TO_PARSE, $ex->getMessage()); $this->raiseLintAtPath(self::LINT_UNABLE_TO_PARSE, $ex->getMessage());
} }
@ -373,12 +429,16 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$strstr, $strstr,
self::LINT_SLOWNESS, self::LINT_SLOWNESS,
'Use strpos() for checking if the string contains something.'); pht(
'Use %s for checking if the string contains something.',
'strpos()'));
} else if ($name === 'stristr') { } else if ($name === 'stristr') {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$strstr, $strstr,
self::LINT_SLOWNESS, self::LINT_SLOWNESS,
'Use stripos() for checking if the string contains something.'); pht(
'Use %s for checking if the string contains something.',
'stripos()'));
} }
} }
} }
@ -415,13 +475,16 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$strpos, $strpos,
self::LINT_SLOWNESS, self::LINT_SLOWNESS,
'Use strncmp() for checking if the string starts with something.'); pht(
'Use %s for checking if the string starts with something.',
'strncmp()'));
} else if ($name === 'stripos') { } else if ($name === 'stripos') {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$strpos, $strpos,
self::LINT_SLOWNESS, self::LINT_SLOWNESS,
'Use strncasecmp() for checking if the string starts with '. pht(
'something.'); 'Use %s for checking if the string starts with something.',
'strncasecmp()'));
} }
} }
} }
@ -697,8 +760,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$function, $function,
self::LINT_PHP_COMPATIBILITY, self::LINT_PHP_COMPATIBILITY,
"This codebase targets PHP {$this->version}, but anonymous ". pht(
"functions were not introduced until PHP 5.3."); 'This codebase targets PHP %s, but anonymous '.
'functions were not introduced until PHP 5.3.',
$this->version));
} }
} }
} }
@ -708,8 +773,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$namespace, $namespace,
self::LINT_PHP_COMPATIBILITY, self::LINT_PHP_COMPATIBILITY,
"This codebase targets PHP {$this->version}, but namespaces were not ". pht(
"introduced until PHP 5.3."); 'This codebase targets PHP %s, but namespaces were not '.
'introduced until PHP 5.3.',
$this->version));
} }
// NOTE: This is only "use x;", in anonymous functions the node type is // NOTE: This is only "use x;", in anonymous functions the node type is
@ -723,8 +790,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$use, $use,
self::LINT_PHP_COMPATIBILITY, self::LINT_PHP_COMPATIBILITY,
"This codebase targets PHP {$this->version}, but namespaces were not ". pht(
"introduced until PHP 5.3."); 'This codebase targets PHP %s, but namespaces were not '.
'introduced until PHP 5.3.',
$this->version));
} }
$statics = $root->selectDescendantsOfType('n_CLASS_STATIC_ACCESS'); $statics = $root->selectDescendantsOfType('n_CLASS_STATIC_ACCESS');
@ -737,8 +806,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$name, $name,
self::LINT_PHP_COMPATIBILITY, self::LINT_PHP_COMPATIBILITY,
"This codebase targets PHP {$this->version}, but `static::` was not ". pht(
"introduced until PHP 5.3."); 'This codebase targets PHP %s, but `static::` was not '.
'introduced until PHP 5.3.',
$this->version));
} }
} }
@ -749,8 +820,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$ternary, $ternary,
self::LINT_PHP_COMPATIBILITY, self::LINT_PHP_COMPATIBILITY,
"This codebase targets PHP {$this->version}, but short ternary was ". pht(
"not introduced until PHP 5.3."); 'This codebase targets PHP %s, but short ternary was '.
'not introduced until PHP 5.3.',
$this->version));
} }
} }
@ -760,8 +833,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$heredoc, $heredoc,
self::LINT_PHP_COMPATIBILITY, self::LINT_PHP_COMPATIBILITY,
"This codebase targets PHP {$this->version}, but nowdoc was not ". pht(
"introduced until PHP 5.3."); 'This codebase targets PHP %s, but nowdoc was not '.
'introduced until PHP 5.3.',
$this->version));
} }
} }
} }
@ -941,8 +1016,7 @@ 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;
@ -966,10 +1040,19 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
head($tokens), head($tokens),
self::LINT_IMPLICIT_FALLTHROUGH, self::LINT_IMPLICIT_FALLTHROUGH,
"This 'case' or 'default' has a nonempty block which does not ". pht(
"end with 'break', 'continue', 'return', 'throw' or 'exit'. Did ". "This '%s' or '%s' has a nonempty block which does not end ".
"you forget to add one of those? If you intend to fall through, ". "with '%s', '%s', '%s', '%s' or '%s'. Did you forget to add ".
"add a '// fallthrough' comment to silence this warning."); "one of those? If you intend to fall through, add a '%s' ".
"comment to silence this warning.",
'case',
'default',
'break',
'continue',
'return',
'throw',
'exit',
'// fallthrough'));
} }
} }
} }
@ -996,8 +1079,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$first, $first,
self::LINT_BRACE_FORMATTING, self::LINT_BRACE_FORMATTING,
pht(
'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);
@ -1005,8 +1089,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$before, $before,
self::LINT_BRACE_FORMATTING, self::LINT_BRACE_FORMATTING,
pht(
'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.'),
' '); ' ');
} }
} }
@ -1025,7 +1110,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$node, $node,
self::LINT_BRACE_FORMATTING, self::LINT_BRACE_FORMATTING,
'Use braces to surround a statement block.'); pht('Use braces to surround a statement block.'));
} }
} }
@ -1046,8 +1131,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$first, $first,
self::LINT_BRACE_FORMATTING, self::LINT_BRACE_FORMATTING,
pht(
'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);
@ -1055,8 +1141,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$before, $before,
self::LINT_BRACE_FORMATTING, self::LINT_BRACE_FORMATTING,
pht(
'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.'),
' '); ' ');
} }
} }
@ -1096,8 +1183,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$expr, $expr,
self::LINT_TAUTOLOGICAL_EXPRESSION, self::LINT_TAUTOLOGICAL_EXPRESSION,
pht(
'Both sides of this expression are identical, so it always '. 'Both sides of this expression are identical, so it always '.
'evaluates to a constant.'); 'evaluates to a constant.'));
} }
} }
@ -1114,8 +1202,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$expr, $expr,
self::LINT_TAUTOLOGICAL_EXPRESSION, self::LINT_TAUTOLOGICAL_EXPRESSION,
'The logical value of this expression is static. Did you forget '. pht(
'to remove some debugging code?'); 'The logical value of this expression is static. '.
'Did you forget to remove some debugging code?'));
} }
} }
} }
@ -1143,7 +1232,6 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
return null; return null;
} }
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();
@ -1153,7 +1241,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtOffset( $this->raiseLintAtOffset(
$comment->getOffset(), $comment->getOffset(),
self::LINT_COMMENT_SPACING, self::LINT_COMMENT_SPACING,
'Put space after comment start.', pht('Put space after comment start.'),
$match[1], $match[1],
$match[1].' '); $match[1].' ');
} }
@ -1161,7 +1249,6 @@ 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();
@ -1172,7 +1259,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtOffset( $this->raiseLintAtOffset(
$comment->getOffset(), $comment->getOffset(),
self::LINT_COMMENT_STYLE, self::LINT_COMMENT_STYLE,
'Use "//" single-line comments, not "#".', pht('Use "%s" single-line comments, not "%s".', '//', '#'),
'#', '#',
(preg_match('/^#\S/', $value) ? '// ' : '//')); (preg_match('/^#\S/', $value) ? '// ' : '//'));
} }
@ -1249,9 +1336,11 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$message = $this->raiseLintAtNode( $message = $this->raiseLintAtNode(
$inner_loop->getChildByIndex(0), $inner_loop->getChildByIndex(0),
self::LINT_REUSED_ITERATORS, self::LINT_REUSED_ITERATORS,
"This loop reuses iterator variables ({$shared_desc}) from an ". pht(
"outer loop. You might be clobbering the outer iterator. Change ". 'This loop reuses iterator variables (%s) from an '.
"the inner loop to use a different iterator name."); 'outer loop. You might be clobbering the outer iterator. '.
'Change the inner loop to use a different iterator name.',
$shared_desc));
$locations = array(); $locations = array();
foreach ($shared as $var) { foreach ($shared as $var) {
@ -1425,9 +1514,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$var, $var,
self::LINT_REUSED_ITERATOR_REFERENCE, self::LINT_REUSED_ITERATOR_REFERENCE,
pht(
'This variable was used already as a by-reference iterator '. 'This variable was used already as a by-reference iterator '.
'variable. Such variables survive outside the foreach loop, '. 'variable. Such variables survive outside the foreach loop, '.
'do not reuse.'); 'do not reuse.'));
} }
} }
@ -1440,8 +1530,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$vvar, $vvar,
self::LINT_VARIABLE_VARIABLE, self::LINT_VARIABLE_VARIABLE,
pht(
'Rewrite this code to use an array. Variable variables are unclear '. 'Rewrite this code to use an array. Variable variables are unclear '.
'and hinder static analysis.'); 'and hinder static analysis.'));
} }
} }
@ -1600,7 +1691,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$call, $call,
self::LINT_EXTRACT_USE, self::LINT_EXTRACT_USE,
'Avoid extract(). It is confusing and hinders static analysis.'); pht(
'Avoid %s. It is confusing and hinders static analysis.',
'extract()'));
} }
// Now we have every declaration except foreach(), handled below. Build // Now we have every declaration except foreach(), handled below. Build
@ -1793,9 +1886,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtOffset( $this->raiseLintAtOffset(
$offset, $offset,
self::LINT_UNDECLARED_VARIABLE, self::LINT_UNDECLARED_VARIABLE,
pht(
'Declare variables prior to use (even if you are passing them '. 'Declare variables prior to use (even if you are passing them '.
'as reference parameters). You may have misspelled this '. 'as reference parameters). You may have misspelled this '.
'variable name.', 'variable name.'),
$concrete); $concrete);
$issued_warnings[$concrete] = true; $issued_warnings[$concrete] = true;
} }
@ -1817,7 +1911,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$token, $token,
self::LINT_PHP_SHORT_TAG, self::LINT_PHP_SHORT_TAG,
'Use the full form of the PHP open tag, "<?php".', pht(
'Use the full form of the PHP open tag, "%s".',
'<?php'),
"<?php\n"); "<?php\n");
} }
break; break;
@ -1825,15 +1921,18 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$token, $token,
self::LINT_PHP_ECHO_TAG, self::LINT_PHP_ECHO_TAG,
'Avoid the PHP echo short form, "<?=".'); pht('Avoid the PHP echo short form, "%s".', '<?='));
break; break;
} else { } else {
if (!preg_match('/^#!/', $token->getValue())) { if (!preg_match('/^#!/', $token->getValue())) {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$token, $token,
self::LINT_PHP_OPEN_TAG, self::LINT_PHP_OPEN_TAG,
'PHP files should start with "<?php", which may be preceded by '. pht(
'a "#!" line for scripts.'); 'PHP files should start with "%s", which may be preceded by '.
'a "%s" line for scripts.',
'<?php',
'#!'));
} }
break; break;
} }
@ -1843,7 +1942,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$token, $token,
self::LINT_PHP_CLOSE_TAG, self::LINT_PHP_CLOSE_TAG,
'Do not use the PHP closing tag, "?>".'); pht('Do not use the PHP closing tag, "%s".', '?>'));
} }
} }
@ -1864,8 +1963,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$name_token, $name_token,
ArcanistXHPASTLintNamingHook::isUpperCamelCase($name_string) ArcanistXHPASTLintNamingHook::isUpperCamelCase($name_string)
? null ? null
: 'Follow naming conventions: classes should be named using '. : pht(
'UpperCamelCase.', 'Follow naming conventions: classes should be named using '.
'UpperCamelCase.'),
); );
} }
@ -1879,8 +1979,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$name_token, $name_token,
ArcanistXHPASTLintNamingHook::isUpperCamelCase($name_string) ArcanistXHPASTLintNamingHook::isUpperCamelCase($name_string)
? null ? null
: 'Follow naming conventions: interfaces should be named using '. : pht(
'UpperCamelCase.', 'Follow naming conventions: interfaces should be named using '.
'UpperCamelCase.'),
); );
} }
@ -1900,8 +2001,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
ArcanistXHPASTLintNamingHook::isLowercaseWithUnderscores( ArcanistXHPASTLintNamingHook::isLowercaseWithUnderscores(
ArcanistXHPASTLintNamingHook::stripPHPFunction($name_string)) ArcanistXHPASTLintNamingHook::stripPHPFunction($name_string))
? null ? null
: 'Follow naming conventions: functions should be named using '. : pht(
'lowercase_with_underscores.', 'Follow naming conventions: functions should be named using '.
'lowercase_with_underscores.'),
); );
} }
@ -1917,8 +2019,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
ArcanistXHPASTLintNamingHook::isLowerCamelCase( ArcanistXHPASTLintNamingHook::isLowerCamelCase(
ArcanistXHPASTLintNamingHook::stripPHPFunction($name_string)) ArcanistXHPASTLintNamingHook::stripPHPFunction($name_string))
? null ? null
: 'Follow naming conventions: methods should be named using '. : pht(
'lowerCamelCase.', 'Follow naming conventions: methods should be named using '.
'lowerCamelCase.'),
); );
} }
@ -1941,8 +2044,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
ArcanistXHPASTLintNamingHook::isLowercaseWithUnderscores( ArcanistXHPASTLintNamingHook::isLowercaseWithUnderscores(
ArcanistXHPASTLintNamingHook::stripPHPVariable($name_string)) ArcanistXHPASTLintNamingHook::stripPHPVariable($name_string))
? null ? null
: 'Follow naming conventions: parameters should be named using '. : pht(
'lowercase_with_underscores.', 'Follow naming conventions: parameters should be named using '.
'lowercase_with_underscores.'),
); );
} }
} }
@ -1960,8 +2064,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$name_token, $name_token,
ArcanistXHPASTLintNamingHook::isUppercaseWithUnderscores($name_string) ArcanistXHPASTLintNamingHook::isUppercaseWithUnderscores($name_string)
? null ? null
: 'Follow naming conventions: class constants should be named '. : pht(
'using UPPERCASE_WITH_UNDERSCORES.', 'Follow naming conventions: class constants should be named '.
'using UPPERCASE_WITH_UNDERSCORES.'),
); );
} }
} }
@ -1986,8 +2091,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
ArcanistXHPASTLintNamingHook::isLowerCamelCase( ArcanistXHPASTLintNamingHook::isLowerCamelCase(
ArcanistXHPASTLintNamingHook::stripPHPVariable($name_string)) ArcanistXHPASTLintNamingHook::stripPHPVariable($name_string))
? null ? null
: 'Follow naming conventions: class properties should be named '. : pht(
'using lowerCamelCase.', 'Follow naming conventions: class properties should be named '.
'using lowerCamelCase.'),
); );
} }
} }
@ -2022,7 +2128,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
// Exclude access of static properties, since lint will be raised at // Exclude access of static properties, since lint will be raised at
// their declaration if they're invalid and they may not conform to // their declaration if they're invalid and they may not conform to
// variable rules. This is slightly overbroad (includes the entire // variable rules. This is slightly overbroad (includes the entire
// rhs of a "Class::..." token) to cover cases like "Class:$x[0]". These // RHS of a "Class::..." token) to cover cases like "Class:$x[0]". These
// variables are simply made exempt from naming conventions. // variables are simply made exempt from naming conventions.
$exclude_tokens = array(); $exclude_tokens = array();
$statics = $def->selectDescendantsOfType('n_CLASS_STATIC_ACCESS'); $statics = $def->selectDescendantsOfType('n_CLASS_STATIC_ACCESS');
@ -2069,8 +2175,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
ArcanistXHPASTLintNamingHook::isLowercaseWithUnderscores( ArcanistXHPASTLintNamingHook::isLowercaseWithUnderscores(
ArcanistXHPASTLintNamingHook::stripPHPVariable($var_string)) ArcanistXHPASTLintNamingHook::stripPHPVariable($var_string))
? null ? null
: 'Follow naming conventions: variables should be named using '. : pht(
'lowercase_with_underscores.', 'Follow naming conventions: variables should be named using '.
'lowercase_with_underscores.'),
); );
} }
} }
@ -2118,9 +2225,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$method_name_token, $method_name_token,
self::LINT_IMPLICIT_CONSTRUCTOR, self::LINT_IMPLICIT_CONSTRUCTOR,
'Name constructors __construct() explicitly. This method is a '. pht(
'constructor because it has the same name as the class it is '. 'Name constructors %s explicitly. This method is a constructor '.
'defined in.'); ' because it has the same name as the class it is defined in.',
'__construct()'));
} }
} }
} }
@ -2144,10 +2252,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(pht('Expected open parentheses.'));
} }
if ($token_c->getTypeName() !== ')') { if ($token_c->getTypeName() !== ')') {
throw new Exception('Expected close paren!'); throw new Exception(pht('Expected close parentheses.'));
} }
$nonsem_o = $token_o->getNonsemanticTokensAfter(); $nonsem_o = $token_o->getNonsemanticTokensAfter();
@ -2176,7 +2284,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtOffset( $this->raiseLintAtOffset(
reset($tokens)->getOffset(), reset($tokens)->getOffset(),
self::LINT_PARENTHESES_SPACING, self::LINT_PARENTHESES_SPACING,
'Parentheses should hug their contents.', pht('Parentheses should hug their contents.'),
$string, $string,
''); '');
} }
@ -2198,7 +2306,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$token, $token,
self::LINT_CONTROL_STATEMENT_SPACING, self::LINT_CONTROL_STATEMENT_SPACING,
'Convention: put a space after control statements.', pht('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);
@ -2221,7 +2329,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$space, $space,
self::LINT_CONTROL_STATEMENT_SPACING, self::LINT_CONTROL_STATEMENT_SPACING,
'Convention: put a single space after control statements.', pht('Convention: put a single space after control statements.'),
' '); ' ');
} }
} }
@ -2250,8 +2358,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$operator, $operator,
self::LINT_BINARY_EXPRESSION_SPACING, self::LINT_BINARY_EXPRESSION_SPACING,
pht(
'Convention: logical and arithmetic operators should be '. 'Convention: logical and arithmetic operators should be '.
'surrounded by whitespace.', 'surrounded by whitespace.'),
$replace); $replace);
} }
} }
@ -2267,7 +2376,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$token, $token,
self::LINT_BINARY_EXPRESSION_SPACING, self::LINT_BINARY_EXPRESSION_SPACING,
'Convention: comma should be followed by space.', pht('Convention: comma should be followed by space.'),
', '); ', ');
break; break;
} }
@ -2297,7 +2406,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$token, $token,
self::LINT_BINARY_EXPRESSION_SPACING, self::LINT_BINARY_EXPRESSION_SPACING,
'Convention: double arrow should be surrounded by whitespace.', pht('Convention: double arrow should be surrounded by whitespace.'),
$replace); $replace);
} }
} }
@ -2325,8 +2434,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$operator, $operator,
self::LINT_BINARY_EXPRESSION_SPACING, self::LINT_BINARY_EXPRESSION_SPACING,
pht(
'Convention: logical and arithmetic operators should be '. 'Convention: logical and arithmetic operators should be '.
'surrounded by whitespace.', 'surrounded by whitespace.'),
$replace); $replace);
} }
} }
@ -2357,7 +2467,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$wtoken, $wtoken,
self::LINT_CONCATENATION_OPERATOR, self::LINT_CONCATENATION_OPERATOR,
'Convention: no spaces around "." (string concatenation) operator.', pht(
'Convention: no spaces around "%s" '.
'(string concatenation) operator.',
'.'),
''); '');
} }
} }
@ -2374,7 +2487,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$defined, $defined,
self::LINT_DYNAMIC_DEFINE, self::LINT_DYNAMIC_DEFINE,
'First argument to define() must be a string literal.'); pht(
'First argument to %s must be a string literal.',
'define()'));
} }
} }
} }
@ -2418,7 +2533,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$variable, $variable,
self::LINT_STATIC_THIS, self::LINT_STATIC_THIS,
'You can not reference "$this" inside a static method.'); pht(
'You can not reference `%s` inside a static method.',
'$this'));
} }
} }
} }
@ -2441,9 +2558,14 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$call, $call,
self::LINT_PREG_QUOTE_MISUSE, self::LINT_PREG_QUOTE_MISUSE,
'If you use pattern delimiters that require escaping (such as //, '. pht(
'but not ()) then you should pass two arguments to preg_quote(), '. 'If you use pattern delimiters that require escaping '.
'so that preg_quote() knows which delimiter to escape.'); '(such as `%s`, but not `%s`) then you should pass two '.
'arguments to %s, so that %s knows which delimiter to escape.',
'//',
'()',
'preg_quote()',
'preg_quote()'));
} }
} }
} }
@ -2473,7 +2595,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$unary, $unary,
self::LINT_EXIT_EXPRESSION, self::LINT_EXIT_EXPRESSION,
'Use exit as a statement, not an expression.'); pht('Use `%s` as a statement, not an expression.', 'exit'));
} }
} }
} }
@ -2490,7 +2612,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtOffset( $this->raiseLintAtOffset(
$last->getOffset() + strlen($last->getValue()), $last->getOffset() + strlen($last->getValue()),
self::LINT_ARRAY_INDEX_SPACING, self::LINT_ARRAY_INDEX_SPACING,
'Convention: no spaces before index access.', pht('Convention: no spaces before index access.'),
$trailing_text, $trailing_text,
''); '');
} }
@ -2523,7 +2645,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtOffset( $this->raiseLintAtOffset(
$token->getOffset() + $offset, $token->getOffset() + $offset,
self::LINT_TODO_COMMENT, self::LINT_TODO_COMMENT,
'This comment has a TODO.', pht('This comment has a TODO.'),
$string); $string);
} }
} }
@ -2566,8 +2688,10 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$decl_name, $decl_name,
self::LINT_CLASS_FILENAME_MISMATCH, self::LINT_CLASS_FILENAME_MISMATCH,
"The name of this file differs from the name of the class or interface ". pht(
"it declares. Rename the file to '{$rename}'."); "The name of this file differs from the name of the ".
"class or interface it declares. Rename the file to '%s'.",
$rename));
} }
private function lintPlusOperatorOnStrings(XHPASTNode $root) { private function lintPlusOperatorOnStrings(XHPASTNode $root) {
@ -2585,8 +2709,11 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtNode( $this->raiseLintAtNode(
$binop, $binop,
self::LINT_PLUS_OPERATOR_ON_STRINGS, self::LINT_PLUS_OPERATOR_ON_STRINGS,
"In PHP, '.' is the string concatenation operator, not '+'. This ". pht(
"expression uses '+' with a string literal as an operand."); "In PHP, '%s' is the string concatenation operator, not '%s'. ".
"This expression uses '+' with a string literal as an operand.",
'.',
'+'));
} }
} }
} }
@ -2639,8 +2766,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$message = $this->raiseLintAtNode( $message = $this->raiseLintAtNode(
$node, $node,
self::LINT_DUPLICATE_KEYS_IN_ARRAY, self::LINT_DUPLICATE_KEYS_IN_ARRAY,
pht(
'Duplicate key in array initializer. PHP will ignore all '. 'Duplicate key in array initializer. PHP will ignore all '.
'but the last entry.'); 'but the last entry.'));
$locations = array(); $locations = array();
foreach ($nodes_by_key[$key] as $node) { foreach ($nodes_by_key[$key] as $node) {
@ -2677,7 +2805,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtOffset( $this->raiseLintAtOffset(
$last->getOffset() - strlen($trailing_text), $last->getOffset() - strlen($trailing_text),
self::LINT_CLOSING_CALL_PAREN, self::LINT_CLOSING_CALL_PAREN,
'Convention: no spaces before closing parenthesis in calls.', pht('Convention: no spaces before closing parenthesis in calls.'),
$trailing_text, $trailing_text,
''); '');
} }
@ -2699,8 +2827,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtOffset( $this->raiseLintAtOffset(
$last->getOffset() - strlen($trailing_text), $last->getOffset() - strlen($trailing_text),
self::LINT_CLOSING_DECL_PAREN, self::LINT_CLOSING_DECL_PAREN,
'Convention: no spaces before closing parenthesis in function and '. pht(
'method declarations.', 'Convention: no spaces before closing parenthesis in '.
'function and method declarations.'),
$trailing_text, $trailing_text,
''); '');
} }
@ -2930,7 +3059,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$token, $token,
self::LINT_ELSEIF_USAGE, self::LINT_ELSEIF_USAGE,
pht('Usage of `else if` is preferred over `elseif`.'), pht('Usage of `%s` is preferred over `%s`.', 'else if', 'elseif'),
'else if'); 'else if');
} }
} }