Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistLinter.php
Show First 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | /* -( Runtime State )------------------------------------------------------ */ | ||||
final public function getLinterID() { | final public function getLinterID() { | ||||
return $this->id; | return $this->id; | ||||
} | } | ||||
/* -( Executing Linters )-------------------------------------------------- */ | /* -( Executing Linters )-------------------------------------------------- */ | ||||
final public function lintPaths(array $paths) { | |||||
assert_instances_of($paths, 'ArcanistWorkingCopyPath'); | |||||
$this->messages = array(); | |||||
foreach ($paths as $path) { | |||||
$this->setActivePath($path); | |||||
$this->lintPath($path); | |||||
} | |||||
return $this->getLintMessages(); | |||||
} | |||||
/** | /** | ||||
* Hook called before a list of paths are linted. | * Hook called before a list of paths are linted. | ||||
* | * | ||||
* Parallelizable linters can start multiple requests in parallel here, | * Parallelizable linters can start multiple requests in parallel here, | ||||
* to improve performance. They can implement @{method:didLintPaths} to | * to improve performance. They can implement @{method:didLintPaths} to | ||||
* collect results. | * collect results. | ||||
* | * | ||||
* Linters which are not parallelizable should normally ignore this callback | * Linters which are not parallelizable should normally ignore this callback | ||||
* and implement @{method:lintPath} instead. | * and implement @{method:lintPath} instead. | ||||
* | * | ||||
* @param list<string> A list of paths to be linted | * @param list<string> A list of paths to be linted | ||||
* @return void | * @return void | ||||
* @task exec | * @task exec | ||||
*/ | */ | ||||
public function willLintPaths(array $paths) { | public function willLintPaths(array $paths) { | ||||
return; | return; | ||||
} | } | ||||
/** | protected function lintPath(ArcanistWorkingCopyPath $path) { | ||||
* Hook called for each path to be linted. | |||||
* | |||||
* Linters which are not parallelizable can do work here. | |||||
* | |||||
* Linters which are parallelizable may want to ignore this callback and | |||||
* implement @{method:willLintPaths} and @{method:didLintPaths} instead. | |||||
* | |||||
* @param string Path to lint. | |||||
* @return void | |||||
* @task exec | |||||
*/ | |||||
public function lintPath($path) { | |||||
return; | return; | ||||
} | } | ||||
/** | /** | ||||
* Hook called after a list of paths are linted. | * Hook called after a list of paths are linted. | ||||
* | * | ||||
* Parallelizable linters can collect results here. | * Parallelizable linters can collect results here. | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | final public function getProjectRoot() { | ||||
return $working_copy->getProjectRoot(); | return $working_copy->getProjectRoot(); | ||||
} | } | ||||
final public function getOtherLocation($offset, $path = null) { | final public function getOtherLocation($offset, $path = null) { | ||||
if ($path === null) { | if ($path === null) { | ||||
$path = $this->getActivePath(); | $path = $this->getActivePath(); | ||||
} | } | ||||
list($line, $char) = $this->getEngine()->getLineAndCharFromOffset( | list($line, $char) = $path->getLineAndCharFromOffset($offset); | ||||
$path, | |||||
$offset); | |||||
return array( | return array( | ||||
'path' => $path, | 'path' => $path, | ||||
'line' => $line + 1, | 'line' => $line + 1, | ||||
'char' => $char, | 'char' => $char, | ||||
); | ); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | final public function getLintMessageName($code) { | ||||
$map = $this->getLintNameMap(); | $map = $this->getLintNameMap(); | ||||
if (isset($map[$code])) { | if (isset($map[$code])) { | ||||
return $map[$code]; | return $map[$code]; | ||||
} | } | ||||
return pht('Unknown lint message!'); | return pht('Unknown lint message!'); | ||||
} | } | ||||
final protected function addLintMessage(ArcanistLintMessage $message) { | final protected function addLintMessage(ArcanistLintMessage $message) { | ||||
$root = $this->getProjectRoot(); | |||||
$path = Filesystem::resolvePath($message->getPath(), $root); | |||||
$message->setPath(Filesystem::readablePath($path, $root)); | |||||
$this->messages[] = $message; | $this->messages[] = $message; | ||||
return $message; | return $message; | ||||
} | } | ||||
final public function getLintMessages() { | final public function getLintMessages() { | ||||
return $this->messages; | return $this->messages; | ||||
} | } | ||||
Show All 31 Lines | final public function raiseLintAtOffset( | ||||
$replacement = null) { | $replacement = null) { | ||||
$path = $this->getActivePath(); | $path = $this->getActivePath(); | ||||
$engine = $this->getEngine(); | $engine = $this->getEngine(); | ||||
if ($offset === null) { | if ($offset === null) { | ||||
$line = null; | $line = null; | ||||
$char = null; | $char = null; | ||||
} else { | } else { | ||||
list($line, $char) = $engine->getLineAndCharFromOffset($path, $offset); | list($line, $char) = $path->getLineAndCharFromOffset($offset); | ||||
} | } | ||||
return $this->raiseLintAtLine( | return $this->raiseLintAtLine( | ||||
$line + 1, | $line + 1, | ||||
$char + 1, | $char + 1, | ||||
$code, | $code, | ||||
$description, | $description, | ||||
$original, | $original, | ||||
$replacement); | $replacement); | ||||
} | } | ||||
public function canRun() { | public function canRun() { | ||||
return true; | return true; | ||||
} | } | ||||
abstract public function getLinterName(); | abstract public function getLinterName(); | ||||
public function getVersion() { | public function getVersion() { | ||||
return null; | return null; | ||||
} | } | ||||
final protected function isCodeEnabled($code) { | final protected function isCodeEnabled($code) { | ||||
// TOOLSETS: Restore this. | |||||
return true; | |||||
$severity = $this->getLintMessageSeverity($code); | $severity = $this->getLintMessageSeverity($code); | ||||
return $this->getEngine()->isSeverityEnabled($severity); | return $this->getEngine()->isSeverityEnabled($severity); | ||||
} | } | ||||
public function getLintSeverityMap() { | public function getLintSeverityMap() { | ||||
return array(); | return array(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines |