1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 16:22:42 +01:00

Set all lint paths at once

Summary:
This code is much more readable to me.
It should also be faster as building the array at once should be faster than one by one.

Test Plan: Made license and XHPAST errors in PHP file, made spelling error in JS file.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3758
This commit is contained in:
vrana 2012-10-20 05:45:22 -07:00
parent 262423b5a8
commit 77af6fb35d
4 changed files with 40 additions and 159 deletions

View file

@ -71,9 +71,7 @@ final class ArcanistSingleLintEngine extends ArcanistLintEngine {
}
$linter = newv($linter_name, array());
foreach ($paths as $path) {
$linter->addPath($path);
}
$linter->setPaths($paths);
return array($linter);
}

View file

@ -39,114 +39,32 @@ final class ComprehensiveLintEngine extends ArcanistLintEngine {
}
}
$generated_linter = new ArcanistGeneratedLinter();
$linters[] = $generated_linter;
$text_paths = preg_grep('/\.(php|css|hpp|cpp|l|y)$/', $paths);
$linters[] = id(new ArcanistGeneratedLinter())->setPaths($text_paths);
$linters[] = id(new ArcanistNoLintLinter())->setPaths($text_paths);
$linters[] = id(new ArcanistTextLinter())->setPaths($text_paths);
$nolint_linter = new ArcanistNoLintLinter();
$linters[] = $nolint_linter;
$linters[] = id(new ArcanistFilenameLinter())->setPaths($paths);
$text_linter = new ArcanistTextLinter();
$linters[] = $text_linter;
foreach ($paths as $path) {
$is_text = false;
if (preg_match('/\.(php|css|hpp|cpp|l|y)$/', $path)) {
$is_text = true;
}
if ($is_text) {
$generated_linter->addPath($path);
$generated_linter->addData($path, $this->loadData($path));
$linters[] = id(new ArcanistXHPASTLinter())
->setPaths(preg_grep('/\.php$/', $paths));
$nolint_linter->addPath($path);
$nolint_linter->addData($path, $this->loadData($path));
$linters[] = id(new ArcanistApacheLicenseLinter())
->setPaths(preg_grep('/\.(php|cpp|hpp|l|y)$/', $paths));
$text_linter->addPath($path);
$text_linter->addData($path, $this->loadData($path));
}
}
$py_paths = preg_grep('/\.py$/', $paths);
$linters[] = id(new ArcanistPyFlakesLinter())->setPaths($py_paths);
$linters[] = id(new ArcanistPEP8Linter())->setPaths($py_paths);
$name_linter = new ArcanistFilenameLinter();
$linters[] = $name_linter;
foreach ($paths as $path) {
$name_linter->addPath($path);
}
$linters[] = id(new ArcanistRubyLinter())
->setPaths(preg_grep('/\.rb$/', $paths));
$xhpast_linter = new ArcanistXHPASTLinter();
$linters[] = $xhpast_linter;
foreach ($paths as $path) {
if (preg_match('/\.php$/', $path)) {
$xhpast_linter->addPath($path);
$xhpast_linter->addData($path, $this->loadData($path));
}
}
$linters[] = id(new ArcanistJSHintLinter())
->setPaths(preg_grep('/\.js$/', $paths));
$linters = array_merge($linters, $this->buildLicenseLinters($paths));
$linters = array_merge($linters, $this->buildPythonLinters($paths));
$linters = array_merge($linters, $this->buildRubyLinters($paths));
$linters = array_merge($linters, $this->buildJSLinters($paths));
return $linters;
}
public function buildLicenseLinters($paths) {
$license_linter = new ArcanistApacheLicenseLinter();
$linters = array();
$linters[] = $license_linter;
foreach ($paths as $path) {
if (preg_match('/\.(php|cpp|hpp|l|y)$/', $path)) {
if (!preg_match('@^externals/@', $path)) {
$license_linter->addPath($path);
$license_linter->addData($path, $this->loadData($path));
}
}
}
return $linters;
}
public function buildPythonLinters($paths) {
$pyflakes_linter = new ArcanistPyFlakesLinter();
$pep8_linter = new ArcanistPEP8Linter();
$linters = array();
$linters[] = $pyflakes_linter;
$linters[] = $pep8_linter;
foreach ($paths as $path) {
if (preg_match('/\.py$/', $path)) {
$pyflakes_linter->addPath($path);
$pyflakes_linter->addData($path, $this->loadData($path));
$pep8_linter->addPath($path);
$pep8_linter->addData($path, $this->loadData($path));
}
}
return $linters;
}
public function buildRubyLinters($paths) {
$ruby_linter = new ArcanistRubyLinter();
$linters = array();
$linters[] = $ruby_linter;
foreach ($paths as $path) {
if (preg_match('/\.rb$/', $path)) {
$ruby_linter->addPath($path);
$ruby_linter->addData($path, $this->loadData($path));
}
}
return $linters;
}
public function buildJSLinters($paths) {
$js_linter = new ArcanistJSHintLinter();
$linters = array();
$linters[] = $js_linter;
foreach ($paths as $path) {
if (preg_match('/\.js$/', $path)) {
$js_linter->addPath($path);
$js_linter->addData($path, $this->loadData($path));
}
}
return $linters;
}
}

