~ubuntu-branches/ubuntu/vivid/phabricator/vivid-proposed

« back to all changes in this revision

Viewing changes to arcanist/src/lint/linter/ArcanistClosureLinter.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-10-23 20:49:26 UTC
  • mfrom: (0.2.1) (0.1.1)
  • Revision ID: package-import@ubuntu.com-20141023204926-vq80u1op4df44azb
Tags: 0~git20141023-1
Initial release (closes: #703046)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Uses gJSLint to detect errors and potential problems in JavaScript code.
 
5
 */
 
6
final class ArcanistClosureLinter extends ArcanistExternalLinter {
 
7
 
 
8
  public function getInfoName() {
 
9
    return 'Closure Linter';
 
10
  }
 
11
 
 
12
  public function getInfoURI() {
 
13
    return 'https://developers.google.com/closure/utilities/';
 
14
  }
 
15
 
 
16
  public function getInfoDescription() {
 
17
    return pht("Uses Google's Closure Linter to check Javascript code.");
 
18
  }
 
19
 
 
20
  public function getLinterName() {
 
21
    return 'Closure Linter';
 
22
  }
 
23
 
 
24
  public function getLinterConfigurationName() {
 
25
    return 'gjslint';
 
26
  }
 
27
 
 
28
  public function getDefaultBinary() {
 
29
    return 'gjslint';
 
30
  }
 
31
 
 
32
  public function getInstallInstructions() {
 
33
    return pht(
 
34
      'Install gJSLint using `sudo easy_install http://closure-linter'.
 
35
      '.googlecode.com/files/closure_linter-latest.tar.gz`');
 
36
  }
 
37
 
 
38
  public function shouldExpectCommandErrors() {
 
39
    return true;
 
40
  }
 
41
 
 
42
  public function supportsReadDataFromStdin() {
 
43
    return false;
 
44
  }
 
45
 
 
46
  protected function parseLinterOutput($path, $err, $stdout, $stderr) {
 
47
    // Each line looks like this:
 
48
    // Line 46, E:0110: Line too long (87 characters).
 
49
    $regex = '/^Line (\d+), (E:\d+): (.*)/';
 
50
    $severity_code = ArcanistLintSeverity::SEVERITY_ERROR;
 
51
 
 
52
    $lines = phutil_split_lines($stdout, false);
 
53
 
 
54
    $messages = array();
 
55
    foreach ($lines as $line) {
 
56
      $line = trim($line);
 
57
      $matches = null;
 
58
      if (!preg_match($regex, $line, $matches)) {
 
59
        continue;
 
60
      }
 
61
      foreach ($matches as $key => $match) {
 
62
        $matches[$key] = trim($match);
 
63
      }
 
64
 
 
65
      $message = new ArcanistLintMessage();
 
66
      $message->setPath($path);
 
67
      $message->setLine($matches[1]);
 
68
      $message->setName($matches[2]);
 
69
      $message->setCode($this->getLinterName());
 
70
      $message->setDescription($matches[3]);
 
71
      $message->setSeverity($severity_code);
 
72
 
 
73
      $messages[] = $message;
 
74
    }
 
75
 
 
76
    return $messages;
 
77
  }
 
78
 
 
79
}