1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-10-24 17:48:50 +02:00
Commit graph

246 commits

Author SHA1 Message Date
vrana
266a4f4c75 Catch exceptions in didRunLinters()
Test Plan: Threw in `didRunLinters()` of one linter, still saw the result of other linters and "Some linters failed" at the end.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5124
2013-02-26 15:00:58 -08:00
vrana
2464f54ecf Initialize used variable in lint console renderer 2013-02-25 16:23:27 -08:00
vrana
9d92253903 Support arc lint --output none
Summary:
I want to run lint on background and I'm interested only in side effect of caching (and maybe exit status).
This is better than discarding stdout later because we don't do unnecessary work and error conditions are still printed.

Test Plan:
  $ arc lint --output none # with error
  $ echo $?
  $ arc lint --output none # with no lintable paths
  $ arc lint --output none # witout errors

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5106
2013-02-25 14:55:57 -08:00
vrana
0b120bd04b Add unit tests for implicit fallthrough lint rule
Summary:
The perf fix actually catches some real problems.
I didn't find anything in libphutil, Arcanist and Phabricator though.

Also bump version.

Also allow configuring the hook.

Test Plan:
Added a test, saw it fail with the old code.
Repeat for hook.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5097
2013-02-23 09:07:28 -08:00
vrana
8ec038291a Fix intraline lint patch rendering
Summary: `,` -> `, ` is currently highlighted wrong.

Test Plan:
Looked at patches of these errors:

- License linter
- `0+0`
- `0,0`

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5093
2013-02-22 17:03:47 -08:00
vrana
21a4574922 Change ArcanistLintRenderer to class
Summary: Renderers **are** renderers not **can** render.

Test Plan: This diff.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5092
2013-02-22 16:15:43 -08:00
vrana
aadaf9a795 Speedup implicit fallthrough lint rule by 99.5 %
Summary: At least on my sample file.

Test Plan: Saw time 0.073 s instead of 12.606 s.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5086
2013-02-22 14:16:03 -08:00
vrana
b758e3737c Log two times per linter instead of N
Summary: This number seems more interesting and it includes time for resolving futures which is the main part of some linters.

Test Plan:
  $ arc --trace lint

Reviewers: fdeliege, epriestley

Reviewed By: epriestley

CC: aran, epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D5075
2013-02-22 09:54:43 -08:00
epriestley
e33bd82c42 Add hgsprintf() and jsprintf() to dynamic string lint warning
Summary: Soon all functions will accept only static parameters! glorious!

Test Plan: Added a couple tests.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D4811
2013-02-21 16:44:34 -08:00
vrana
459251a8d0 Call willLintPath() in future linter
Summary: Also simplify creating futures.

Test Plan: This diff.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, s.o.butler

Differential Revision: https://secure.phabricator.com/D5042
2013-02-21 11:57:38 -08:00
vrana
5e7a458053 Use full message if XHPAST fails to parse the file
Summary:
The message is too defensive.

Test Plan: Tested in the fork.

Reviewers: epriestley, nh

Reviewed By: epriestley

CC: aran, Korvin, s.o.butler

Differential Revision: https://secure.phabricator.com/D5043
2013-02-21 09:14:49 -08:00
vrana
df013f6282 Resolve XHPAST linter futures on background
Summary: This is a little bit tricky - if both XHPAST and PhutilXHPAST linters lint the same path then they get the same future wrapped in two different Future iterators.

Test Plan:
  $ arc unit

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5015
2013-02-21 00:58:23 -08:00
vrana
a3e0c26ea8 Delete newLintAtLine()
Summary: Nobody needs it because `raiseLintAtLine()` returns the message.

Test Plan:
  $ arc unit

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4870
2013-02-21 00:56:08 -08:00
epriestley
652472d059 Undumb other generic text linters
Summary:
Make all the broad-spectrum text linters use the new binary check.

I didn't touch `ComprehensiveLintEngine` because it's a nest of vipers and no one has complained; see T2039.

Test Plan: Ran `arc lint` on text files and binaries in a libphutil project (arcanist).

Reviewers: lisp

Reviewed By: lisp

CC: aran

