1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-22 21:40:54 +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(
$config,
array(
'exclude' => 'optional string | list<string>',
'linters' => 'map<string, map<string, wild>>',
));
$global_exclude = (array)idx($config, 'exclude', array());
$this->validateRegexps($global_exclude);
$built_linters = array();
$all_paths = $this->getPaths();
foreach ($config['linters'] as $name => $spec) {
@ -81,7 +85,11 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
$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,
$global_exclude);
$console->writeLog(
"Found %d matching paths for linter \"%s\".\n",
count($paths),
@ -126,7 +134,12 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
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();
$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");
$match[] = $path;
}
@ -180,17 +209,28 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine {
return $match;
}
private function validateRegexps(array $regexps, $linter, $config) {
private function validateRegexps(
array $regexps,
$linter = null,
$config = null) {
foreach ($regexps as $regexp) {
$ok = @preg_match($regexp, '');
if ($ok === false) {
throw new Exception(
pht(
'Regular expression "%s" (in "%s" configuration for linter "%s") '.
'is not a valid regular expression.',
$regexp,
$config,
$linter));
if ($linter) {
throw new Exception(
pht(
'Regular expression "%s" (in "%s" configuration for linter '.
'"%s") is not a valid regular expression.',
$regexp,
$config,
$linter));
} else {
throw new Exception(
pht(
'Regular expression "%s" is not a valid regular expression.',
$regexp));
}
}
}
}