diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 26f1d2e7..9e24b9c5 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -99,6 +99,7 @@ phutil_register_library_map(array( 'ArcanistXHPASTLinter' => 'lint/linter/xhpast', 'ArcanistXHPASTLinterTestCase' => 'lint/linter/xhpast/__tests__', 'BranchInfo' => 'branch', + 'ComprehensiveEngine' => 'lint/engine/comprehensive', 'ExampleLintEngine' => 'lint/engine/example', 'PhutilLintEngine' => 'lint/engine/phutil', 'PhutilModuleRequirements' => 'parser/phutilmodule', @@ -165,6 +166,7 @@ phutil_register_library_map(array( 'ArcanistUserAbortException' => 'ArcanistUsageException', 'ArcanistXHPASTLinter' => 'ArcanistLinter', 'ArcanistXHPASTLinterTestCase' => 'ArcanistLinterTestCase', + 'ComprehensiveEngine' => 'ArcanistLintEngine', 'ExampleLintEngine' => 'ArcanistLintEngine', 'PhutilLintEngine' => 'ArcanistLintEngine', 'PhutilUnitTestEngine' => 'ArcanistBaseUnitTestEngine', diff --git a/src/lint/engine/comprehensive/ComprehensiveLintEngine.php b/src/lint/engine/comprehensive/ComprehensiveLintEngine.php new file mode 100644 index 00000000..2aea781a --- /dev/null +++ b/src/lint/engine/comprehensive/ComprehensiveLintEngine.php @@ -0,0 +1,148 @@ +getPaths(); + + // This needs to go first so that changes to generated files cause module + // linting. This linter also operates on removed files, because removing + // a file changes the static properties of a module. + $module_linter = new ArcanistPhutilModuleLinter(); + $linters[] = $module_linter; + foreach ($paths as $path) { + $module_linter->addPath($path); + } + + // Remaining lint engines operate on file contents and ignore removed + // files. + foreach ($paths as $key => $path) { + if (!$this->pathExists($path)) { + unset($paths[$key]); + } + if (preg_match('@^externals/@', $path)) { + // Third-party stuff lives in /externals/; don't run lint engines + // against it. + unset($paths[$key]); + } + } + + $generated_linter = new ArcanistGeneratedLinter(); + $linters[] = $generated_linter; + + $nolint_linter = new ArcanistNoLintLinter(); + $linters[] = $nolint_linter; + + $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)); + + $nolint_linter->addPath($path); + $nolint_linter->addData($path, $this->loadData($path)); + + $text_linter->addPath($path); + $text_linter->addData($path, $this->loadData($path)); + } + } + + $name_linter = new ArcanistFilenameLinter(); + $linters[] = $name_linter; + foreach ($paths as $path) { + $name_linter->addPath($path); + } + + $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 = array_merge($linters, $this->buildLicenseLinters($paths)); + $linters = array_merge($linters, $this->buildPythonLinters($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 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; + } + +} diff --git a/src/lint/engine/comprehensive/__init__.php b/src/lint/engine/comprehensive/__init__.php new file mode 100644 index 00000000..0bd8062b --- /dev/null +++ b/src/lint/engine/comprehensive/__init__.php @@ -0,0 +1,22 @@ +