Michael Akinde [Thu, 14 Jan 2016 14:59:10 +0000 (06:59 -0800)]
Minor fixes to arcanist cpplint
Summary:
This fixes the regex in "getLintCode..." so that it accepts lint
codes such as `build/c++11` which have become valid lint codes
in later versions of cpplint.
It also corrects the install instructions for the linter (Google's
style guide is no longer available on SVN and has been migrated to
Github).
Test Plan:
For the Regex:
- Create an .arclint in a project such as:
```
{
"linters": {
"cpplint": {
"type": "cpplint",
"severity": {
"build/c++11": "advice"
}
}
}
}
```
- Run `arc lint` with the existing linter. This should fail. Patch the linter, and this should now be accepted.
For the Instructions
- Verify the download location `wget https://raw.github.com/google/styleguide/gh-pages/cpplint/cpplint.py`
epriestley [Tue, 12 Jan 2016 01:18:58 +0000 (17:18 -0800)]
If the Script-and-Regex linter captures no "line" text, treat the message as affecting the entire file
Summary: Fixes T10124.
Test Plan:
Added this "linter" to `.arclint`:
```
"thing": {
"type": "script-and-regex",
"script-and-regex.script": "echo every file is very bad #",
"script-and-regex.regex": "/^(?P<message>.*)/"
}
```
...to produce this diff. Also made a variant of it which matches lines to make sure that still works.
John Allen [Wed, 6 Jan 2016 21:15:09 +0000 (13:15 -0800)]
Fix cpplint message regex
Summary:
ref T8404
The issue is caused, not by the non-zero return code, but by the fact that
$messages is coming back empty due to the incorrect regex. tyhoff pointed out
that the regex matched correctly when we used STDIN, but now it is failing.
Test Plan:
arc lint cpp file containing lint error. run cpplint on the
file directly to confirm that there are errors and that the return code
is non-zero
epriestley [Tue, 5 Jan 2016 18:10:06 +0000 (10:10 -0800)]
(stable) Fix `arc diff --raw` with "onto" target properties
Summary:
Currently, `git show | arc diff --raw` and similar doesn't work because we try to figure out what the "Branch: feature (branched from whatever)" value is, which doesn't make sense.
```
$ git show | arc diff --raw --trace
ARGV '/Users/epriestley/dev/core/lib/arcanist/bin/../scripts/arcanist.php' 'diff' '--raw' '--trace'
LOAD Loaded "phutil" from "/Users/epriestley/dev/core/lib/libphutil/src".
LOAD Loaded "arcanist" from "/Users/epriestley/dev/core/lib/arcanist/src".
Config: Reading user configuration file "/Users/epriestley/.arcrc"...
Config: Did not find system configuration at "/etc/arcconfig".
Working Copy: Reading .arcconfig from "/Users/epriestley/dev/core/lib/arcanist/.arcconfig".
Working Copy: Path "/Users/epriestley/dev/core/lib/arcanist" is part of `git` working copy "/Users/epriestley/dev/core/lib/arcanist".
Working Copy: Project root is at "/Users/epriestley/dev/core/lib/arcanist".
Config: Reading local configuration file "/Users/epriestley/dev/core/lib/arcanist/.git/arc/config"...
Loading phutil library from '/Users/epriestley/dev/core/lib/arcanist/src'...
>>> [0] <conduit> conduit.connect() <bytes = 489>
>>> [1] <http> https://secure.phabricator.com/api/conduit.connect
<<< [1] <http> 211,217 us
<<< [0] <conduit> 212,001 us
>>> [2] <event> diff.didCollectChanges <listeners = 0>
<<< [2] <event> 140 us
>>> [3] <event> diff.didBuildMessage <listeners = 0>
<<< [3] <event> 46 us
Reading diff from stdin...
>>> [4] <conduit> differential.creatediff() <bytes = 10,542>
>>> [5] <http> https://secure.phabricator.com/api/differential.creatediff
<<< [5] <http> 120,215 us
<<< [4] <conduit> 120,411 us
>>> [6] <event> diff.wasCreated <listeners = 0>
<<< [6] <event> 41 us
SKIP STAGING Raw changes can not be pushed to a staging area.
>>> [7] <conduit> harbormaster.queryautotargets() <bytes = 290>
>>> [8] <http> https://secure.phabricator.com/api/harbormaster.queryautotargets
<<< [8] <http> 217,717 us
<<< [7] <conduit> 217,944 us
>>> [9] <conduit> harbormaster.sendmessage() <bytes = 274>
>>> [10] <http> https://secure.phabricator.com/api/harbormaster.sendmessage
>>> [11] <conduit> harbormaster.sendmessage() <bytes = 274>
>>> [12] <http> https://secure.phabricator.com/api/harbormaster.sendmessage
<<< [10] <http> 123,821 us
<<< [9] <conduit> 134,329 us
<<< [12] <http> 227,580 us
<<< [11] <conduit> 227,787 us
[2016-01-05 10:08:58] EXCEPTION: (Exception) This workflow ('ArcanistDiffWorkflow') requires a Repository API, override requiresRepositoryAPI() to return true. at [<arcanist>/src/workflow/ArcanistWorkflow.php:804]
arcanist(head=master, ref.master=b3e68c9f1793), phutil(head=stable, ref.master=adb8a9c074ba, ref.stable=7b8d38cd2d4e)
#0 ArcanistWorkflow::getRepositoryAPI() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:2421]
#1 ArcanistDiffWorkflow::getDiffOntoTargets() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:2411]
#2 ArcanistDiffWorkflow::updateOntoDiffProperty() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:534]
#3 ArcanistDiffWorkflow::run() called at [<arcanist>/scripts/arcanist.php:392]
```
Test Plan: Ran `arc diff --raw` in `phabricator/`.
epriestley [Tue, 5 Jan 2016 18:10:06 +0000 (10:10 -0800)]
Fix `arc diff --raw` with "onto" target properties
Summary:
Currently, `git show | arc diff --raw` and similar doesn't work because we try to figure out what the "Branch: feature (branched from whatever)" value is, which doesn't make sense.
```
$ git show | arc diff --raw --trace
ARGV '/Users/epriestley/dev/core/lib/arcanist/bin/../scripts/arcanist.php' 'diff' '--raw' '--trace'
LOAD Loaded "phutil" from "/Users/epriestley/dev/core/lib/libphutil/src".
LOAD Loaded "arcanist" from "/Users/epriestley/dev/core/lib/arcanist/src".
Config: Reading user configuration file "/Users/epriestley/.arcrc"...
Config: Did not find system configuration at "/etc/arcconfig".
Working Copy: Reading .arcconfig from "/Users/epriestley/dev/core/lib/arcanist/.arcconfig".
Working Copy: Path "/Users/epriestley/dev/core/lib/arcanist" is part of `git` working copy "/Users/epriestley/dev/core/lib/arcanist".
Working Copy: Project root is at "/Users/epriestley/dev/core/lib/arcanist".
Config: Reading local configuration file "/Users/epriestley/dev/core/lib/arcanist/.git/arc/config"...
Loading phutil library from '/Users/epriestley/dev/core/lib/arcanist/src'...
>>> [0] <conduit> conduit.connect() <bytes = 489>
>>> [1] <http> https://secure.phabricator.com/api/conduit.connect
<<< [1] <http> 211,217 us
<<< [0] <conduit> 212,001 us
>>> [2] <event> diff.didCollectChanges <listeners = 0>
<<< [2] <event> 140 us
>>> [3] <event> diff.didBuildMessage <listeners = 0>
<<< [3] <event> 46 us
Reading diff from stdin...
>>> [4] <conduit> differential.creatediff() <bytes = 10,542>
>>> [5] <http> https://secure.phabricator.com/api/differential.creatediff
<<< [5] <http> 120,215 us
<<< [4] <conduit> 120,411 us
>>> [6] <event> diff.wasCreated <listeners = 0>
<<< [6] <event> 41 us
SKIP STAGING Raw changes can not be pushed to a staging area.
>>> [7] <conduit> harbormaster.queryautotargets() <bytes = 290>
>>> [8] <http> https://secure.phabricator.com/api/harbormaster.queryautotargets
<<< [8] <http> 217,717 us
<<< [7] <conduit> 217,944 us
>>> [9] <conduit> harbormaster.sendmessage() <bytes = 274>
>>> [10] <http> https://secure.phabricator.com/api/harbormaster.sendmessage
>>> [11] <conduit> harbormaster.sendmessage() <bytes = 274>
>>> [12] <http> https://secure.phabricator.com/api/harbormaster.sendmessage
<<< [10] <http> 123,821 us
<<< [9] <conduit> 134,329 us
<<< [12] <http> 227,580 us
<<< [11] <conduit> 227,787 us
[2016-01-05 10:08:58] EXCEPTION: (Exception) This workflow ('ArcanistDiffWorkflow') requires a Repository API, override requiresRepositoryAPI() to return true. at [<arcanist>/src/workflow/ArcanistWorkflow.php:804]
arcanist(head=master, ref.master=b3e68c9f1793), phutil(head=stable, ref.master=adb8a9c074ba, ref.stable=7b8d38cd2d4e)
#0 ArcanistWorkflow::getRepositoryAPI() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:2421]
#1 ArcanistDiffWorkflow::getDiffOntoTargets() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:2411]
#2 ArcanistDiffWorkflow::updateOntoDiffProperty() called at [<arcanist>/src/workflow/ArcanistDiffWorkflow.php:534]
#3 ArcanistDiffWorkflow::run() called at [<arcanist>/scripts/arcanist.php:392]
```
Test Plan: Ran `arc diff --raw` in `phabricator/`.
Joshua Spence [Tue, 22 Dec 2015 21:39:44 +0000 (08:39 +1100)]
Improve the "self member reference" linter rule
Summary:
Extends `ArcanistSelfMemberReferenceXHPASTLinterRule` to warn about the use of a hardcoded class name instead of `self` when instantiating a class. Arguably, we should maybe rename the linter rule from `ArcanistSelfMemberReferenceXHPASTLinterRule` to `ArcanistSelfUsageXHPASTLinterRule`, or even maybe split this rule into three separate rules:
epriestley [Fri, 18 Dec 2015 00:16:05 +0000 (16:16 -0800)]
Use "--whitespace nowarn" in `arc patch` to respect trailing whitespace
Summary: Fixes T10008. Git tries to fix some issues by default (apparently? empirically; not consistent with documentation, I think?), but patches from `arc patch` are "always" accurate (disregarding other bugs we might have -- basically, they haven't been emailed or copy/pasted or anything like that) so we can just tell it to apply the patch exactly as-is.
epriestley [Sun, 13 Dec 2015 11:08:06 +0000 (03:08 -0800)]
Explain how to move forward or backward from `arc land --hold`
Summary: Fixes T9973. When users run `arc land --hold`, give them the commands to move forward (push) or backward (checkout the branch/tag/commit they were on) and be explicit that branches have not changed.
Test Plan: Ran `arc land --hold`, got lots of explanatory text.
Dimitry Andric [Sun, 13 Dec 2015 10:35:07 +0000 (02:35 -0800)]
Simplify diff exit code handling.
Summary:
This fixes T9970 in an alternate manner, with the same effect: the
binary_safe_diff.sh script returns 0 if the diff succeeds, 1 in all
other cases.
Test Plan:
Tested locally with a fixed binary_safe_diff.sh, resulting in this
correct review:
Dimitry Andric [Sun, 13 Dec 2015 10:21:43 +0000 (02:21 -0800)]
Preserve the exit code of the diff command in binary_safe_diff.sh
Summary:
Some versions of Subversion (1.9 in any case, maybe others) will
duplicate diff headers, if the diff command run through --diff-cmd
returns 0.
This lead to T9970, where the addition of a new file with properties
only shows the properties themselves in the review, not the content of
the new file.
Test Plan: This is a trivial change, is a test needed at all?
epriestley [Thu, 10 Dec 2015 22:33:33 +0000 (14:33 -0800)]
In `arc diff`, try to guess where a change should land
Summary:
Ref T9952. Ref T3462. My primary goal is to improve prefilling of the "Onto Branch:" field in the "Land Revision" dialog.
When uploading a diff with `arc diff`, add a property with some information about which branch to target. In particular:
- If the local branch tracks an upstream branch (or tracks something which tracks something which tracks the upstream), target that.
- If not, but "arc.land.onto.default" is set, target that.
This doesn't try to guess in other cases, since they're more involved. I'll add some context about this in T3462.
I don't //love// using "diff properties" for this, but it doesn't make cleaning them up any harder since we already use it for other stuff which isn't going away (lint/unit excuses).
Test Plan:
- Added some `var_dump()` and used `arc diff --only` to generate diffs.
- Saw upstream tracking and config-based rules generate reasonable values and submit them.
epriestley [Thu, 10 Dec 2015 22:10:02 +0000 (14:10 -0800)]
Don't use "-c" flag in "git:branch-unique()" revision range rule
Summary:
Fixes T9953.
- "-c" was introduced in 1.7.2.
- "--no-color" has existed forever as far as I can tell.
- "--no-column" was introducd in 1.7.11, but there was nothing that needed to be disabled before that (hopefully).
Test Plan:
- Ran `arc which --trace` and observed a reasonable `git branch` command with correct output.
- Ran `arc which --trace` with a faked older Git version, observed command omit `--no-column`.
Joshua Spence [Tue, 8 Dec 2015 19:56:48 +0000 (06:56 +1100)]
Add a linter rule for curly brace array indexes
Summary: In PHP, both `$x['key']` and `$x{'key'}` can be used to access an array (see http://stackoverflow.com/questions/8092248/php-curly-braces-in-array-notation), but the former should be preferred.
Joshua Spence [Wed, 2 Dec 2015 21:11:22 +0000 (08:11 +1100)]
Add a linter rule for invalid octals
Summary: PHP doesn't handle octals very well. Basically, it seems that any numeric scalar matching `/^0\d+$/` will be treated as an octal, whereas this should be `/^0[0-7]+$/`. As a result, `08` and `09` are both treated as `0` (because they are invalid octals. This diff adds a linter rule to detect this abnormality.
Joshua Spence [Tue, 1 Dec 2015 19:25:22 +0000 (06:25 +1100)]
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` |
+=====+=======================================================+===================================================================+
```
epriestley [Fri, 27 Nov 2015 16:35:17 +0000 (08:35 -0800)]
Improve error handling in `arc install-certificate`
Summary: Fixes T9858. Reasonable typos and misunderstandings currently produce very confusing error messages.
Test Plan:
```
$ arc install certificate
Usage Exception: Server URI "certificate" must include a protocol and domain. It should be in the form "https://phabricator.example.com/".
```
Joshua Spence [Wed, 25 Nov 2015 19:18:19 +0000 (06:18 +1100)]
Fix a compatibility issue with `ArcanistUnsafeDynamicStringXHPASTLinterRule`
Summary: A user reported to me that `arc lint` was failing with an error message along the lines of "argument 1 passed to `idx` must be of type array, bool given". I suspect that the user is running an older version of PHP, which means that `array_combine(array(), array())` is returning `false` instead of the expected `array()`. Instead, avoid calling `array_combine` on an empty array.
Test Plan: I don't have PHP 5.3 easily accessible to test this.
Joshua Spence [Mon, 23 Nov 2015 21:18:38 +0000 (08:18 +1100)]
Add a linter rule to determine whether a class should be marked as `abstract`
Summary:
A class containing `abstract` methods must itself be marked as `abstract`.
```
PHP Fatal error: Class X contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (X::Y) in /home/josh/workspace/github.com/phacility/arcanist/test.php on line 5
```
Joshua Spence [Mon, 23 Nov 2015 21:17:25 +0000 (08:17 +1100)]
Add a linter rule for unnecessary symbol aliases
Summary: Add a linter rule to detect symbols which are aliased with the same name, such as `use X\Y\Z as Z`. This is unnecessary and is more-simply expressed as `use X\Y\Z`.
Joshua Spence [Mon, 23 Nov 2015 19:42:39 +0000 (06:42 +1100)]
Add a linter rule for `use` statement namespace prefixes
Summary:
When importing or aliases a symbol with a `use` statement, the leading namespace separator is optional and does not modify the behavior. That is, `use \X` is equivalent to `use X`. As such, the latter syntax should be preferred because it is more concise.
According to the [[http://php.net/manual/en/language.namespaces.importing.php | PHP documentation]]:
> Note that for namespaced names (fully qualified namespace names containing namespace separator, such as `Foo\Bar` as opposed to global names that do not, such as `FooBar`), the leading backslash is unnecessary and not recommended, as import names must be fully qualified, and are not processed relative to the current namespace.
Alex Vandiver [Fri, 20 Nov 2015 06:28:02 +0000 (22:28 -0800)]
Examine upstream path instead of assuming "origin"
Summary:
Instead of blindly assuming that "origin" is the repository that
arcanist should communicate with, use the remote that is configured
for the branch in git.
Test Plan:
Used `arc which` with a branch with no upstream, an
origin/master upstream, and an upstream/master upstream -- the last of
which is being used to create and land this diff.
Alex Vandiver [Fri, 20 Nov 2015 18:55:37 +0000 (10:55 -0800)]
Try switching to the branch of the same name, instead of detached head
Summary:
Landing from a branch that directly tracks origin/master places one in
a detached HEAD state. Instead, examine if there is a local branch of
the name that we landed onto, that also tracks the upstream; if so,
switch to that.
Test Plan:
Made a branch via `git checkout -b testing origin/master`
and tried to `arc land`
Joshua Spence [Thu, 19 Nov 2015 08:34:32 +0000 (19:34 +1100)]
Write a linter rule for unexpected `return` values
Summary:
Although it is technically possible to return a value from a PHP constructor, it is rather odd and should be avoided. See some discussion on [[http://stackoverflow.com/q/11904255 | StackOverflow]]. Consider the following example:
```lang=php
class SomeClass {
public function __construct() {
return 'quack';
}
}
```
This doesn't work:
```lang=php, counterexample
echo new SomeClas();
```
Joshua Spence [Wed, 18 Nov 2015 21:58:03 +0000 (08:58 +1100)]
Add a linter rule for `parent` references
Summary:
Add a linter rule to detect static method calls which //should// reference the `parent` class instead of a hardcoded class reference. For example, consider the following:
```lang=php, counterexample
class SomeClass extends AnotherClass {
public function someMethod() {
AnotherClass::someOtherMethod();
}
}
```
This should instead be written as:
```lang=php
class SomeClass extends AnotherClass {
public function someMethod() {
parent::someOtherMethod();
}
}
```
Joshua Spence [Wed, 18 Nov 2015 21:57:23 +0000 (08:57 +1100)]
Test XHPAST linter rules in isolation
Summary:
Separate XHPAST linter rules in isolation from other rules and formalize the concept of a "linter rule". As the number of XHPAST linter rules grows (we currently have around 80), it becomes increasingly difficult to manage all of the test cases because `ArcanistXHPASTLinterTestCase` currently tests the entire linter (i.e. //all// linter rules) rather than testing individual rules in isolation. See D13534 for a situation in which this is painful. This is particularly bad for third party development because unit tests could break at any time depending on upstream changes.
Basically, in order to facilitate the unit testing of XHPAST linter rules in isolation, I have made the following changes:
# Added a `setRules()` method to `ArcanistXHPASTLinter`. Currently, `ArcanistXHPASTLinter` loads all `ArcanistXHPASTLinterRule` subclasses unconditionally. The `setRules()` method provides a way to override the configured linter rules.
# Formalize the concept of a "linter rule". The `ArcanistXHPASTLinterRule` class was introduced in D10541. I feel that the modularization of `ArcanistXHPASTLinter` has made the linter much more maintainable and easily testable and I intend to extend this concept to other linters, such as `ArcanistTextLinter`.
Joshua Spence [Thu, 12 Nov 2015 20:07:52 +0000 (07:07 +1100)]
Add XHAST linter standards
Summary: Ref T8742. As mentioned in D13512. This still needs some work, but looks roughly how I expect it to. Mainly, I want to move the standards stuff to the linter itself rather than the linter rule. I wanted to push this out for some initial feedback though.
When a user lands "cascade-d" onto "origin/master", we should pull A, B and C if they aren't ahead of the remote.
If a user lands "cascade-d" onto itself, we should pull A, B, and C if they aren't ahead of the remote, then reset D to the remote.
We also find this chain if the last component of it is connected by the local branch having the same name as the remote branch (typical for "master") instead of an actual connection through tracking brnaches.
epriestley [Wed, 28 Oct 2015 18:30:57 +0000 (11:30 -0700)]
Pull git upstream-path logic into a separate class
Summary:
Ref T9661. I need to reuse this to fix the complex workflow described in T9661 where we need to follow multiple paths to the upstream and cascade updates across them.
Pull the logic into a separate class to make this easier and less copy/pastey.
This shouldn't change any behavior.
Test Plan: Ran `arc land --preview` from detached head, remote-tracking branch, non-tracking branch, local-tracking branch. Selection of target/remote seemed correct in all cases.
epriestley [Wed, 28 Oct 2015 17:03:51 +0000 (10:03 -0700)]
Fix a check when deciding to destroy the local branch after "arc land"
Summary: Fixes T9660. The behavior for this check wasn't quite right -- we want to check the "source ref" (what we're landing) against the "target onto" (the branch we're landing it onto).
Test Plan:
- Landed from `master` (tracking origin/master). No delete.
- Landed from `feature1` (tracking local/master). Delete.
- Landed from `feature2` (tracking origin/master). Delete.
epriestley [Wed, 28 Oct 2015 15:28:46 +0000 (08:28 -0700)]
Make rules for guessing onto/remote more powerful and more explicit in `arc land`
Summary:
Fixes T9543. Fixes T9658. Ref T3855.
Major functional change is that you can have a sequence of branches like:
origin/master -> notmaster -> feature1
...where they track each other, but you named your local master something else. Currently, we resolve only one level of upstreams, so we try to land onto "notmaster" in this case, which is wrong.
Instead, keep resolving upstreams until we either hit a cycle, don't have another upstream to look at, or find someting in a remote. In this case we'll eventually find "origin/master" and select "origin" as the remote and "master" as the target.
Other minor changes:
- Make this selection process explicit.
- Make the help 3000x longer.
Also fix a bug where we could incorrectly try to tell Differential to update awith `--preview`.
Test Plan:
- Landed from a tag.
- Landed from a tracking branch.
- Landed from an nth-degree tracking branch.
- Tried to land from a local branch with a cycle in upstreams.
- Landed with --remote and --onto.
- Read `arc help land`.
This declares bankruptcy and replaces the entire `arc land` workflow under Git. These are the notable changes:
- (T3855) You can now land from a branch to itself.
- (T3855) We now try to restore the original state very aggressively after any failure, instead of dumping you into the middle of a mess.
- (T9537) You can now land without a local branch.
- ([not actually] T9543) We'll now ignore the local branch if it just happens to be named the same thing as the remote branch but doesn't actually track it.
- (T8620) You can now land from a detached HEAD.
- (T4333) We now preserve the author and author date of whatever you land.
This may need some followup work. In particular:
- The signal handler (that tries to put you in a better place if you ^C in the middle of things) causes ^C to work awkwardly in prompts. This might not be worth it.
- Errors/instructions on push/merge issues might need work.
- I dropped support for `--delete-remote` and `--update-with-blah-blah` because I think these flags aren't worth their complexity.
- I've simplified the update/merge algorithm a bit. It may need some complexity added back in.
- I probably missed a few things because this covers like 200 unique, creative workflows.
- Users might need more guidance on the workflows that drop them in the middle of nowhere if they manage to reach them more often than I think.
Test Plan:
- Used `arc land` to land like at least 15,000 different kinds of changes.
- Landed normally.
- Landed from a branch onto itself.
- Landed from a detached head.
- Landed nothing.
- Landed with no local branch.
- Landed onto made-up branches.
- Landed with bad targets.
- ^C'd things in the middle.
epriestley [Thu, 22 Oct 2015 19:55:16 +0000 (19:55 +0000)]
Improve two error handling behaviors in `arc upgrade`
Summary:
Fixes T9222. Two issues here:
- First, we currently continue on error. Throw instead. I just swapped us from "phutil_passthru()" to "execx()" since I don't think printing out the "pulling from remote..." status messages is very important, and this makes it easier to raise a useful exception.
- Second, if you have a dirty working copy we currently may try to do some sort of silly stuff which won't work, like prompt you to amend changes. Instead, do a slightly lower-level check and just bail.
Test Plan:
- Ran `arc upgrade` with a dirty working copy and got a tailored, useful error.
- Ran `arc upgrade` with an artificially bad `git pull` command, got a failure with a specific error message.
Jon Parise [Wed, 21 Oct 2015 16:46:20 +0000 (09:46 -0700)]
External linters can now specify a version requirement.
Summary:
Linters can now use the `version` configuration value to specify the required
version of the external binary. The version number may be prefixed with <, <=,
>, >=, or = to specify the version comparison operator (default: =).
PHP's native `version_compare()` function is used to perform the comparison.
Fixes T4954.
Test Plan: Tested against a sample of external linters.
epriestley [Mon, 19 Oct 2015 21:35:14 +0000 (14:35 -0700)]
Allow Script-and-Regex linter to have optional/empty capturing patterns for char/line
Summary:
See discussion in D13737. If you're using this linter to match messages which //sometimes// have a character, you can get `""` (empty string) matches when the expression doesn't match. We'll complain about these later.
epriestley [Sun, 4 Oct 2015 15:49:20 +0000 (08:49 -0700)]
Pass author config to `git` with "-c x=y" instead of "--author"
Summary: See D14232. That didn't actually work. It looks like this does.
Test Plan:
- Ran `git commit --author ...` on build server and saw the same failure.
- Ran `git -c ... -c ... commit ...` on build server and saw it work.
epriestley [Sun, 4 Oct 2015 15:41:48 +0000 (08:41 -0700)]
Allow an arc test to execute without a git author configured
Summary:
On `sbuild`, we currently get a failure on this test. Use an explicit `--author` so we can run the test even if `user.email` and `user.name` are not set in global Git config.
```
FAIL ArcanistBundleTestCase::testGitRepository
15 EXCEPTION (CommandException): Command failed with error #128!
16 COMMAND
17 git commit -m 'Mark koan2 +x and edit it.'
18
19 STDOUT
20 (empty)
21
22 STDERR
23
24 *** Please tell me who you are.
25
26 Run
27
28 git config --global user.email "you@example.com"
29 git config --global user.name "Your Name"
30
31 to set your account's default identity.
32 Omit --global to set the identity only in this repository.
33
34 fatal: empty ident name (for <builder@sbuild001.phacility.net>) not allowed
```
Test Plan: Ran `arc unit --everything`. Will verify in production.
Allow users to skip "arc:prompt" by entering no text
Summary:
Fixes T9476. Currently, if you enter no text in "arc:prompt", we abort resolution immediately.
However, this is a bit inconsistent (other rules that fail to resolve are skipped) it is reasonable to put some default rule behind "arc:prompt" so that you can just mash enter to select it. This construction is unusual, but seems fine and sensible to me.
If you're using "arc:prompt" as the last rule, the behavior is the same as before, so this should only make the rule more useful.
Test Plan:
- Ran `arc which --base 'arc:prompt, git:HEAD^'` with and without the patch.
- Without the patch, entering no text at "arc:prompt" failed immediately.
- With the patch, entering no text caused fallback to the "git:HEAD^" rule.
Improve validation of 'name' and 'code' parameters for lint messages
Summary: Ref T9145. Fixes T9316. We now require "name" and "code" has a maximum length (currently, this is 32, but the next diff will raise it to 128).
Test Plan:
- Installed PHPCS.
- Hit both the "name" and "code" issues.
- Applied this patch.
- Got better errors sooner.
Summary:
Fixes T9455. Depends on D14136. When you have a dirty submodule:
$ nano submodule/file.c # save changes
...we currently ask you to make a commit when you run `arc diff`, which is meaningless and misleading.
Instead, prompt the user separately.
This behavior isn't perfect but I think it's about the best we can do within reason.
Test Plan:
- Ran `arc diff` in a working copy with uncommitted submodule changes only, got new prompt.
- Ran `arc diff` in a working copy with submodule base commit changes only, got old (correct) prompt.
- Ran `arc diff` in a working copy with both, got only old prompt (which is incomplete, but reasonable/meaningful).
Summary:
Fixes a minor issue from D14034. PHP doesn't like `clone null;`, and if you type a nonsense command like `arc nbrhch` (as I frequently do) we try to `clone null` here.
Instead, just `return null;` if no workflow matches. Clone otherwise.
Test Plan:
- Ran `arc nbrhcanc`
- Ran `arc branch`