From: Joshua Spence Date: Sun, 11 May 2014 12:32:38 +0000 (-0700) Subject: Allow global excludes to be specified in `.arclint`. X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=c4985ef4155622a06979e21df444d02be13130fd;p=arcanist.git 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 --- diff --git a/src/lint/engine/ArcanistConfigurationDrivenLintEngine.php b/src/lint/engine/ArcanistConfigurationDrivenLintEngine.php index ef12f765..b3cb0db3 100644 --- a/src/lint/engine/ArcanistConfigurationDrivenLintEngine.php +++ b/src/lint/engine/ArcanistConfigurationDrivenLintEngine.php @@ -25,9 +25,13 @@ final class ArcanistConfigurationDrivenLintEngine extends ArcanistLintEngine { PhutilTypeSpec::checkMap( $config, array( + 'exclude' => 'optional string | list', 'linters' => 'map>', )); + $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)); + } } } }