diff --git a/src/lint/linter/ArcanistClosureLinter.php b/src/lint/linter/ArcanistClosureLinter.php new file mode 100644 --- /dev/null +++ b/src/lint/linter/ArcanistClosureLinter.php @@ -0,0 +1,109 @@ +getDeprecatedConfiguration('lint.closure.prefix'); + $bin = $this->getDeprecatedConfiguration('lint.closure.bin', 'gjslint'); + + if ($prefix) { + return $prefix.'/'.$bin; + } else { + return $bin; + } + } + + public function shouldUseInterpreter() { + return true; + } + + public function getDefaultInterpreter() { + return 'python'; + } + + public function getInstallInstructions() { + return pht('Install gJSLint using `sudo easy_install http://closure-linter'. + '.googlecode.com/files/closure_linter-latest.tar.gz`'); + } + + public function shouldExpectCommandErrors() { + return true; + } + + public function supportsReadDataFromStdin() { + return false; + } + + protected function getDefaultFlags() { + $options = $this->getDeprecatedConfiguration( + 'lint.closure.options', + array()); + + return $options; + } + + protected function parseLinterOutput($path, $err, $stdout, $stderr) { + // Each line looks like this: + // Line 46, E:0110: Line too long (87 characters). + $regex = '/^Line (\d+), (E:\d+): (.*)/'; + $severity_code = ArcanistLintSeverity::SEVERITY_ERROR; + + $lines = explode("\n", $stdout); + + $messages = array(); + foreach ($lines as $line) { + $line = trim($line); + $matches = null; + if (!preg_match($regex, $line, $matches)) { + continue; + } + foreach ($matches as $key => $match) { + $matches[$key] = trim($match); + } + + $message = new ArcanistLintMessage(); + $message->setPath($path); + $message->setLine($matches[1]); + $message->setName($matches[2]); + $message->setCode($this->getLinterName()); + $message->setDescription($matches[3]); + $message->setSeverity($severity_code); + + $messages[] = $message; + } + + return $messages; + } +}