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:
parent
48c67d9c15
commit
c4985ef415
1 changed files with 50 additions and 10 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue