1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-02-11 14:28:31 +01:00
phorge-arcanist/src/workflow/ArcanistLintersWorkflow.php

307 lines
7.8 KiB
PHP
Raw Normal View History

<?php
/**
* List available linters.
*/
final class ArcanistLintersWorkflow extends ArcanistWorkflow {
public function getWorkflowName() {
return 'linters';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**linters** [__options__] [__name__]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(pht(<<<EOTEXT
Supports: cli
List the available and configured linters, with information about
what they do and which versions are installed.
if __name__ is provided, the linter with that name will be displayed.
EOTEXT
));
}
public function getArguments() {
return array(
'verbose' => array(
'help' => pht('Show detailed information, including options.'),
),
'search' => array(
'param' => 'search',
'repeat' => true,
'help' => pht(
'Search for linters. Search is case-insensitive, and is performed'.
'against name and description of each linter.'),
),
'*' => 'exact',
);
}
public function run() {
$console = PhutilConsole::getConsole();
$linters = id(new PhutilClassMapQuery())
->setAncestorClass('ArcanistLinter')
->execute();
try {
$built = $this->newLintEngine()->buildLinters();
} catch (ArcanistNoEngineException $ex) {
$built = array();
}
$linter_info = $this->getLintersInfo($linters, $built);
$status_map = $this->getStatusMap();
$pad = ' ';
$color_map = array(
'configured' => 'green',
'available' => 'yellow',
'error' => 'red',
);
$is_verbose = $this->getArgument('verbose');
$exact = $this->getArgument('exact');
$search_terms = $this->getArgument('search');
if ($exact && $search_terms) {
throw new ArcanistUsageException(
'Specify either search expression or exact name');
}
if ($exact) {
$linter_info = $this->findExactNames($linter_info, $exact);
Add a table showing all XHPAST linter rules to the output of `arc linters xhpast` Summary: Now that we have 91 subclasses of `ArcanistXHPASTLinterRule`, it is becoming difficult to manage the IDs. This diff adds a table to `arc linters xhpast` workflow to facilitate this. Test Plan: ``` > arc xhpast-linter-rules +=====+=======================================================+===================================================================+ | ID | Class | Name | +=====+=======================================================+===================================================================+ | 1 | ArcanistSyntaxErrorXHPASTLinterRule | PHP Syntax Error! | | 2 | ArcanistUnableToParseXHPASTLinterRule | Unable to Parse | | 3 | ArcanistVariableVariableXHPASTLinterRule | Use of Variable Variable | | 4 | ArcanistExtractUseXHPASTLinterRule | Use of `extract` | | 5 | ArcanistUndeclaredVariableXHPASTLinterRule | Use of Undeclared Variable | | 6 | ArcanistPHPShortTagXHPASTLinterRule | Use of Short Tag `<?` | | 7 | ArcanistPHPEchoTagXHPASTLinterRule | Use of Echo Tag `<?=` | | 8 | ArcanistPHPCloseTagXHPASTLinterRule | Use of Close Tag `?>` | | 9 | ArcanistNamingConventionsXHPASTLinterRule | Naming Conventions | | 10 | ArcanistImplicitConstructorXHPASTLinterRule | Implicit Constructor | | 12 | ArcanistDynamicDefineXHPASTLinterRule | Dynamic `define` | | 13 | ArcanistStaticThisXHPASTLinterRule | Use of `$this` in Static Context | | 14 | ArcanistPregQuoteMisuseXHPASTLinterRule | Misuse of `preg_quote` | | 15 | ArcanistPHPOpenTagXHPASTLinterRule | Expected Open Tag | | 16 | ArcanistTodoCommentXHPASTLinterRule | TODO Comment | | 17 | ArcanistExitExpressionXHPASTLinterRule | `exit` Used as Expression | | 18 | ArcanistCommentStyleXHPASTLinterRule | Comment Style | | 19 | ArcanistClassFilenameMismatchXHPASTLinterRule | Class-Filename Mismatch | | 20 | ArcanistTautologicalExpressionXHPASTLinterRule | Tautological Expression | | 21 | ArcanistPlusOperatorOnStringsXHPASTLinterRule | Not String Concatenation | | 22 | ArcanistDuplicateKeysInArrayXHPASTLinterRule | Duplicate Keys in Array | | 23 | ArcanistReusedIteratorXHPASTLinterRule | Reuse of Iterator Variable | | 24 | ArcanistBraceFormattingXHPASTLinterRule | Brace Placement | | 25 | ArcanistParenthesesSpacingXHPASTLinterRule | Spaces Inside Parentheses | | 26 | ArcanistControlStatementSpacingXHPASTLinterRule | Space After Control Statement | | 27 | ArcanistBinaryExpressionSpacingXHPASTLinterRule | Space Around Binary Operator | | 28 | ArcanistArrayIndexSpacingXHPASTLinterRule | Spacing Before Array Index | | 30 | ArcanistImplicitFallthroughXHPASTLinterRule | Implicit Fallthrough | | 32 | ArcanistReusedAsIteratorXHPASTLinterRule | Variable Reused As Iterator | | 34 | ArcanistCommentSpacingXHPASTLinterRule | Comment Spaces | | 36 | ArcanistSlownessXHPASTLinterRule | Slow Construct | | 37 | ArcanistCallParenthesesXHPASTLinterRule | Call Formatting | | 38 | ArcanistDeclarationParenthesesXHPASTLinterRule | Declaration Formatting | | 39 | ArcanistReusedIteratorReferenceXHPASTLinterRule | Reuse of Iterator References | | 40 | ArcanistKeywordCasingXHPASTLinterRule | Keyword Conventions | | 41 | ArcanistDoubleQuoteXHPASTLinterRule | Unnecessary Double Quotes | | 42 | ArcanistElseIfUsageXHPASTLinterRule | `elseif` Usage | | 43 | ArcanistSemicolonSpacingXHPASTLinterRule | Semicolon Spacing | | 44 | ArcanistConcatenationOperatorXHPASTLinterRule | Concatenation Spacing | | 45 | ArcanistPHPCompatibilityXHPASTLinterRule | PHP Compatibility | | 46 | ArcanistLanguageConstructParenthesesXHPASTLinterRule | Language Construct Parentheses | | 47 | ArcanistEmptyStatementXHPASTLinterRule | Empty Block Statement | | 48 | ArcanistArraySeparatorXHPASTLinterRule | Array Separator | | 49 | ArcanistConstructorParenthesesXHPASTLinterRule | Constructor Parentheses | | 50 | ArcanistDuplicateSwitchCaseXHPASTLinterRule | Duplicate Case Statements | | 51 | ArcanistBlacklistedFunctionXHPASTLinterRule | Use of Blacklisted Function | | 52 | ArcanistImplicitVisibilityXHPASTLinterRule | Implicit Method Visibility | | 53 | ArcanistCallTimePassByReferenceXHPASTLinterRule | Call-Time Pass-By-Reference | | 54 | ArcanistFormattedStringXHPASTLinterRule | Formatted String | | 55 | ArcanistUnnecessaryFinalModifierXHPASTLinterRule | Unnecessary Final Modifier | | 56 | ArcanistUnnecessarySemicolonXHPASTLinterRule | Unnecessary Semicolon | | 57 | ArcanistSelfMemberReferenceXHPASTLinterRule | Self Member Reference | | 58 | ArcanistLogicalOperatorsXHPASTLinterRule | Logical Operators | | 59 | ArcanistInnerFunctionXHPASTLinterRule | Inner Functions | | 60 | ArcanistDefaultParametersXHPASTLinterRule | Default Parameters | | 61 | ArcanistLowercaseFunctionsXHPASTLinterRule | Lowercase Functions | | 62 | ArcanistClassNameLiteralXHPASTLinterRule | Class Name Literal | | 63 | ArcanistUselessOverridingMethodXHPASTLinterRule | Useless Overriding Method | | 64 | ArcanistNoParentScopeXHPASTLinterRule | No Parent Scope | | 65 | ArcanistAliasFunctionXHPASTLinterRule | Alias Functions | | 66 | ArcanistCastSpacingXHPASTLinterRule | Cast Spacing | | 67 | ArcanistToStringExceptionXHPASTLinterRule | Throwing Exception in `__toString` Method | | 68 | ArcanistLambdaFuncFunctionXHPASTLinterRule | `__lambda_func` Function | | 69 | ArcanistInstanceOfOperatorXHPASTLinterRule | `instanceof` Operator | | 70 | ArcanistInvalidDefaultParameterXHPASTLinterRule | Invalid Default Parameter | | 71 | ArcanistModifierOrderingXHPASTLinterRule | Modifier Ordering | | 72 | ArcanistInvalidModifiersXHPASTLinterRule | Invalid Modifiers | | 73 | ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule | Space After Unary Prefix Operator | | 74 | ArcanistObjectOperatorSpacingXHPASTLinterRule | Object Operator Spacing | | 75 | ArcanistUnaryPostfixExpressionSpacingXHPASTLinterRule | Space Before Unary Postfix Operator | | 76 | ArcanistArrayValueXHPASTLinterRule | Array Element | | 77 | ArcanistListAssignmentXHPASTLinterRule | List Assignment | | 78 | ArcanistInlineHTMLXHPASTLinterRule | Inline HTML | | 79 | ArcanistGlobalVariableXHPASTLinterRule | Global Variables | | 80 | ArcanistParseStrUseXHPASTLinterRule | Questionable Use of `parse_str` | | 81 | ArcanistNewlineAfterOpenTagXHPASTLinterRule | Newline After PHP Open Tag | | 82 | ArcanistEmptyFileXHPASTLinterRule | Empty File | | 83 | ArcanistParentMemberReferenceXHPASTLinterRule | Parent Member Reference | | 84 | ArcanistArrayCombineXHPASTLinterRule | `array_combine()` Unreliable | | 85 | ArcanistDeprecationXHPASTLinterRule | Use of Deprecated Function | | 86 | ArcanistUnsafeDynamicStringXHPASTLinterRule | Unsafe Usage of Dynamic String | | 87 | ArcanistRaggedClassTreeEdgeXHPASTLinterRule | Class Not `abstract` Or `final` | | 88 | ArcanistClassExtendsObjectXHPASTLinterRule | Class Not Extending `Phobject` | | 90 | ArcanistNestedNamespacesXHPASTLinterRule | Nested `namespace` Statements | | 91 | ArcanistThisReassignmentXHPASTLinterRule | `$this` Reassignment | | 92 | ArcanistUnexpectedReturnValueXHPASTLinterRule | Unexpected `return` Value | | 97 | ArcanistUseStatementNamespacePrefixXHPASTLinterRule | `use` Statement Namespace Prefix | | 99 | ArcanistUnnecessarySymbolAliasXHPASTLinterRule | Unnecessary Symbol Alias | | 107 | ArcanistAbstractPrivateMethodXHPASTLinterRule | `abstract` Method Cannot Be Declared `private` | | 108 | ArcanistAbstractMethodBodyXHPASTLinterRule | `abstract` Method Cannot Contain Body | | 113 | ArcanistClassMustBeDeclaredAbstractXHPASTLinterRule | `class` Containing `abstract` Methods Must Be Declared `abstract` | +=====+=======================================================+===================================================================+ ``` Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D14563
2015-12-02 06:25:22 +11:00
if (!$linter_info) {
$console->writeOut(
"%s\n",
pht(
'No match found. Try `%s %s` to search for a linter.',
'arc linters --search',
$exact[0]));
return;
}
$is_verbose = true;
}
if ($search_terms) {
$linter_info = $this->filterByNames($linter_info, $search_terms);
}
foreach ($linter_info as $key => $linter) {
$status = $linter['status'];
$color = $color_map[$status];
$text = $status_map[$status];
$print_tail = false;
$console->writeOut(
"<bg:".$color.">** %s **</bg> **%s** (%s)\n",
$text,
nonempty($linter['name'], '-'),
$linter['short']);
if ($linter['exception']) {
$console->writeOut(
"\n%s**%s**\n%s\n",
$pad,
get_class($linter['exception']),
phutil_console_wrap(
$linter['exception']->getMessage(),
strlen($pad)));
$print_tail = true;
}
if ($is_verbose) {
$version = $linter['version'];
$uri = $linter['uri'];
if ($version || $uri) {
$console->writeOut("\n");
$print_tail = true;
}
if ($version) {
$console->writeOut("%s%s **%s**\n", $pad, pht('Version'), $version);
}
if ($uri) {
$console->writeOut("%s__%s__\n", $pad, $linter['uri']);
}
$description = $linter['description'];
if ($description) {
$console->writeOut(
"\n%s\n",
phutil_console_wrap($linter['description'], strlen($pad)));
$print_tail = true;
}
$options = $linter['options'];
if ($options) {
$console->writeOut(
"\n%s**%s**\n\n",
$pad,
pht('Configuration Options'));
$last_option = last_key($options);
foreach ($options as $option => $option_spec) {
$console->writeOut(
"%s__%s__ (%s)\n",
$pad,
$option,
$option_spec['type']);
$console->writeOut(
"%s\n",
phutil_console_wrap(
$option_spec['help'],
strlen($pad) + 2));
if ($option != $last_option) {
$console->writeOut("\n");
}
}
$print_tail = true;
}
Add a table showing all XHPAST linter rules to the output of `arc linters xhpast` Summary: Now that we have 91 subclasses of `ArcanistXHPASTLinterRule`, it is becoming difficult to manage the IDs. This diff adds a table to `arc linters xhpast` workflow to facilitate this. Test Plan: ``` > arc xhpast-linter-rules +=====+=======================================================+===================================================================+ | ID | Class | Name | +=====+=======================================================+===================================================================+ | 1 | ArcanistSyntaxErrorXHPASTLinterRule | PHP Syntax Error! | | 2 | ArcanistUnableToParseXHPASTLinterRule | Unable to Parse | | 3 | ArcanistVariableVariableXHPASTLinterRule | Use of Variable Variable | | 4 | ArcanistExtractUseXHPASTLinterRule | Use of `extract` | | 5 | ArcanistUndeclaredVariableXHPASTLinterRule | Use of Undeclared Variable | | 6 | ArcanistPHPShortTagXHPASTLinterRule | Use of Short Tag `<?` | | 7 | ArcanistPHPEchoTagXHPASTLinterRule | Use of Echo Tag `<?=` | | 8 | ArcanistPHPCloseTagXHPASTLinterRule | Use of Close Tag `?>` | | 9 | ArcanistNamingConventionsXHPASTLinterRule | Naming Conventions | | 10 | ArcanistImplicitConstructorXHPASTLinterRule | Implicit Constructor | | 12 | ArcanistDynamicDefineXHPASTLinterRule | Dynamic `define` | | 13 | ArcanistStaticThisXHPASTLinterRule | Use of `$this` in Static Context | | 14 | ArcanistPregQuoteMisuseXHPASTLinterRule | Misuse of `preg_quote` | | 15 | ArcanistPHPOpenTagXHPASTLinterRule | Expected Open Tag | | 16 | ArcanistTodoCommentXHPASTLinterRule | TODO Comment | | 17 | ArcanistExitExpressionXHPASTLinterRule | `exit` Used as Expression | | 18 | ArcanistCommentStyleXHPASTLinterRule | Comment Style | | 19 | ArcanistClassFilenameMismatchXHPASTLinterRule | Class-Filename Mismatch | | 20 | ArcanistTautologicalExpressionXHPASTLinterRule | Tautological Expression | | 21 | ArcanistPlusOperatorOnStringsXHPASTLinterRule | Not String Concatenation | | 22 | ArcanistDuplicateKeysInArrayXHPASTLinterRule | Duplicate Keys in Array | | 23 | ArcanistReusedIteratorXHPASTLinterRule | Reuse of Iterator Variable | | 24 | ArcanistBraceFormattingXHPASTLinterRule | Brace Placement | | 25 | ArcanistParenthesesSpacingXHPASTLinterRule | Spaces Inside Parentheses | | 26 | ArcanistControlStatementSpacingXHPASTLinterRule | Space After Control Statement | | 27 | ArcanistBinaryExpressionSpacingXHPASTLinterRule | Space Around Binary Operator | | 28 | ArcanistArrayIndexSpacingXHPASTLinterRule | Spacing Before Array Index | | 30 | ArcanistImplicitFallthroughXHPASTLinterRule | Implicit Fallthrough | | 32 | ArcanistReusedAsIteratorXHPASTLinterRule | Variable Reused As Iterator | | 34 | ArcanistCommentSpacingXHPASTLinterRule | Comment Spaces | | 36 | ArcanistSlownessXHPASTLinterRule | Slow Construct | | 37 | ArcanistCallParenthesesXHPASTLinterRule | Call Formatting | | 38 | ArcanistDeclarationParenthesesXHPASTLinterRule | Declaration Formatting | | 39 | ArcanistReusedIteratorReferenceXHPASTLinterRule | Reuse of Iterator References | | 40 | ArcanistKeywordCasingXHPASTLinterRule | Keyword Conventions | | 41 | ArcanistDoubleQuoteXHPASTLinterRule | Unnecessary Double Quotes | | 42 | ArcanistElseIfUsageXHPASTLinterRule | `elseif` Usage | | 43 | ArcanistSemicolonSpacingXHPASTLinterRule | Semicolon Spacing | | 44 | ArcanistConcatenationOperatorXHPASTLinterRule | Concatenation Spacing | | 45 | ArcanistPHPCompatibilityXHPASTLinterRule | PHP Compatibility | | 46 | ArcanistLanguageConstructParenthesesXHPASTLinterRule | Language Construct Parentheses | | 47 | ArcanistEmptyStatementXHPASTLinterRule | Empty Block Statement | | 48 | ArcanistArraySeparatorXHPASTLinterRule | Array Separator | | 49 | ArcanistConstructorParenthesesXHPASTLinterRule | Constructor Parentheses | | 50 | ArcanistDuplicateSwitchCaseXHPASTLinterRule | Duplicate Case Statements | | 51 | ArcanistBlacklistedFunctionXHPASTLinterRule | Use of Blacklisted Function | | 52 | ArcanistImplicitVisibilityXHPASTLinterRule | Implicit Method Visibility | | 53 | ArcanistCallTimePassByReferenceXHPASTLinterRule | Call-Time Pass-By-Reference | | 54 | ArcanistFormattedStringXHPASTLinterRule | Formatted String | | 55 | ArcanistUnnecessaryFinalModifierXHPASTLinterRule | Unnecessary Final Modifier | | 56 | ArcanistUnnecessarySemicolonXHPASTLinterRule | Unnecessary Semicolon | | 57 | ArcanistSelfMemberReferenceXHPASTLinterRule | Self Member Reference | | 58 | ArcanistLogicalOperatorsXHPASTLinterRule | Logical Operators | | 59 | ArcanistInnerFunctionXHPASTLinterRule | Inner Functions | | 60 | ArcanistDefaultParametersXHPASTLinterRule | Default Parameters | | 61 | ArcanistLowercaseFunctionsXHPASTLinterRule | Lowercase Functions | | 62 | ArcanistClassNameLiteralXHPASTLinterRule | Class Name Literal | | 63 | ArcanistUselessOverridingMethodXHPASTLinterRule | Useless Overriding Method | | 64 | ArcanistNoParentScopeXHPASTLinterRule | No Parent Scope | | 65 | ArcanistAliasFunctionXHPASTLinterRule | Alias Functions | | 66 | ArcanistCastSpacingXHPASTLinterRule | Cast Spacing | | 67 | ArcanistToStringExceptionXHPASTLinterRule | Throwing Exception in `__toString` Method | | 68 | ArcanistLambdaFuncFunctionXHPASTLinterRule | `__lambda_func` Function | | 69 | ArcanistInstanceOfOperatorXHPASTLinterRule | `instanceof` Operator | | 70 | ArcanistInvalidDefaultParameterXHPASTLinterRule | Invalid Default Parameter | | 71 | ArcanistModifierOrderingXHPASTLinterRule | Modifier Ordering | | 72 | ArcanistInvalidModifiersXHPASTLinterRule | Invalid Modifiers | | 73 | ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule | Space After Unary Prefix Operator | | 74 | ArcanistObjectOperatorSpacingXHPASTLinterRule | Object Operator Spacing | | 75 | ArcanistUnaryPostfixExpressionSpacingXHPASTLinterRule | Space Before Unary Postfix Operator | | 76 | ArcanistArrayValueXHPASTLinterRule | Array Element | | 77 | ArcanistListAssignmentXHPASTLinterRule | List Assignment | | 78 | ArcanistInlineHTMLXHPASTLinterRule | Inline HTML | | 79 | ArcanistGlobalVariableXHPASTLinterRule | Global Variables | | 80 | ArcanistParseStrUseXHPASTLinterRule | Questionable Use of `parse_str` | | 81 | ArcanistNewlineAfterOpenTagXHPASTLinterRule | Newline After PHP Open Tag | | 82 | ArcanistEmptyFileXHPASTLinterRule | Empty File | | 83 | ArcanistParentMemberReferenceXHPASTLinterRule | Parent Member Reference | | 84 | ArcanistArrayCombineXHPASTLinterRule | `array_combine()` Unreliable | | 85 | ArcanistDeprecationXHPASTLinterRule | Use of Deprecated Function | | 86 | ArcanistUnsafeDynamicStringXHPASTLinterRule | Unsafe Usage of Dynamic String | | 87 | ArcanistRaggedClassTreeEdgeXHPASTLinterRule | Class Not `abstract` Or `final` | | 88 | ArcanistClassExtendsObjectXHPASTLinterRule | Class Not Extending `Phobject` | | 90 | ArcanistNestedNamespacesXHPASTLinterRule | Nested `namespace` Statements | | 91 | ArcanistThisReassignmentXHPASTLinterRule | `$this` Reassignment | | 92 | ArcanistUnexpectedReturnValueXHPASTLinterRule | Unexpected `return` Value | | 97 | ArcanistUseStatementNamespacePrefixXHPASTLinterRule | `use` Statement Namespace Prefix | | 99 | ArcanistUnnecessarySymbolAliasXHPASTLinterRule | Unnecessary Symbol Alias | | 107 | ArcanistAbstractPrivateMethodXHPASTLinterRule | `abstract` Method Cannot Be Declared `private` | | 108 | ArcanistAbstractMethodBodyXHPASTLinterRule | `abstract` Method Cannot Contain Body | | 113 | ArcanistClassMustBeDeclaredAbstractXHPASTLinterRule | `class` Containing `abstract` Methods Must Be Declared `abstract` | +=====+=======================================================+===================================================================+ ``` Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D14563
2015-12-02 06:25:22 +11:00
$additional = $linter['additional'];
foreach ($additional as $title => $body) {
$console->writeOut(
"\n%s**%s**\n\n",
$pad,
$title);
// TODO: This should maybe use `tsprintf`.
// See some discussion in D14563.
echo $body;
}
if ($print_tail) {
$console->writeOut("\n");
}
}
}
if (!$is_verbose) {
$console->writeOut(
"%s\n",
pht('(Run `%s` for more details.)', 'arc linters --verbose'));
}
}
/**
* Get human-readable linter statuses, padded to fixed width.
*
* @return map<string, string> Human-readable linter status names.
*/
private function getStatusMap() {
$text_map = array(
'configured' => pht('CONFIGURED'),
'available' => pht('AVAILABLE'),
'error' => pht('ERROR'),
);
$sizes = array();
foreach ($text_map as $key => $string) {
$sizes[$key] = phutil_utf8_console_strlen($string);
}
$longest = max($sizes);
foreach ($text_map as $key => $string) {
if ($sizes[$key] < $longest) {
$text_map[$key] .= str_repeat(' ', $longest - $sizes[$key]);
}
}
$text_map['padding'] = str_repeat(' ', $longest);
return $text_map;
}
private function getLintersInfo(array $linters, array $built) {
// Note that an engine can emit multiple linters of the same class to run
// different rulesets on different groups of files, so these linters do not
// necessarily have unique classes or types.
$groups = array();
foreach ($built as $linter) {
$groups[get_class($linter)][] = $linter;
}
$linter_info = array();
foreach ($linters as $key => $linter) {
$installed = idx($groups, $key, array());
$exception = null;
if ($installed) {
$status = 'configured';
try {
$version = head($installed)->getVersion();
} catch (Exception $ex) {
$status = 'error';
$exception = $ex;
}
} else {
$status = 'available';
$version = null;
}
$linter_info[$key] = array(
'name' => $linter->getLinterConfigurationName(),
'class' => get_class($linter),
'status' => $status,
'version' => $version,
'short' => $linter->getInfoName(),
'uri' => $linter->getInfoURI(),
'description' => $linter->getInfoDescription(),
'exception' => $exception,
'options' => $linter->getLinterConfigurationOptions(),
Add a table showing all XHPAST linter rules to the output of `arc linters xhpast` Summary: Now that we have 91 subclasses of `ArcanistXHPASTLinterRule`, it is becoming difficult to manage the IDs. This diff adds a table to `arc linters xhpast` workflow to facilitate this. Test Plan: ``` > arc xhpast-linter-rules +=====+=======================================================+===================================================================+ | ID | Class | Name | +=====+=======================================================+===================================================================+ | 1 | ArcanistSyntaxErrorXHPASTLinterRule | PHP Syntax Error! | | 2 | ArcanistUnableToParseXHPASTLinterRule | Unable to Parse | | 3 | ArcanistVariableVariableXHPASTLinterRule | Use of Variable Variable | | 4 | ArcanistExtractUseXHPASTLinterRule | Use of `extract` | | 5 | ArcanistUndeclaredVariableXHPASTLinterRule | Use of Undeclared Variable | | 6 | ArcanistPHPShortTagXHPASTLinterRule | Use of Short Tag `<?` | | 7 | ArcanistPHPEchoTagXHPASTLinterRule | Use of Echo Tag `<?=` | | 8 | ArcanistPHPCloseTagXHPASTLinterRule | Use of Close Tag `?>` | | 9 | ArcanistNamingConventionsXHPASTLinterRule | Naming Conventions | | 10 | ArcanistImplicitConstructorXHPASTLinterRule | Implicit Constructor | | 12 | ArcanistDynamicDefineXHPASTLinterRule | Dynamic `define` | | 13 | ArcanistStaticThisXHPASTLinterRule | Use of `$this` in Static Context | | 14 | ArcanistPregQuoteMisuseXHPASTLinterRule | Misuse of `preg_quote` | | 15 | ArcanistPHPOpenTagXHPASTLinterRule | Expected Open Tag | | 16 | ArcanistTodoCommentXHPASTLinterRule | TODO Comment | | 17 | ArcanistExitExpressionXHPASTLinterRule | `exit` Used as Expression | | 18 | ArcanistCommentStyleXHPASTLinterRule | Comment Style | | 19 | ArcanistClassFilenameMismatchXHPASTLinterRule | Class-Filename Mismatch | | 20 | ArcanistTautologicalExpressionXHPASTLinterRule | Tautological Expression | | 21 | ArcanistPlusOperatorOnStringsXHPASTLinterRule | Not String Concatenation | | 22 | ArcanistDuplicateKeysInArrayXHPASTLinterRule | Duplicate Keys in Array | | 23 | ArcanistReusedIteratorXHPASTLinterRule | Reuse of Iterator Variable | | 24 | ArcanistBraceFormattingXHPASTLinterRule | Brace Placement | | 25 | ArcanistParenthesesSpacingXHPASTLinterRule | Spaces Inside Parentheses | | 26 | ArcanistControlStatementSpacingXHPASTLinterRule | Space After Control Statement | | 27 | ArcanistBinaryExpressionSpacingXHPASTLinterRule | Space Around Binary Operator | | 28 | ArcanistArrayIndexSpacingXHPASTLinterRule | Spacing Before Array Index | | 30 | ArcanistImplicitFallthroughXHPASTLinterRule | Implicit Fallthrough | | 32 | ArcanistReusedAsIteratorXHPASTLinterRule | Variable Reused As Iterator | | 34 | ArcanistCommentSpacingXHPASTLinterRule | Comment Spaces | | 36 | ArcanistSlownessXHPASTLinterRule | Slow Construct | | 37 | ArcanistCallParenthesesXHPASTLinterRule | Call Formatting | | 38 | ArcanistDeclarationParenthesesXHPASTLinterRule | Declaration Formatting | | 39 | ArcanistReusedIteratorReferenceXHPASTLinterRule | Reuse of Iterator References | | 40 | ArcanistKeywordCasingXHPASTLinterRule | Keyword Conventions | | 41 | ArcanistDoubleQuoteXHPASTLinterRule | Unnecessary Double Quotes | | 42 | ArcanistElseIfUsageXHPASTLinterRule | `elseif` Usage | | 43 | ArcanistSemicolonSpacingXHPASTLinterRule | Semicolon Spacing | | 44 | ArcanistConcatenationOperatorXHPASTLinterRule | Concatenation Spacing | | 45 | ArcanistPHPCompatibilityXHPASTLinterRule | PHP Compatibility | | 46 | ArcanistLanguageConstructParenthesesXHPASTLinterRule | Language Construct Parentheses | | 47 | ArcanistEmptyStatementXHPASTLinterRule | Empty Block Statement | | 48 | ArcanistArraySeparatorXHPASTLinterRule | Array Separator | | 49 | ArcanistConstructorParenthesesXHPASTLinterRule | Constructor Parentheses | | 50 | ArcanistDuplicateSwitchCaseXHPASTLinterRule | Duplicate Case Statements | | 51 | ArcanistBlacklistedFunctionXHPASTLinterRule | Use of Blacklisted Function | | 52 | ArcanistImplicitVisibilityXHPASTLinterRule | Implicit Method Visibility | | 53 | ArcanistCallTimePassByReferenceXHPASTLinterRule | Call-Time Pass-By-Reference | | 54 | ArcanistFormattedStringXHPASTLinterRule | Formatted String | | 55 | ArcanistUnnecessaryFinalModifierXHPASTLinterRule | Unnecessary Final Modifier | | 56 | ArcanistUnnecessarySemicolonXHPASTLinterRule | Unnecessary Semicolon | | 57 | ArcanistSelfMemberReferenceXHPASTLinterRule | Self Member Reference | | 58 | ArcanistLogicalOperatorsXHPASTLinterRule | Logical Operators | | 59 | ArcanistInnerFunctionXHPASTLinterRule | Inner Functions | | 60 | ArcanistDefaultParametersXHPASTLinterRule | Default Parameters | | 61 | ArcanistLowercaseFunctionsXHPASTLinterRule | Lowercase Functions | | 62 | ArcanistClassNameLiteralXHPASTLinterRule | Class Name Literal | | 63 | ArcanistUselessOverridingMethodXHPASTLinterRule | Useless Overriding Method | | 64 | ArcanistNoParentScopeXHPASTLinterRule | No Parent Scope | | 65 | ArcanistAliasFunctionXHPASTLinterRule | Alias Functions | | 66 | ArcanistCastSpacingXHPASTLinterRule | Cast Spacing | | 67 | ArcanistToStringExceptionXHPASTLinterRule | Throwing Exception in `__toString` Method | | 68 | ArcanistLambdaFuncFunctionXHPASTLinterRule | `__lambda_func` Function | | 69 | ArcanistInstanceOfOperatorXHPASTLinterRule | `instanceof` Operator | | 70 | ArcanistInvalidDefaultParameterXHPASTLinterRule | Invalid Default Parameter | | 71 | ArcanistModifierOrderingXHPASTLinterRule | Modifier Ordering | | 72 | ArcanistInvalidModifiersXHPASTLinterRule | Invalid Modifiers | | 73 | ArcanistUnaryPrefixExpressionSpacingXHPASTLinterRule | Space After Unary Prefix Operator | | 74 | ArcanistObjectOperatorSpacingXHPASTLinterRule | Object Operator Spacing | | 75 | ArcanistUnaryPostfixExpressionSpacingXHPASTLinterRule | Space Before Unary Postfix Operator | | 76 | ArcanistArrayValueXHPASTLinterRule | Array Element | | 77 | ArcanistListAssignmentXHPASTLinterRule | List Assignment | | 78 | ArcanistInlineHTMLXHPASTLinterRule | Inline HTML | | 79 | ArcanistGlobalVariableXHPASTLinterRule | Global Variables | | 80 | ArcanistParseStrUseXHPASTLinterRule | Questionable Use of `parse_str` | | 81 | ArcanistNewlineAfterOpenTagXHPASTLinterRule | Newline After PHP Open Tag | | 82 | ArcanistEmptyFileXHPASTLinterRule | Empty File | | 83 | ArcanistParentMemberReferenceXHPASTLinterRule | Parent Member Reference | | 84 | ArcanistArrayCombineXHPASTLinterRule | `array_combine()` Unreliable | | 85 | ArcanistDeprecationXHPASTLinterRule | Use of Deprecated Function | | 86 | ArcanistUnsafeDynamicStringXHPASTLinterRule | Unsafe Usage of Dynamic String | | 87 | ArcanistRaggedClassTreeEdgeXHPASTLinterRule | Class Not `abstract` Or `final` | | 88 | ArcanistClassExtendsObjectXHPASTLinterRule | Class Not Extending `Phobject` | | 90 | ArcanistNestedNamespacesXHPASTLinterRule | Nested `namespace` Statements | | 91 | ArcanistThisReassignmentXHPASTLinterRule | `$this` Reassignment | | 92 | ArcanistUnexpectedReturnValueXHPASTLinterRule | Unexpected `return` Value | | 97 | ArcanistUseStatementNamespacePrefixXHPASTLinterRule | `use` Statement Namespace Prefix | | 99 | ArcanistUnnecessarySymbolAliasXHPASTLinterRule | Unnecessary Symbol Alias | | 107 | ArcanistAbstractPrivateMethodXHPASTLinterRule | `abstract` Method Cannot Be Declared `private` | | 108 | ArcanistAbstractMethodBodyXHPASTLinterRule | `abstract` Method Cannot Contain Body | | 113 | ArcanistClassMustBeDeclaredAbstractXHPASTLinterRule | `class` Containing `abstract` Methods Must Be Declared `abstract` | +=====+=======================================================+===================================================================+ ``` Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D14563
2015-12-02 06:25:22 +11:00
'additional' => $linter->getAdditionalInformation(),
);
}
return isort($linter_info, 'short');
}
private function filterByNames(array $linters, array $search_terms) {
$filtered = array();
foreach ($linters as $key => $linter) {
$name = $linter['name'];
$short = $linter['short'];
$description = $linter['description'];
foreach ($search_terms as $term) {
if (stripos($name, $term) !== false ||
stripos($short, $term) !== false ||
stripos($description, $term) !== false) {
$filtered[$key] = $linter;
}
}
}
return $filtered;
}
private function findExactNames(array $linters, array $names) {
$filtered = array();
foreach ($linters as $key => $linter) {
$name = $linter['name'];
foreach ($names as $term) {
if (strcasecmp($name, $term) == 0) {
$filtered[$key] = $linter;
}
}
}
return $filtered;
}
}