Joshua Spence [Tue, 17 Jun 2014 15:28:40 +0000 (01:28 +1000)]
Move the "ragged classtree edge" linter rule to `ArcanistPhutilXHPASTLinter`.
Summary: This linter rule is very specific to the Phabricator and it is unlikely that it is being used elsewhere. We should move it to `ArcanistPhutilXHPASTLinter`, where other Phabricator-specific linting code lives.
Summary: Depends on D9586. The progress bar is written to stderr which results in bad stuff happening when you try run `lint` (`PhutilLibraryLinter` calls it)
Tal Shiri [Mon, 16 Jun 2014 22:28:04 +0000 (15:28 -0700)]
Allow specifying runtime configuration with --set-config key=value
Summary:
This is useful for wrapper scripts that want to customize arcanist's behavior without affecting the global configuration.
This can be implemented with arcanist_configuration entry in .arcconfig, however it is currently limited to
per-project settings, and this feature makes writing wrapper scripts a little easier.
Test Plan: arc diff --set-config editor=vim (yeah yeah, crappy test case)
Joshua Spence [Mon, 16 Jun 2014 20:40:36 +0000 (06:40 +1000)]
Add an `ArcanistJscsLinter`.
Summary: Add a linter which wraps around [[https://github.com/mdevils/node-jscs | JSCS]].
Test Plan: Currently, we can't test this linter with out existing infrastructure. Specifically, `jscs` will only lint `*.js` files. I have done a fair bit of manual testing though.
Joshua Spence [Mon, 16 Jun 2014 15:00:23 +0000 (01:00 +1000)]
Add constants and class methods to `php_compat_info.json`.
Summary: Allows the `ArcanistXHPASTLinter` to determine whether constants can be used, based on the target PHP version. Also added class methods to the compatibility information, although this isn't used yet (it is small anyway).
Test Plan: Created a test file that contained the `JSON_PRETTY_PRINT` constant. Verified that a linter error was raised.
Joshua Spence [Mon, 16 Jun 2014 14:30:16 +0000 (00:30 +1000)]
Update `update_compat_info.php` to use PHP_CompatInfo version 3
Summary:
Fixes T5377. The current `scripts/update_compat_info.php` script works for PHP CompatInfo version 2, but doesn't work with the newer version 3.
There are a few breaking changes in version 3 that had to be addressed:
- PHP 5.3 is required. Whilst Arcanist is generally compatible with PHP 5.2, I don't think that having this dependency presents any real issues because it is purely a development tool that is rarely updated.
- [[https://getcomposer.org/ | Composer]] is used for packaging, which makes including the library slightly more complicated. Basically, I had to install `PHP_CompatInfo` globally with Composer (`composer global require "bartlett/php-compatinfo"` and then symlink `~/.composer/vendor` into `externals/includes`.
Test Plan: Compared the `resources/php_compat_info.json` file. There are a bunch of functions/classes that //were// in this file but are no longer, but I think that I've covered the most popular extensions.
epriestley [Thu, 12 Jun 2014 22:46:15 +0000 (15:46 -0700)]
Dirty cache of HEAD commit after an amend/range reload
Summary:
Introducing `--head` caused us to run `git diff base..head` explicitly.
However, we can now hit this workflow:
- We resolve `HEAD` as commit `aaaa1`.
- This is cached.
- We notice dirty working copy changes and prompt the user to amend them to HEAD.
- The user accepts the amend.
- We amend, creating commit `bbbb2`.
- We dirty the commit range and reload the working copy. This //does not// dirty the cache of HEAD.
- We run `git diff`, but it uses the old cached HEAD: `git diff base..aaaa1`.
- This works fine (`aaaa1` still exists, it's just not on any branch) but produces the wrong diff (without amended changes).
To resolve this, implement the "dirty the cache when the range reloads" hook.
Also never try to amend if the user provides `--head`.
Test Plan:
Ran `arc diff --only --trace` in a working copy with a new commit and some uncommitted changes.
- Prior to this change, saw a `git diff base..aaaa1` command and the wrong diff.
- After this change, saw a `git diff base..bbbb2` command and the correct diff.
epriestley [Wed, 11 Jun 2014 23:35:50 +0000 (16:35 -0700)]
Tweak error and status messages for commit ranges
Summary: Improve/clarify some error messages a bit, hopefully.
Test Plan: Ran `arc which`, `arc diff`, etc., with various explicit, implicit, and `--head` flags. Read error messages, didn't catch anything too awkward.
Tal Shiri [Wed, 11 Jun 2014 21:37:01 +0000 (14:37 -0700)]
--range support for git
Summary:
This adds support for passing range of commits for arc diff. This is useful when you want to submit code reviews for past commits without mucking around with the working copy.
This will probably require changes :)
Test Plan: Tested locally, but totally need to add tests for this
Joshua Spence [Wed, 11 Jun 2014 12:39:51 +0000 (05:39 -0700)]
Present case of class and interface names.
Summary: Currently, class and interface names are converted to lowercase when comparing minimum and maximum versions. This is necessary in order to compare with the data from `php_compat_info.json` but causes the lint message to be slightly misleading.
Test Plan:
Linted a test file.
**Before**
```
Error (XHP31) Use Of PHP 5.3 Features
This codebase targets PHP 5.2.3, but `iterator` was not introduced until
PHP 5.3.0.
1 <?php
2
>>> 3 final class FooBar implements Iterator {}
```
**After**
```
Error (XHP31) Use Of PHP 5.3 Features
This codebase targets PHP 5.2.3, but `Iterator` was not introduced until
PHP 5.3.0.
1 <?php
2
>>> 3 final class FooBar implements Iterator {}
```
Joshua Spence [Wed, 11 Jun 2014 01:20:59 +0000 (18:20 -0700)]
Don't lint symlinks by default.
Summary: Fixes T5300. Currently, if a dead symbolic link is linted, all kinds of errors will be thrown by most linters because they will try to read the (non-existent) file contents. Instead, let's not lint symbolic links by default. In the case that the target of a symbolic link is inside the working copy, then it should be being linted anyway.
Test Plan: Created a symbolic link and verified that it wasn't linted (by any linter other than the `ArcanistFilenameLinter`).
Joshua Spence [Tue, 10 Jun 2014 18:02:42 +0000 (11:02 -0700)]
Apply various linter fixes.
Summary: Applied various linter fixes. Also make the `.editorconfig` file a bit more specific. Unfortunately, `arc lint --apply-patches` currently modifies some test data that it shouldn't, but this should be fixed after T5105.
Test Plan: Ran `arc unit` to make sure things weren't broken.
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.