Differential Revision: https://secure.phabricator.com/D5040
2013-02-20 14:36:53 -08:00
Robert Smith
92a5803d30 Add linting for syntax brought in by unresolved merge conflicts.
Summary:
Add linting capability for detecting files which contain
syntax introduced by unresolved merge conflicts. The detection is
file-type-agnostic (the only requirement is that the file is a text
file).

Test Plan:
Tested in three ways.

The first way is to add all three forms of syntax to a file to
indicate a merge conflict. HPHP will pick this up as a syntax error
before this linter reaches it.

The second way is to add the syntax in a comment. In that case, this
linter will show three warnings. For example:

    $ arc lint ArcanistMergeConflictLinter.php
    >>> Lint for arcanist/src/lint/linter/ArcanistMergeConflictLinter.php:

       Warning  (MERGECONFLICT1) Unresolved merge conflict
        This syntax indicates there is still an unresolved merge conflict.

                  20
                  21     foreach ($lines as $lineno => $line) {
                  22 /*
        >>>       23 >>>>>>>
                  24
                  25 =======

       Warning  (MERGECONFLICT1) Unresolved merge conflict
        This syntax indicates there is still an unresolved merge conflict.

                  22 /*
                  23 >>>>>>>
                  24
        >>>       25 =======
                  26
                  27 <<<<<<<

       Warning  (MERGECONFLICT1) Unresolved merge conflict
        This syntax indicates there is still an unresolved merge conflict.

                  24
                  25 =======
                  26
        >>>       27 <<<<<<<
                  28
                  29 */

The last test was to test on various different file types, including
JavaScript, PHP, an animated GIF, a PNG, and a Bash file to make sure
the file type detection worked. Each of the aforementioned tests
passed.

Reviewers: vrana, epriestley

Reviewed By: epriestley

CC: aran, epriestley, Korvin

Maniphest Tasks: T2547

Differential Revision: https://secure.phabricator.com/D4966
2013-02-20 14:19:55 -08:00
François Deliège
8be64ec4c6 Log slow linters using service call
Summary:
Following @epriestley suggestion to use PhutilServiceProfiler to log lint as a service call

Test Plan: arc lint

Reviewers: vrana

CC: phunt, aran, epriestley

Differential Revision: https://secure.phabricator.com/D4820
2013-02-20 11:43:51 -08:00
epriestley
7a67173b97 Apply new whitespace lint rules to arcanist/
Summary: Automated changes from `arc lint`.

Test Plan: Looked them over.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D5017
2013-02-19 14:09:20 -08:00
epriestley
157184e01d Add a lint rule for spaces before the closing paren of a function/method call
Summary: This is technically documented, but not currently enforced and we aren't consistent about it in the codebase.

Test Plan: See D5002.

Reviewers: chad, vrana

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D5003
2013-02-19 13:50:13 -08:00
vrana
688e159319 Fix visibility of future linter methods 2013-02-19 13:09:34 -08:00
vrana
81171ca39d Run PEP8 linter on background
Test Plan:
  $ arc lint pep8.py --cache 0 --engine ComprehensiveLintEngine --trace

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4967
2013-02-19 12:56:57 -08:00
vrana
cd50b0884e Don't run disabled lint rules in other linters.
Summary: D4963 for other linters.

Test Plan: Saw time 0.001 instead of 0.113 in spellcheck linter.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4965
2013-02-14 15:54:10 -08:00
vrana
eb8b414cc7 Don't run disabled lint rules
Summary:
We always generate all messages and then filter them out based on minimum severity.
It's lots of useless work, especially in commit hook mode where we are interested only in errors.

Test Plan:
  $ arc lint --cache 0 --severity error ArcanistXHPASTLinter.php
  0.406 s before, 0.074 after

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4963
2013-02-14 15:31:10 -08:00
vrana
619dd62f31 Respect granularity in reading cached lint messages
Summary:
We save repository version to lint cache but ignore it when reading the cache.
Fix it.

Test Plan: Made an error for linter with repo granularity, deleted the error from the cache. Relinted, didn't see the error. Changed another file and relinted, saw the error.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4841
2013-02-14 11:45:38 -08:00
epriestley
42ae7cd92f Add lint warning for $o->m()[0], not just f()[0]
Summary: We only caught half of this.

Test Plan: Unit test.

Reviewers: edward

Reviewed By: edward

CC: aran

Maniphest Tasks: T1261

Differential Revision: https://secure.phabricator.com/D4920
2013-02-12 07:07:35 -08:00
vrana
2419718593 Merge PHT into dynamic string linter
Test Plan: Existing unit test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4914
2013-02-11 18:59:53 -08:00
epriestley
acf7600e6e Temporarily restore apache/license linters
Summary:
Restores linters only, without unit tests or entry in ComprehensiveLinter. Marks them deprecated.

If use at Facebook isn't widespread I'd prefer to simply delete them.

Test Plan: none

Reviewers: vrana

Reviewed By: vrana

CC: aran

Maniphest Tasks: T2274

Differential Revision: https://secure.phabricator.com/D4906
2013-02-11 14:12:10 -08:00
vrana
e1d906ea18 Allow configuring PhutilXHPAST linter
Summary: Also move Phabricator stuff outside.

Test Plan: Updated unit test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4894
2013-02-11 10:41:26 -08:00
Bryan Cuccioli
8b1215ffcf Delete license linters.
Summary: Remove all references to ArcanistLicenseLinter and ArcanistApacheLicenseLinter.

Test Plan: Rerun the linter and ensure nothing is broken.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4901
2013-02-11 09:04:19 -08:00
vrana
6a70964a40 Deprecate phutil_escape_html()
Summary:
My original idea was to return safe HTML from this function.
But we are down to 20 occurrences in Phabricator and you shouldn't need this function in safe HTML world at all.

Test Plan:
  $ arc lint src/applications/audit/controller/PhabricatorAuditListController.php

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4890
2013-02-09 15:18:19 -08:00
epriestley
38d23516d1 Add lint warnings about use of phutil_render_tag and javelin_render_tag
Summary: Raise deprecation warnings for these methods. I won't commit this until the phutil_tag branch merges.

Test Plan: Unit tests.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Maniphest Tasks: T2432

Differential Revision: https://secure.phabricator.com/D4770
2013-02-08 17:38:56 -08:00
vrana
ca37bfb2ab Display other locations of Reused lint errors
Summary: It's not trivial to find them inside 700+ lines long functions.

Test Plan:
Linted `reused-iterators.lint-test` renamed to `_.php`, saw other locations.
Repeated for `reused-local.lint-test`.
Repeated for `duplicate-key-in-array.lint-test`.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4871
2013-02-08 15:49:50 -08:00
epriestley
2c2cb3b78a Improve error message for phutil missing symbols
Summary: This is fairly confusing. Make the error message suggest the common remedy (update libphutil).

Test Plan: Eyeballed it.

Reviewers: Afaque_Hussain, btrahan, vrana

Reviewed By: Afaque_Hussain

CC: aran

Differential Revision: https://secure.phabricator.com/D4834
2013-02-06 19:11:06 -08:00
vrana
bd71ba675e Implement hook for checking switch lint
Summary:
We want to use it for `yield` and `invariant_violation()` which throws.
Having node instead of token would be better but this would be enough.

Test Plan: Implemented a hook in FB repo and added a test case there.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4821
2013-02-05 11:46:59 -08:00
vrana
a9e316bf9c Fix dynamic string usage as safe input
Summary: This fixes some real issues.

Test Plan:
  $ arc lint

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, btrahan

Differential Revision: https://secure.phabricator.com/D4795
2013-02-02 16:28:15 -08:00
vrana
03199df925 Lint dynamic string usage in parameters treated as safe
Summary:
This disallows code like this:

  $cmd = 'ls';
  execx($cmd);

But I guess it's not that big deal?

Test Plan: Linted whole Arcanist and Phabricator codebases, most parts looks fixable.

Reviewers: epriestley

CC: nh, aran, Korvin

Differential Revision: https://secure.phabricator.com/D4794
2013-02-02 16:26:52 -08:00
vrana
8374dbc4e3 Handle $var::method() in XHPAST linter
Test Plan: Didn't see a fatal in new test case.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4783
2013-02-01 11:21:06 -08:00
vrana
3f747be644 Move isConstantString() to base class
Summary: This can be useful by itself, we want to use it in FB linter.

Test Plan: This diff.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4744
2013-01-30 12:56:59 -08:00
vrana
98e8d0c9c4 Split php-tags-bad.lint-test to two tests
Summary: D1818 effectivelly disabled this test case.

Test Plan: This diff.

Reviewers: epriestley, nh

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4746
2013-01-30 12:46:30 -08:00
vrana
5aa3bc6ec0 Separate Phutil specific lint rules from XHPAST
Summary: Also provides an example how to build custom linter using XHPAST.

Test Plan: Added debug output to `willLintPaths()`, verified that each path is parsed only once.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4718
2013-01-29 10:54:40 -08:00
Jesse Mullan
c49997a6e8 Added paths to search for python linters
Summary: Added paths to search for python linters

Test Plan: Linted in ubuntu

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2414

Differential Revision: https://secure.phabricator.com/D4648
2013-01-26 05:32:26 -08:00
epriestley
44e25495ca Raise a lint warning on array_combine(x, x)
Summary: Suggest array_fuse().

Test Plan:
Unit tests, and:

  $ arc lint --lintall src/unit/engine/phutil/ArcanistPhutilTestCase.php
  >>> Lint for src/unit/engine/phutil/ArcanistPhutilTestCase.php:

     Warning  (XHP37) array_combine() Unreliable
      Prior to PHP 5.4, array_combine() fails when given empty arrays. Prefer
      to write array_combine(x, x) as array_fuse(x).

               252     $callable,
               253     $exception_class = 'Exception') {
               254     return $this->tryTestCases(
      >>>      255       array_combine(array_keys($map), array_keys($map)),
               256       array_values($map),
               257       $callable,
               258       $exception_class);

Reviewers: btrahan, vrana, chad

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D4659
2013-01-25 17:06:49 -08:00
vrana
a1b902b190 Cache results of repository linters
Summary:
The cache key is repository base revision and hash of all modified files.
It isn't perfect in SVN where every file might have a different revision.
It's also suboptimal as just committing or amending changes the cache key even if the files contents weren't modified.
We can improve it later, perhaps by using previous revision and files modified since it.

Test Plan:
Changed granularity of XHPAST linter to repository.
Linted the same repo twice, verified that it was read from cache the second file.
Changed a single file, verified that all files were re-linted.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4608
2013-01-24 16:15:55 -08:00
epriestley
7f93b7de02 Don't use xhpast binary to compute xhpastlinter cache version if the binary doesn't exist
Summary: The binary may not be built, in which case this raises a warning.

Test Plan: Will make @zeeg test.

Reviewers: zeeg, vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D4569
2013-01-22 17:16:37 -08:00
vrana
98fec27752 Fix PHT linter
Summary: Variables in strings and concatenation lists.

Test Plan:
New unit tests.

  preg_match('/^((?>[^$\\\\]*)|\\\\.)*$/s', str_repeat('a', 1e6));

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4540
2013-01-19 11:48:17 -08:00
vrana
78017033bd Warn against usage of nowdoc
Summary: Also include binary hash in the version.

Test Plan: New unit test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4535
2013-01-19 09:23:17 -08:00
vrana
85c0ed13d9 Set used variable 2013-01-18 13:32:48 -08:00
epriestley
a39b591c95 Allow pht(<<<HEREDOC ... HEREDOC)
Summary: Don't raise lint on heredoc literals.

Test Plan: Linted pht() + heredoc in D4477.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D4478
2013-01-16 14:57:10 -08:00
vrana
90129c5432 Include real PEP8 version and options in lint cache key
Summary: This should be done for all external and configurable linters.

Test Plan: Linted file with lint problems, changed options, relinted.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4475
2013-01-16 12:17:11 -08:00
vrana
8142aab9d3 Fix whitespace around else 2013-01-16 12:15:46 -08:00
vrana
f25c01606b Cache stopped paths in lint
Summary:
If linter with file cache granularity stops linting then we don't run it on the same path next time.
But we still run linters with non-file cache granularity causing that they run even on the paths that would be stopped otherwise.

Test Plan:
Put global granularity linter after Generated linter.
Caused an error from this linter but in ignored path.
Verified that 'stopped' is saved in `lint-cache.json`.
Linted the same files second time, verified that the path is still skipped (wasn't before).

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4446
2013-01-15 17:58:32 -08:00