1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 23:02:41 +01:00

Allow global excludes to be specified in .arclint.

Summary: Currently, paths to be excluded from linting need to be specified for each linter individually. This is a pain for projects that are using even a moderate number of linters and which have common paths which should be excluded from linting completely.

Test Plan: Unfortunately, it's hard to test this sort of stuff. I cloned the `arclint-examples` repository and tested my changes there,

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9054
This commit is contained in:
Joshua Spence 2014-05-11 05:32:38 -07:00 committed by epriestley
parent 48c67d9c15
commit c4985ef415

View file

@ -25,9 +25,13 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
PhutilTypeSpec::checkMap( PhutilTypeSpec::checkMap(
$config, $config,
array( array(
'exclude' => 'optional string | list<string>',
'linters' => 'map<string, map<string, wild>>', 'linters' => 'map<string, map<string, wild>>',
)); ));
$global_exclude = (array)idx($config, 'exclude', array());
$this->validateRegexps($global_exclude);
$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) {
@ -81,7 +85,11 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
$console->writeLog("Examining paths for linter \"%s\".\n", $name); $console->writeLog("Examining paths for linter \"%s\".\n", $name);
$paths = $this->matchPaths($all_paths, $include, $exclude); $paths = $this->matchPaths(
$all_paths,
$include,
$exclude,
$global_exclude);
$console->writeLog( $console->writeLog(
"Found %d matching paths for linter \"%s\".\n", "Found %d matching paths for linter \"%s\".\n",
count($paths), count($paths),
@ -126,7 +134,12 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
return $map; return $map;
} }
private function matchPaths(array $paths, array $include, array $exclude) { private function matchPaths(
array $paths,
array $include,
array $exclude,
array $global_exclude) {
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
$match = array(); $match = array();
@ -173,6 +186,22 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
} }
} }
if ($global_exclude) {
$console->writeLog(" Testing global \"exclude\" rules.\n");
foreach ($global_exclude as $rule) {
if (preg_match($rule, $path)) {
$console->writeLog(
" Path matches global \"exclude\" rule: %s\n",
$rule);
continue 2;
} else {
$console->writeLog(
" Path does not match global \"exclude\" rule: %s\n",
$rule);
}
}
}
$console->writeLog(" Path matches.\n"); $console->writeLog(" Path matches.\n");
$match[] = $path; $match[] = $path;
} }
@ -180,17 +209,28 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
return $match; return $match;
} }
private function validateRegexps(array $regexps, $linter, $config) { private function validateRegexps(
array $regexps,
$linter = null,
$config = null) {
foreach ($regexps as $regexp) { foreach ($regexps as $regexp) {
$ok = @preg_match($regexp, ''); $ok = @preg_match($regexp, '');
if ($ok === false) { if ($ok === false) {
if ($linter) {
throw new Exception( throw new Exception(
pht( pht(
'Regular expression "%s" (in "%s" configuration for linter "%s") '. 'Regular expression "%s" (in "%s" configuration for linter '.
'is not a valid regular expression.', '"%s") is not a valid regular expression.',
$regexp, $regexp,
$config, $config,
$linter)); $linter));
} else {
throw new Exception(
pht(
'Regular expression "%s" is not a valid regular expression.',
$regexp));
}
} }
} }
} }