1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-02-13 15:28:34 +01:00
phorge-arcanist/src/lint/linter/ArcanistScalaSBTLinter.php
epriestley 7870e7f2e4 Warn when accessing deprecated lint config
Summary:
Ref T2039. Addresses two issues:

  - Issues a warning for use of config which is deprecated by `.arclint`.
  - We no longer require an engine to be present for these linters, so `arc linters` doesn't fatal if they aren't configured.

Test Plan:
  - Ran `arc linters` in a repo with no JSHint.
  - Ran `arc linters` in a repo with junk in .arcconfig and got a warning when it was read. Verified it still took effect.

Reviewers: chad, btrahan, joshuaspence

Reviewed By: joshuaspence

Subscribers: epriestley

Maniphest Tasks: T2039

Differential Revision: https://secure.phabricator.com/D9058
2014-05-11 18:39:28 -07:00

76 lines
2.1 KiB
PHP

<?php
/**
* Uses `sbt compile` to detect various warnings/errors in Scala code.
*/
final class ArcanistScalaSBTLinter extends ArcanistLinter {
public function getLinterName() {
return 'ScalaSBT';
}
public function canRun() {
// Check if this looks like a SBT project. If it doesn't, throw, because
// we rely fairly heavily on `sbt compile` working, below. We don't want
// to call out to scalac ourselves, because then we'll end up in Class Path
// Hell. We let the build system handle this for us.
if (!Filesystem::pathExists('project/Build.scala') &&
!Filesystem::pathExists('build.sbt')) {
return false;
}
return true;
}
private function getSBTPath() {
$sbt_bin = "sbt";
$prefix = $this->getDeprecatedConfiguration('lint.scala_sbt.prefix');
if ($prefix !== null) {
$sbt_bin = $prefix . $sbt_bin;
}
return $sbt_bin;
}
private function getMessageCodeSeverity($type_of_error) {
switch ($type_of_error) {
case 'warn':
return ArcanistLintSeverity::SEVERITY_WARNING;
case 'error':
return ArcanistLintSeverity::SEVERITY_ERROR;
}
}
public function lintPath($path) {
$sbt = $this->getSBTPath();
// Tell SBT to not use color codes so our regex life is easy.
// TODO: Should this be "clean compile" instead of "compile"?
$f = new ExecFuture("%s -Dsbt.log.noformat=true compile", $sbt);
list($err, $stdout, $stderr) = $f->resolve();
$lines = explode("\n", $stdout);
$messages = array();
foreach ($lines as $line) {
$matches = null;
if (!preg_match(
"/\[(warn|error)\] (.*?):(\d+): (.*?)$/",
$line,
$matches)) {
continue;
}
foreach ($matches as $key => $match) {
$matches[$key] = trim($match);
}
$message = new ArcanistLintMessage();
$message->setPath($matches[2]);
$message->setLine($matches[3]);
$message->setCode($this->getLinterName());
$message->setDescription($matches[4]);
$message->setSeverity($this->getMessageCodeSeverity($matches[1]));
$this->addLintMessage($message);
}
}
}