~ubuntu-branches/ubuntu/wily/phabricator/wily

« back to all changes in this revision

Viewing changes to src/lint/linter/ArcanistRubyLinter.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-11-01 23:20:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20141101232006-mvlnp0cil67tsboe
Tags: upstream-0~git20141101/arcanist
Import upstream version 0~git20141101, component arcanist

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Uses `ruby` to detect various errors in Ruby code.
 
5
 */
 
6
final class ArcanistRubyLinter extends ArcanistExternalLinter {
 
7
 
 
8
  public function getInfoURI() {
 
9
    return 'https://www.ruby-lang.org/';
 
10
  }
 
11
 
 
12
  public function getInfoName() {
 
13
    return pht('Ruby');
 
14
  }
 
15
 
 
16
  public function getInfoDescription() {
 
17
    return pht('Use `ruby` to check for syntax errors in Ruby source files.');
 
18
  }
 
19
 
 
20
  public function getLinterName() {
 
21
    return 'RUBY';
 
22
  }
 
23
 
 
24
  public function getLinterConfigurationName() {
 
25
    return 'ruby';
 
26
  }
 
27
 
 
28
  public function getDefaultBinary() {
 
29
    $prefix = $this->getDeprecatedConfiguration('lint.ruby.prefix');
 
30
    if ($prefix !== null) {
 
31
      $ruby_bin = $prefix.'ruby';
 
32
    }
 
33
 
 
34
    return 'ruby';
 
35
  }
 
36
 
 
37
  public function getVersion() {
 
38
    list($stdout) = execx('%C --version', $this->getExecutableCommand());
 
39
 
 
40
    $matches = array();
 
41
    $regex = '/^ruby (?P<version>\d+\.\d+\.\d+)p\d+/';
 
42
    if (preg_match($regex, $stdout, $matches)) {
 
43
      return $matches['version'];
 
44
    } else {
 
45
      return false;
 
46
    }
 
47
  }
 
48
 
 
49
  public function getInstallInstructions() {
 
50
    return pht('Install `ruby` from <http://www.ruby-lang.org/>.');
 
51
  }
 
52
 
 
53
  public function supportsReadDataFromStdin() {
 
54
    return true;
 
55
  }
 
56
 
 
57
  public function shouldExpectCommandErrors() {
 
58
    return true;
 
59
  }
 
60
 
 
61
  protected function getMandatoryFlags() {
 
62
    // -w: turn on warnings
 
63
    // -c: check syntax
 
64
    return array('-w', '-c');
 
65
  }
 
66
 
 
67
  protected function parseLinterOutput($path, $err, $stdout, $stderr) {
 
68
    $lines = phutil_split_lines($stderr, false);
 
69
 
 
70
    $messages = array();
 
71
    foreach ($lines as $line) {
 
72
      $matches = null;
 
73
 
 
74
      if (!preg_match('/(.*?):(\d+): (.*?)$/', $line, $matches)) {
 
75
        continue;
 
76
      }
 
77
 
 
78
      foreach ($matches as $key => $match) {
 
79
        $matches[$key] = trim($match);
 
80
      }
 
81
 
 
82
      $code = head(explode(',', $matches[3]));
 
83
 
 
84
      $message = new ArcanistLintMessage();
 
85
      $message->setPath($path);
 
86
      $message->setLine($matches[2]);
 
87
      $message->setCode($this->getLinterName());
 
88
      $message->setName(pht('Syntax Error'));
 
89
      $message->setDescription($matches[3]);
 
90
      $message->setSeverity($this->getLintMessageSeverity($code));
 
91
 
 
92
      $messages[] = $message;
 
93
    }
 
94
 
 
95
    if ($err && !$messages) {
 
96
      return false;
 
97
    }
 
98
 
 
99
    return $messages;
 
100
  }
 
101
 
 
102
}