View file

@ -30,11 +30,7 @@ class PhutilLintEngine extends ArcanistLintEngine {
$paths = $this->getPaths();
$library_linter = new ArcanistPhutilLibraryLinter();
$linters[] = $library_linter;
foreach ($paths as $path) {
$library_linter->addPath($path);
}
$linters[] = id(new ArcanistPhutilLibraryLinter())->setPaths($paths);
// Remaining linters operate on file contents and ignore removed files.
foreach ($paths as $key => $path) {
@ -48,66 +44,30 @@ class PhutilLintEngine extends ArcanistLintEngine {
}
}
$name_linter = new ArcanistFilenameLinter();
$linters[] = $name_linter;
$linters[] = id(new ArcanistFilenameLinter())->setPaths($paths);
// Skip directories and lint only regular files in remaining linters.
foreach ($paths as $key => $path) {
$name_linter->addPath($path);
if (!$this->getCommitHookMode() &&
!is_file($this->getFilePathOnDisk($path))) {
if ($this->getCommitHookMode()) {
continue;
}
if (!is_file($this->getFilePathOnDisk($path))) {
unset($paths[$key]);
}
}
$generated_linter = new ArcanistGeneratedLinter();
$linters[] = $generated_linter;
$text_paths = preg_grep('/\.(php|css|js|hpp|cpp|l|y)$/', $paths);
$linters[] = id(new ArcanistGeneratedLinter())->setPaths($text_paths);
$linters[] = id(new ArcanistNoLintLinter())->setPaths($text_paths);
$linters[] = id(new ArcanistTextLinter())->setPaths($text_paths);
$linters[] = id(new ArcanistSpellingLinter())->setPaths($text_paths);
$nolint_linter = new ArcanistNoLintLinter();
$linters[] = $nolint_linter;
$linters[] = id(new ArcanistXHPASTLinter())
->setCustomSeverityMap($this->getXHPASTSeverityMap())
->setPaths(preg_grep('/\.php$/', $paths));
$text_linter = new ArcanistTextLinter();
$linters[] = $text_linter;
$spelling_linter = new ArcanistSpellingLinter();
$linters[] = $spelling_linter;
foreach ($paths as $path) {
$is_text = false;
if (preg_match('/\.(php|css|js|hpp|cpp|l|y)$/', $path)) {
$is_text = true;
}
if ($is_text) {
$generated_linter->addPath($path);
$generated_linter->addData($path, $this->loadData($path));
$nolint_linter->addPath($path);
$nolint_linter->addData($path, $this->loadData($path));
$text_linter->addPath($path);
$text_linter->addData($path, $this->loadData($path));
$spelling_linter->addPath($path);
$spelling_linter->addData($path, $this->loadData($path));
}
}
$xhpast_linter = new ArcanistXHPASTLinter();
$xhpast_map = $this->getXHPASTSeverityMap();
$xhpast_linter->setCustomSeverityMap($xhpast_map);
$linters[] = $xhpast_linter;
foreach ($paths as $path) {
if (preg_match('/\.php$/', $path)) {
$xhpast_linter->addPath($path);
$xhpast_linter->addData($path, $this->loadData($path));
}
}
$license_linter = new ArcanistApacheLicenseLinter();
$linters[] = $license_linter;
foreach ($paths as $path) {
if (preg_match('/\.(php|cpp|hpp|l|y)$/', $path)) {
$license_linter->addPath($path);
$license_linter->addData($path, $this->loadData($path));
}
}
$linters[] = id(new ArcanistApacheLicenseLinter())
->setPaths(preg_grep('/\.(php|cpp|hpp|l|y)$/', $paths));
return $linters;
}

View file

@ -57,6 +57,11 @@ abstract class ArcanistLinter {
return $this;
}
public function setPaths(array $paths) {
$this->paths = $paths;
return $this;
}
public function getPaths() {
return array_values($this->paths);
}