1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-26 08:42:40 +01:00

Remove debug key from .arclint file format.

Summary: Having a `debug` key in the `.arclint` file format doesn't seem right. Instead, it would be better to just use a `PhutilConsole` and the `writeLog` method so that "debug" messages are output when using `arc --trace`.

Test Plan: Ran `arc lint --trace` in a repository using `.arclint`.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9021
This commit is contained in:
Joshua Spence 2014-05-09 06:00:36 -07:00 committed by epriestley
parent 1591b21e86
commit 4298b4ea8b

View file

@ -2,8 +2,6 @@
final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine { final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
private $debugMode;
public function buildLinters() { public function buildLinters() {
$working_copy = $this->getWorkingCopy(); $working_copy = $this->getWorkingCopy();
$config_path = $working_copy->getProjectPath('.arclint'); $config_path = $working_copy->getProjectPath('.arclint');
@ -28,11 +26,8 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
$config, $config,
array( array(
'linters' => 'map<string, map<string, wild>>', 'linters' => 'map<string, map<string, wild>>',
'debug' => 'optional bool',
)); ));
$this->debugMode = idx($config, 'debug', false);
$built_linters = array(); $built_linters = array();
$all_paths = $this->getPaths(); $all_paths = $this->getPaths();
foreach ($config['linters'] as $name => $spec) { foreach ($config['linters'] as $name => $spec) {
@ -84,10 +79,11 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
$this->validateRegexps($include, $name, 'include'); $this->validateRegexps($include, $name, 'include');
$this->validateRegexps($exclude, $name, 'exclude'); $this->validateRegexps($exclude, $name, 'exclude');
$this->debugLog('Examining paths for linter "%s".', $name); $console = PhutilConsole::getConsole();
$console->writeLog("Examining paths for linter \"%s\".\n", $name);
$paths = $this->matchPaths($all_paths, $include, $exclude); $paths = $this->matchPaths($all_paths, $include, $exclude);
$this->debugLog( $console->writeLog(
'Found %d matching paths for linter "%s".', "Found %d matching paths for linter \"%s\".\n",
count($paths), count($paths),
$name); $name);
@ -131,48 +127,53 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
} }
private function matchPaths(array $paths, array $include, array $exclude) { private function matchPaths(array $paths, array $include, array $exclude) {
$debug = $this->debugMode; $console = PhutilConsole::getConsole();
$match = array(); $match = array();
foreach ($paths as $path) { foreach ($paths as $path) {
$this->debugLog("Examining path '%s'...", $path); $console->writeLog("Examining path '%s'...\n", $path);
$keep = false; $keep = false;
if (!$include) { if (!$include) {
$keep = true; $keep = true;
$this->debugLog( $console->writeLog(
" Including path by default because there is no 'include' rule."); " Including path by default because there is no 'include' rule.\n");
} else { } else {
$this->debugLog(' Testing "include" rules.'); $console->writeLog(" Testing \"include\" rules.\n");
foreach ($include as $rule) { foreach ($include as $rule) {
if (preg_match($rule, $path)) { if (preg_match($rule, $path)) {
$keep = true; $keep = true;
$this->debugLog(' Path matches include rule: %s', $rule); $console->writeLog(" Path matches include rule: %s\n", $rule);
break; break;
} else { } else {
$this->debugLog(' Path does not match include rule: %s', $rule); $console->writeLog(
" Path does not match include rule: %s\n",
$rule);
} }
} }
} }
if (!$keep) { if (!$keep) {
$this->debugLog(' Path does not match any include rules, discarding.'); $console->writeLogLog(
" Path does not match any include rules, discarding.\n");
continue; continue;
} }
if ($exclude) { if ($exclude) {
$this->debugLog(' Testing "exclude" rules.'); $console->writeLog(" Testing \"exclude\" rules.\n");
foreach ($exclude as $rule) { foreach ($exclude as $rule) {
if (preg_match($rule, $path)) { if (preg_match($rule, $path)) {
$this->debugLog(' Path matches "exclude" rule: %s', $rule); $console->writeLog(" Path matches \"exclude\" rule: %s\n", $rule);
continue 2; continue 2;
} else { } else {
$this->debugLog(' Path does not match "exclude" rule: %s', $rule); $console->writeLog(
" Path does not match \"exclude\" rule: %s\n",
$rule);
} }
} }
} }
$this->debugLog(' Path matches.'); $console->writeLog(" Path matches.\n");
$match[] = $path; $match[] = $path;
} }
@ -194,16 +195,4 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
} }
} }
private function debugLog($pattern /* , $arg, ... */) {
if (!$this->debugMode) {
return;
}
$console = PhutilConsole::getConsole();
$argv = func_get_args();
$argv[0] .= "\n";
call_user_func_array(array($console, 'writeErr'), $argv);
}
} }