Changeset View
Changeset View
Standalone View
Standalone View
src/lint/engine/ArcanistConfigurationDrivenLintEngine.php
<?php | <?php | ||||
final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine { | class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine { | ||||
NorthIsUp: I have no idea what the correct thing to do here is. | |||||
public function buildLinters() { | public function getLinterConfig() { | ||||
$working_copy = $this->getWorkingCopy(); | $working_copy = $this->getWorkingCopy(); | ||||
$config_path = $working_copy->getProjectPath('.arclint'); | $config_path = $working_copy->getProjectPath('.arclint'); | ||||
if (!Filesystem::pathExists($config_path)) { | if (!Filesystem::pathExists($config_path)) { | ||||
throw new Exception( | throw new Exception( | ||||
"Unable to find '.arclint' file to configure linters. Create a ". | "Unable to find '.arclint' file to configure linters. Create a ". | ||||
"'.arclint' file in the root directory of the working copy."); | "'.arclint' file in the root directory of the working copy."); | ||||
} | } | ||||
$data = Filesystem::readFile($config_path); | $data = Filesystem::readFile($config_path); | ||||
$config = json_decode($data, true); | $config = json_decode($data, true); | ||||
if (!is_array($config)) { | if (!is_array($config)) { | ||||
throw new Exception( | throw new Exception( | ||||
"Expected '.arclint' file to be a valid JSON file, but failed to ". | "Expected '.arclint' file to be a valid JSON file, but failed to ". | ||||
"decode it: {$config_path}"); | "decode it: {$config_path}"); | ||||
} | } | ||||
return $config; | |||||
} | |||||
public function buildLinters() { | |||||
$config = $this->getLinterConfig(); | |||||
$linters = $this->loadAvailableLinters(); | $linters = $this->loadAvailableLinters(); | ||||
try { | try { | ||||
PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
$config, | $config, | ||||
array( | array( | ||||
'exclude' => 'optional regex | list<regex>', | 'exclude' => 'optional regex | list<regex>', | ||||
'linters' => 'map<string, map<string, wild>>', | 'linters' => 'map<string, map<string, wild>>', | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | foreach ($config['linters'] as $name => $spec) { | ||||
$built_linters[] = $linter; | $built_linters[] = $linter; | ||||
} | } | ||||
return $built_linters; | return $built_linters; | ||||
} | } | ||||
private function loadAvailableLinters() { | private function loadAvailableLinters() { | ||||
$linters = id(new PhutilSymbolLoader()) | $linters = id(new PhutilSymbolLoader()) | ||||
->setAncestorClass('ArcanistLinter') | ->setAncestorClass('ArcanistLinter') | ||||
->loadObjects(); | ->loadObjects(); | ||||
$map = array(); | $map = array(); | ||||
foreach ($linters as $linter) { | foreach ($linters as $linter) { | ||||
$name = $linter->getLinterConfigurationName(); | $name = $linter->getLinterConfigurationName(); | ||||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |
I have no idea what the correct thing to do here is.