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

273 commits

Author SHA1 Message Date
epriestley
6e5be59ad6 Port flake8 to ArcanistExternalLinter
Summary:
Ref T3186. Brings another linter onboard. This one uses the stdin stuff.

The unit test was ostensibly broken so I fixed it, but that might just be some kind of version issue.

Test Plan: Unit tests.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3186

Differential Revision: https://secure.phabricator.com/D6802
2013-08-23 11:52:54 -07:00
epriestley
e23fc30c19 Introduce a rough abstract base class for "linters which run programs and read the results"
Summary:
Ref T3186. We have about 50 linters which run programs and read the results, all of which have ad-hoc one-off custom config that isn't formalized anywhere.

Consolidate all this stuff into `ArcanistExternalLinter`, which is configurable through `.arclint` (although nothing supports this quite yet).

Extend CSSLint and Pep8Lint from `ArcanistExternalLinter`.

Add unit tests for both.

There are still some rough edges here, but it mostly seems to work pretty well.

Test Plan: Ran unit tests, hit some (most?) of the error cases.

Reviewers: btrahan

Reviewed By: btrahan

CC: chad, aran, Firehed

Maniphest Tasks: T3186

Differential Revision: https://secure.phabricator.com/D6800
2013-08-23 11:52:44 -07:00
epriestley
f18130a6aa Simplify and demuck some of the linter test cases
Summary:
Ref T3186.

  - Every linter builds a WorkingCopyIdentity in the same way, with no specialized data. Don't do that.
  - Linters get passed a goofy hardcoded ".php" path. Don't do that.
  - Linters generally run on an imaginary path, which might not work. Just give them a real path by building a tiny working copy in `/tmp`.
  - Fix a TODO now that we have better typechecking.

Test Plan: `arc unit --everything`, intentionally broke a test to make sure that still works.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3186

Differential Revision: https://secure.phabricator.com/D6798
2013-08-22 16:02:41 -07:00
epriestley
97ad54ed00 Lay groundwork for configuration-driven linters
Summary:
Ref T2039. That task has a bunch of discussion, but basically we do a poor job of serving the midrange of lint configuration right now.

If you have something simple, the default linters work.

If you have something complex, building your own engine lets you do whatever you want.

But many users want something in between, which isn't really well accommodated. The idea is to let you write a `.arclint` file, which looks something like this:

  {
   "linters" : {
      "css" : {
        "type" : "csslint",
        "include" : "(\.css$)",
        "exclude" : "(^externals/)",
        "bin" : "/usr/local/bin/csslint"
      },
      "js" : {
        "type" : "jshint",
        "include" : "(\.js$)",
        "exclude" : "(^externals/)",
        "bin" : "support/bin/jshint",
        "interpreter" : "/usr/local/bin/node"
      }
   }
  }

...which will provide a bunch of common options around lint severity, interpreter and binary locaitons, included and excluded files, etc.

This implements some basics, and very rough support in the Filename linter.

Test Plan:
Generated a `.arclint` file and saw it apply filename lint correctly. Used `debug` mode and tried invalid regexps.

  {
    "debug" : true,
    "linters" : {
      "filename" : {
        "type" : "filename",
        "exclude" : ["@^externals/@"]
      }
    }
  }

Next steps include:

  - Provide an external linter archetype (T3186) and expose a common set of configuration here ("bin", "interpreter", "flags", "severity").
  - Provide a `.arcunit` file which works similarly (it can probably be simpler).

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2039

Differential Revision: https://secure.phabricator.com/D6797
2013-08-22 16:02:16 -07:00
Lajos Veres
a680c55670 Add CSSLint linter to Arcanist
See: https://github.com/facebook/arcanist/pull/93

Reviewed by: epriestley
2013-08-02 05:14:00 -07:00
Jakub Vrana
19181fb3e8 Remove warning about deprecated phutil_render_tag()
Test Plan: None.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D6567
2013-07-28 11:00:00 -07:00
epriestley
490984936b Revert "Merge pull request #93 from vlajos/csslint"
This reverts commit 2852a965e3, reversing
changes made to 46bb3dbc36.

See: https://github.com/facebook/arcanist/pull/93
2013-07-22 06:52:08 -07:00
Jeff Ferland
2852a965e3 Merge pull request #93 from vlajos/csslint
CSS lint support for arcanist using csslint.
2013-07-22 06:44:22 -07:00
Jakub Vrana
f5ceceea87 Lint undeclared variables in strings
Summary: Depends on D6405.

Test Plan:
New unit test.
Linted libphutil, Arcanist, Phabricator.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D6406
2013-07-10 08:26:11 -07:00
Lajos Veres
2e30c97ade comment typo fix 2013-07-09 14:11:21 +01:00
Lajos Veres
395c15e630 add css lint 2013-07-09 12:46:59 +01:00
epriestley
fbcd686e18 Update spelling replacement rule for 'algorithmical'
Summary:
I suspect that when people use 'algorithmical', they mean it as an adjective and not an adverb.

'algorithmic' = adjective
'algorithmically' = adverb

Test Plan: Add the word 'algorithmical' to a file. Run `arc lint` on the file. See suggestion to correct it to 'algorithmic'.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D6373
2013-07-08 09:46:24 -07:00
Omer Strulovich
9a46ba7ea1 Support for lint messages which are always shown
Summary: If one wishes to implement a linter which finds unused resources or variables the current scheme does not work as the lint engine filters all changes from lines which were not introduced in a diff. To solve that, I've added an "always show" configuration for a lint message allowing creation of such linters.

Test Plan:
1. Created a custom linter for finding unused Android resources in a project
2. Ran arc lint with linter added and received warnings as expected

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D6119
2013-06-09 08:38:30 -07:00
Jakub Vrana
5336f4bcf0 Verify classes used in typehints
Summary: Also support `SomeInterface::CONSTANT`.

Test Plan:
  interface I {
    const A = 1;
  }
  I::A;

  function f(stdClass $a, array $b, Iterator $c) {
  }

Linted Phabricator.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D6135
2013-06-05 13:53:43 -07:00
epriestley
e93726cb3b Fix some Arcanist lint warnings
Summary: Lint. See https://github.com/facebook/phabricator/pull/332

Test Plan: Lint.

Reviewers: chad

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D6126
2013-06-04 15:29:39 -07:00
epriestley
ae66d4caa9 Use a temporary file to execute arc patch
Summary:
Piping data around on Windows doesn't work well when it contains zany characters like "null" and "newline". Fixes T3266.

Instead of piping data into `git apply`, write to a temporary file.

Test Plan:
Ran `arc patch`, got good results.

  >>> [17] <exec> $ git apply --index --reject -- '/private/var/folders/8k/c3vkmjy5335gcxdzxkhwq82w0000gn/T/7z9iea6srikoo0sc/4266-ZEyvz9'

Reviewers: btrahan, hach-que

Reviewed By: hach-que

CC: aran

Maniphest Tasks: T3266

Differential Revision: https://secure.phabricator.com/D6070
2013-05-30 21:03:21 -07:00
Jakub Vrana
eb449a40b4 Update PHP compat info
Summary: Also warn against functions not available on Windows at all.

Test Plan: Compared old and new file.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5975
2013-05-22 11:36:41 -07:00
Jakub Vrana
a1c0ba785d Lint for PHP 5.3 on Windows
Test Plan: Linted `FileFinder`.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5972
2013-05-19 11:00:08 -07:00
Nick Harper
28df67963b Don't use cache in svn-hook-pre-commit
Test Plan: arc lint

Reviewers: epriestley, wez

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5779
2013-04-24 15:10:27 -07:00
Phil Dibowitz
fb88bb9da6 Add a configuration for python path
Test Plan: not a clue

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5717
2013-04-16 15:10:34 -07:00
epriestley
2df40b5445 Lint TRUE, nUlL, etc., for Phabricator conventions
Summary: Detect and fix unconventional spellings of `true`, `false`, `null` and `array` (these are the only keywords I've seen spelled unconventionally in the wild).

Test Plan: Unit tests.

Reviewers: DurhamGoode, btrahan, vrana

Reviewed By: vrana

CC: aran

Maniphest Tasks: T2985

Differential Revision: https://secure.phabricator.com/D5686
2013-04-15 10:22:56 -07:00
Shayne Sweeney
cf76d2fc1c Add py/pl files to $text_paths (remove l/y files?!)
Summary:
I'm guessing this was refactored somewhere down the line and it meant
that Python and Perl files were no longer considered text files.

I'm imagining the old regex was: p(hp|y|l). Therefore I blame CSS.

Test Plan:
Perform an arc lint on a Python or Perl file that has trailing whitespace
on a line. It should prompt you for an autocorrecting lint.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5637
2013-04-09 15:07:05 -07:00
Nick Harper
30e12a0c9a Improve error if python can't run pep8
Summary:
On systems with an ancient version of python, the pep8 linter won't run.
Instead of blowing up in the user's face, we should display a nice error
message.

Test Plan:
Put /usr/bin (where the ancient version of python is) at the beginning of
my path and tried to lint some python. I got a nice error instead of a
stack trace.

Reviewers: epriestley, wez

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5356
2013-03-19 11:44:49 -07:00
Jakub Vrana
a925ef9dc1 Improve Windows compatibility
Test Plan:
  $ arc liberate
  $ arc lint

Reviewers: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5319
2013-03-10 18:08:41 -07:00
vrana
955bfb5581 Initialize variable in lint patch output 2013-03-08 15:25:33 -08:00
Andrew Chen
263cf9a95f Complain about Reuse of By-ref Iterators
Summary:
Added a lint rule that warns about reusing iterator reference
variables.

Test Plan:
- Add a file with examples found in with https://secure.phabricator.com/T2536
- Did not make a unit test yet

Reviewers: vrana, bill, epriestley

Reviewed By: epriestley

CC: aran, epriestley, Korvin

Maniphest Tasks: T2536

Differential Revision: https://secure.phabricator.com/D5179
2013-03-05 07:45:02 -08:00
vrana
2f09de2e79 Include linter class MD5 in linter version
Summary:
People constantly forget to bump the linter version and I don't see a way how to stop it.
This may bump the version even if it wouldn't be required but let's rather undercache than overcache.

Test Plan: `var_dump($version)`.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5129
2013-02-26 16:01:25 -08:00
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