Make retrieving parents for mercurial commits work consistently across platforms
Summary:
Currently the template is single quoted, but Windows only supports double quotes. This meant that the output would be like:
lang=text
'aabbccddeeffaabbccddeeffaabbccddeeff0123
'
Which is clearly wrong.
This is displayed like that in Phabricator as well, which is confusing.
Test Plan: ran `arc diff` on a Windows machine and saw the correct behaviour.
Joshua Spence [Mon, 9 Jun 2014 19:25:14 +0000 (12:25 -0700)]
Allow spaces after the `.` operator if followed by a comment.
Summary: Currently, `'foo'. // Some comment` is not allowed by the `ArcanistXHPASTLinter::LINT_BINARY_EXPRESSION_SPACING` rule. I believe that in the case of a trailing comment, we //should// allow whitespace after the `.` operator.
Test Plan: Wrote and executed a unit test for this case.
Joshua Spence [Mon, 9 Jun 2014 18:36:00 +0000 (11:36 -0700)]
Lint the `ArcanistSpellingDefaultData` class.
Summary:
Currently, the `ArcanistSpellingDefaultData` is marked with a `@nolint` annotation. This means that it doesn't get linted by any linters. Really, the intention here was to make sure that this file isn't linted by the `ArcanistSpellingLinter` linter.
Now that the `.arclint` file is more mature, we can easily just exclude this file from being linted //only// by the spelling linter, whilst allowing other linters to run.
Joshua Spence [Wed, 28 May 2014 13:33:58 +0000 (06:33 -0700)]
Add a version number to `ArcanistXHPASTLinter`.
Summary: Fixes T5209. It makes sense for the `ArcanistXHPASTLinter` to implement the `getVersion` method in order to be able to enforce version requirements (as in T4954).
Joshua Spence [Sat, 24 May 2014 02:54:04 +0000 (19:54 -0700)]
Handle `arc --version`.
Summary: It seems reasonable to transform `arc --version` into `arc version`. The version command is similar to the help command in that it is a command that users unfamiliar with Arcanist will probably try to run at some stage.
Joshua Spence [Sat, 24 May 2014 02:35:33 +0000 (19:35 -0700)]
Add a `version` workflow to arcanist.
Summary: A `version` workflow would be useful, especially for less technical users. Additionally, whenever I am faced with a new command I reasonably expect `$CMD [--help|help]` and `$CMD [--version|version]` to work.
epriestley [Fri, 23 May 2014 21:06:29 +0000 (14:06 -0700)]
set custom arcrc file earlier
Summary: It appears to have never really work? At least as far as phabricator.uri (empirically).
Test Plan:
removed ~/.arcrc, run call-conduit user.whoami with --arcrc-file and --trace.
set-config, get-config and alias also read and write to the right place now.
Joshua Spence [Fri, 23 May 2014 20:53:05 +0000 (13:53 -0700)]
Change double quotes to single quotes.
Summary: Ran `arc lint --apply-patches --everything` over rARC, mainly to change double quotes to single quotes where appropriate. These changes also validate that the `ArcanistXHPASTLinter::LINT_DOUBLE_QUOTE` rule is working as expected.
epriestley [Thu, 22 May 2014 17:36:31 +0000 (10:36 -0700)]
Fix "arc linters" if no engine is built or configured
Summary: `$engine` will be undefined here. This was just copy/paste derp, combined with me accidentally having an `.arclint` file in a place I didn't expect to have one when I tried to test this.
Test Plan: Ran `arc linters` in a totally bare, non-.arclint-having working copy
Joshua Spence [Thu, 22 May 2014 16:22:36 +0000 (09:22 -0700)]
Capture maximum version information in `php_compat_info`.
Summary: Ref T5141. In order to be able to warn when deprecated functions are used, we need to be aware of from which version the functions were deprecated.
Test Plan: Ran `arc lint` and made sure no unexpected warnings were raised.
Joshua Spence [Thu, 22 May 2014 16:14:14 +0000 (09:14 -0700)]
Capture a wider range of version information in `php_compat_info.json`.
Summary: Ref T5141. Currently, `php_compat_info.json` is hardcoded to support PHP 5.2.3. Instead, store as much version information as possible in `php_compat_info.json` and filter accordingly in `ArcanistXHPASTLinter.`
Test Plan: Ran `arc lint` and made sure no additional warnings were raised.
epriestley [Wed, 21 May 2014 19:23:51 +0000 (12:23 -0700)]
Fix XHPAST to detect use of undeclared variables in `catch`
Summary:
Currently, when code has a block like:
} catch (Exception $ex) {
...we attempt to mark "$ex" as declared. However, we incorrectly mark every variable used anywhere in the block as declared. This means we'll never raise this warning in a `catch` block.
Instead //only// mark the caught exception as declared.
Test Plan: Added a failing unit test and made it pass.
James Rhodes [Wed, 21 May 2014 00:15:31 +0000 (10:15 +1000)]
Handles an issue in windows with large code bases not squash merging correctly.
Summary: Handles an issue in windows with large code bases not squash merging correctly, this only catches the issue it doesn't really do any recovery.
Test Plan: We have been running this change in our work environment, it's a hard bug to replicate but when it has reared it's head this has caught it.
epriestley [Tue, 20 May 2014 18:34:28 +0000 (11:34 -0700)]
Improve 'arc get-config', 'arc set-config' and show more config info with --trace
Summary:
Fixes T4952. Several issues:
- You review configuration values with `arc set-config --show`. This makes no sense and never has, I think it just predated `arc get-config` or was easier or something.
- Instead, review values with `arc get-config` and review details with `arc get-config --verbose`.
- Show better and more detailed information about all config sources.
- Establish and show default values from a new "default" source.
- With `--trace` include more information about attempts to read configuration files.
Test Plan:
Ran `arc get-config --trace --verbose` in various working directories and received sensible-looking output.
Joshua Spence [Mon, 19 May 2014 14:52:07 +0000 (07:52 -0700)]
Remove the `ExampleLintEngine` class.
Summary: Ref T2039. Now that the `ArcanistConfigurationDrivenLintEngine` has gained more widespread use, we do no longer expect users to need to write their own lint engine. The documentation has already been updated to reflect this.
Joshua Spence [Mon, 19 May 2014 14:49:51 +0000 (07:49 -0700)]
Improve autofixing of double quotes in XHPAST linter.
Summary: The XHPAST double quotes rule autofixes strings which use double quotes where single quotes would suffice. In the case in which the double-quoted string contained an escaped double quote, the autofix string can be improved by removing the escape symbol.
Test Plan: Modified existing unit tests to cover this case.
Joshua Spence [Mon, 19 May 2014 14:48:58 +0000 (07:48 -0700)]
Add a rule to the XHPAST linter to check for whitespace before a semicolon.
Summary: This rule is based on a rule from [[https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php | PHP_CodeSniffer]].
Joshua Spence [Mon, 19 May 2014 13:33:22 +0000 (06:33 -0700)]
Add a rule to the XHPAST linter for detecting `elseif` usage.
Summary: This rule is adapted from [[https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ElseIfDeclarationSniff.php | PHP_CodeSniffer]] and is used to enforce the consistent use of `else if`.
Joshua Spence [Sun, 18 May 2014 13:47:37 +0000 (06:47 -0700)]
Fix the `ArcanistXHPASTLinter` single quote rule.
Summary: Previously, the `ArcanistXHPASTLinter` was suggesting that `"\1"` be written as `'\1'`, which is incorrect. Therefore, I ensured that all of the cases listed in the [[http://www.php.net/manual/en/language.types.string.php | PHP documentation]] were handled correctly.
Joshua Spence [Sun, 18 May 2014 01:36:25 +0000 (18:36 -0700)]
Fix the `ArcanistJSONLintLinter::getVersion` function.
Summary: Ref T4954. There was a typo in the original implementation. It wasn't noticed until now because the `getVersion` function isn't really used anywhere.
Test Plan: Ran `arc linters` in a repository with `ArcanistJSONLintLinter` configured, noticed that the version number appeared in the output.
Joshua Spence [Sun, 18 May 2014 01:18:03 +0000 (18:18 -0700)]
Relax the version regex for `ArcanistFlake8Linter`.
Summary: As noticed by @epriestley in D9060, `flake8 --version` can emit a string like "2.0" rather than the expected "2.0.0".
Test Plan: Uninstalled my existing version of `flake8` (v2.1.0) and installed a prior version (`pip install flake8==2.0.0`). Ran `flake8 --version` and inspected the output.
Joshua Spence [Sat, 17 May 2014 04:48:12 +0000 (21:48 -0700)]
Set the working directory to the project root for external linter `ExecFuture` classes.
Summary: Fixes T5085. Currently, the `ExecFuture` instances that are used to call an external linter are executed in the current working directory. This means that if a path is specified in the `.arclint` file, relative to the project root directory, that the path will not be properly interpreted by the external linter when `arc lint` is called from a level deeper than the project root.
Test Plan: Ran `arc lint` from a subdirectory of a project and verified that the linter did not throw an exception due to not being able to find the specified configuration file.
Joshua Spence [Sat, 17 May 2014 04:42:52 +0000 (21:42 -0700)]
Add some `.arclint` configuration options for `ArcanistJSHintLinter`.
Summary:
Allow `.jshintrc` and `.jshintignore` paths to be passed to `jshint`.
Ref T2039.
Test Plan: Added the `jshintrc` and `jshintignore` keys to an `.arclint` file that was configured to use `ArcanistJSHintLinter`. Ran `arc lint --trace` and inspected the flags that were passed to `jshint`.
epriestley [Fri, 16 May 2014 02:03:29 +0000 (19:03 -0700)]
Fix `arc diff --raw` when run outside a repository
Summary: Fixes T5071. If you run `arc diff --raw` from some arbitrary, non-repository directory we incorrectly try to read information out of the working copy. Even if this information is available, `arc diff --raw` should not assume it's accurate (there's no guarantee the diff comes from the working copy).
Test Plan: Ran `arc diff --raw` in an arbitrary directory.
Vihang Mehta [Thu, 15 May 2014 16:18:24 +0000 (09:18 -0700)]
Add Closure linter to arcanist
Summary:
Found https://secure.phabricator.com/D4519 but it was horribly out of date, so decided to write a new version.
Kinda clobbered together form that diff and the new version of ArcanistJSHintLinter
Test Plan: Tested on personal projects with js files.
James Rhodes [Thu, 15 May 2014 00:11:45 +0000 (17:11 -0700)]
Fix issue where message contained % but wasn't intended for use with parameters
Summary: This fixes an issue with the C# linter where a message could be returned from cslint that wasn't intended for use with parameters. This just ensures there's enough parameters so that it won't crash (and consequently ignore lint messages).
Joshua Spence [Wed, 14 May 2014 00:32:49 +0000 (17:32 -0700)]
Minor improvements to the `ArcanistLintCheckstyleXMLRenderer` class.
Summary: Ref T4948. Move the `startDocument` code to a `renderPreamble` function so that, at least theoretically, the renderer can be reused. Otherwise, the only way to reuse the renderer would be to construct a new instance.
Test Plan: Ran `arc lint --output xml` and verified that the output looked reasonable.
Joshua Spence [Tue, 13 May 2014 22:17:56 +0000 (15:17 -0700)]
Be more strict with the type of `.arclint` properties.
Summary: Although this provides less context in terms of the error message (for example, `Parameter has invalid type. Expected type 'optional regex|list<regex>', got type 'list<string>'.`), I think that it is the right approach. I think that `PhutilTypeSpec::checkMap` should be improved such that additional context is provided in the exception message.
Test Plan: Ran `arc lint`. Modified `.arclint` to contain an invalid regex and ran `arc lint` again.
epriestley [Tue, 13 May 2014 18:36:56 +0000 (11:36 -0700)]
Read 'phabricator.uri' and 'default' out of more config sources
Summary: We have old/inconsistent code for reading these. Instead, read from sources in a modern way.
Test Plan:
- Removed "default" and "phabricator.uri" from user/local/project config.
- Set "default" in "/etc/arcconfig".
- Ran `arc tasks` and got a "connect to Phabricator" message.
Joshua Spence [Tue, 13 May 2014 13:16:02 +0000 (06:16 -0700)]
Minor cleanup of linter testing code.
Summary:
Just some minor cleaning up, including:
- Removing old annotations for Diviner.
- Renaming some `lint-test` files so that the directory name bears a closer resemblance to that of the linter.
- Remove some useless `return` statements.
epriestley [Mon, 12 May 2014 12:06:04 +0000 (05:06 -0700)]
Fill out some more info functions for libphutil-specific linters
Summary: Ref T2039. It looks like "phutil-library" didn't make it over, I'll add that to the other two (unless I'm wrong and this isn't an oversight?).
Joshua Spence [Mon, 12 May 2014 11:46:56 +0000 (04:46 -0700)]
Remove the `getConfig` and `setConfig` method.
Summary: It seems that there is a lot of overlap between `getConfig` / `setConfig` and `getLinterConfigurationOptions` / `setLinterConfigurationValue` respectively.
Joshua Spence [Mon, 12 May 2014 11:46:41 +0000 (04:46 -0700)]
Allow `ArcanistPhutilXHPASTLinter` to be configured from `.arclint`.
Summary: Currently, `PhabricatorLintEngine` configures the `ArcanistPhutilXHPASTLinter` linter. In order to use `.arclint` instead, we need to expose the `ArcanistPhutilXHPASTLinter` configuration to the `.arclint` format.
epriestley [Mon, 12 May 2014 03:23:07 +0000 (20:23 -0700)]
Provide `arc linters --verbose` to list all available options
Summary:
Ref T2039. I'll update the corresponding documentation.
It feels a little awkward that this is disconnected from `getLinterConfigurationOptions()`, but I dislike returning weird ad-hoc structures more than I dislike having two methods. Most linters don't implement either of these anyway.
Test Plan: Ran `arc linters` and `arc linters --verbose`.
Joshua Spence [Mon, 12 May 2014 02:33:40 +0000 (19:33 -0700)]
Use the `ArcanistConfigurationDrivenLintEngine` as a linting engine.
Summary: Ref T2039. The `.arclint` file is reasonably complete now and we should start using it if possible, since we are trying to recommend it to others.
epriestley [Mon, 12 May 2014 02:28:46 +0000 (19:28 -0700)]
Allow linters to share resources by shoving them on the Engine
Summary:
Currently, the Phutil XHPAST Linter and vanilla XHPAST Linter reuse the same parse tree, but do this by having explicit knowledge of one another.
Instead, let them synchronize by writing to a glorified array of globals on the Engine. They no longer require knowledge of one another, so this can work under `.arclint`.
(This could probably be a little cleaner by putting more logic in the shared base class, but Facebook has some kind of goofy subclass of this thing and //this// patch won't disrupt it, while a cleaner one might.)
This should unblock D9057.
Test Plan: Ran unit tests and normal lint, got accurate looking results without duplicate invocations showing up in `--trace`.
Joshua Spence [Mon, 12 May 2014 02:28:26 +0000 (19:28 -0700)]
Remove severity options from some linters.
Summary: The `ArcanistGeneratedLinter` and `ArcanistNoLintLinter` don't actually ever raise any linter messages, so it doesn't make sense to set custom severities for these linters. Instead, don't expose this configuration.
epriestley [Mon, 12 May 2014 01:39:28 +0000 (18:39 -0700)]
Warn when accessing deprecated lint config
Summary:
Ref T2039. Addresses two issues:
- Issues a warning for use of config which is deprecated by `.arclint`.
- We no longer require an engine to be present for these linters, so `arc linters` doesn't fatal if they aren't configured.
Test Plan:
- Ran `arc linters` in a repo with no JSHint.
- Ran `arc linters` in a repo with junk in .arcconfig and got a warning when it was read. Verified it still took effect.
epriestley [Sun, 11 May 2014 20:42:56 +0000 (13:42 -0700)]
Add 'arc linters' to list available linters and status
Summary: Ref T2039. We're starting to get kind of a lot of linters; provide `arc linters` to help users review and understand them and construct `.arclint` files.
Joshua Spence [Sun, 11 May 2014 12:32:38 +0000 (05:32 -0700)]
Allow global excludes to be specified in `.arclint`.
Summary: Currently, paths to be excluded from linting need to be specified for each linter individually. This is a pain for projects that are using even a moderate number of linters and which have common paths which should be excluded from linting completely.
Test Plan: Unfortunately, it's hard to test this sort of stuff. I cloned the `arclint-examples` repository and tested my changes there,
Joshua Spence [Sat, 10 May 2014 08:55:47 +0000 (01:55 -0700)]
Modernize `ArcanistMergeConflictLinter`.
Summary: The only real change here is adding a `getLinterConfigurationName` method so that this linter can be used with an `.arclint` file. Everything else is just some minor tidying.
Joshua Spence [Sat, 10 May 2014 08:52:57 +0000 (01:52 -0700)]
Add `--quiet` flags to the `ArcanistCSSLintLinter`.
Summary: This isn't really necessary, nor does it bear any significant benefits, however semantically it seems to make sense. From `csslint --help`, the `--quiet` flag causes `csslint` to "Only output when errors are present".
Test Plan:
Tested using `csslint` directly:
```
> csslint test.css
csslint: No errors in /home/joshua/workspace/github.com/facebook/arcanist/foo.css.
> csslint --quiet test.css
```
Joshua Spence [Fri, 9 May 2014 13:00:36 +0000 (06:00 -0700)]
Remove `debug` key from `.arclint` file format.
Summary: Having a `debug` key in the `.arclint` file format doesn't seem right. Instead, it would be better to just use a `PhutilConsole` and the `writeLog` method so that "debug" messages are output when using `arc --trace`.
Test Plan: Ran `arc lint --trace` in a repository using `.arclint`.
Joshua Spence [Tue, 6 May 2014 04:18:43 +0000 (21:18 -0700)]
Parse JSON as an associate array.
Summary:
It seems that in some situations, JSHint does not set the `evidence`
property. In such cases, PHP fails with `Undefined property:
stdClass::$evidence`. It would be safer to access the error object as an
associative array rather than as `stdClass`.
Joshua Spence [Tue, 6 May 2014 03:15:35 +0000 (20:15 -0700)]
Add a JSON linter.
Summary: Provide bindings for [[https://github.com/zaach/jsonlint | JSONLint]], which is a useful tool for linting and validating JSON. Theoretically, this could be done with pure PHP, however it would not be trivial (`json_decode`, for example, does not provide any context as to JSON validation errors).
Joshua Spence [Tue, 6 May 2014 01:59:35 +0000 (18:59 -0700)]
Fix `flake8` unit test.
Summary:
This unit test is failing for me. It seems that I have a newer version of `flake8`. We should probably provide support for the most recent versions of any external tools, at least until we can implement version-specific stuff.
I am running `2.1.0 (pep8: 1.5.6, pyflakes: 0.8.1, mccabe: 0.2.1) CPython 2.7.6 on Linux`.
Joshua Spence [Tue, 6 May 2014 01:58:13 +0000 (18:58 -0700)]
Convert more linters to modern formats with `.arclint` support
Summary:
Ref T3186. Ref T2039.
- Convert JSHint to modern format; improve granularity of errors.
- Convert PyFlakes to modern format;
- Remove ApacheLicenseLinter and LicenseLinter (these have been deprecated for a very long time).
This is somewhat disruptive and will break some users by no longer respecting various path/config options. I'll sequence documentation and deprecation warnings in front of these.