public function buildLinters() { // This is a list of paths which the user wants to lint. Either they // provided them explicitly, or arc figured them out from a commit or set // of changes. The engine needs to return a list of ArcanistLinter objects, // representing the linters which should be run on these files. $paths = $this->getPaths(); //echo('Foobar'); // $paths = ['./src/inbox']; // The ArcanistPyLintLinter runs "PyLint" (an open source python linter) on // files you give it. There are several linters available by default like // this one which you can use out of the box, or you can write your own. // Linters are responsible for actually analyzing the contents of a file // and raising warnings and errors. $pyflakes_linter = new ArcanistPyFlakesLinter(); $pylint_linter = new MGArcanistPyLintLinter(); $pep8_linter = new ArcanistPEP8Linter(); // Remove any paths that don't exist before we add paths to linters. We want // to do this for linters that operate on file contents because the // generated list of paths will include deleted paths when a file is // removed. foreach ($paths as $key => $path) { if (!$this->pathExists($path)) { unset($paths[$key]); } } foreach ($paths as $path) { if (!preg_match('/\\.py$/', $path)) { // This isn't a python file, so don't try to apply the PyLint linter // to it. continue; } if (preg_match('@^externals/@', $path)) { // This is just an example of how to exclude a path so it doesn't get // linted. If you put third-party code in an externals/ directory, you // can just have your lint engine ignore it. continue; } // Add the path, to tell the linter it should examine the source code // to try to find problems. $pyflakes_linter->addPath($path); $pylint_linter->addPath($path); $pep8_linter->addPath($path); } // We only built one linter, but you can build more than one (e.g., a // Javascript linter for JS), and return a list of linters to execute. You // can also add a path to more than one linter (for example, if you want // to run a Python linter and a more general text linter on every .py file). return array($pyflakes_linter, $pylint_linter, $pep8_linter); }
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 buildLinters() { $linters = array(); $paths = $this->getPaths(); // Remove all deleted files, which are not checked by the // following linters. foreach ($paths as $key => $path) { if (!Filesystem::pathExists($this->getFilePathOnDisk($path))) { unset($paths[$key]); } } $generated_linter = new ArcanistGeneratedLinter(); $linters[] = $generated_linter; $nolint_linter = new ArcanistNoLintLinter(); $linters[] = $nolint_linter; $text_linter = new ArcanistTextLinter(); $text_linter->setCustomSeverityMap(array(ArcanistTextLinter::LINT_LINE_WRAP => ArcanistLintSeverity::SEVERITY_ADVICE)); $linters[] = $text_linter; $java_text_linter = new ArcanistTextLinter(); $java_text_linter->setMaxLineLength(100); $java_text_linter->setCustomSeverityMap(array(ArcanistTextLinter::LINT_LINE_WRAP => ArcanistLintSeverity::SEVERITY_ADVICE)); $linters[] = $java_text_linter; $pep8_options = $this->getPEP8WithTextOptions() . ',E302'; $python_linter = new ArcanistPEP8Linter(); $python_linter->setConfig(array('options' => $pep8_options)); $linters[] = $python_linter; $python_2space_linter = new ArcanistPEP8Linter(); $python_2space_linter->setConfig(array('options' => $pep8_options . ',E111')); $linters[] = $python_2space_linter; // Currently we can't run cpplint in commit hook mode, because it // depends on having access to the working directory. if (!$this->getCommitHookMode()) { $cpp_linter = new FbcodeCppLinter(); $cpp_linter2 = new PfffCppLinter(); $linters[] = $cpp_linter; $linters[] = $cpp_linter2; } $spelling_linter = new ArcanistSpellingLinter(); $linters[] = $spelling_linter; foreach ($paths as $path) { $is_text = false; $text_extensions = '/\\.(' . 'cpp|cxx|c|cc|h|hpp|hxx|tcc|' . 'py|rb|hs|pl|pm|tw|' . 'php|phpt|css|js|' . 'java|' . 'thrift|' . 'lua|' . 'siv|' . 'txt' . ')$/'; if (preg_match($text_extensions, $path)) { $is_text = true; } if ($is_text) { $nolint_linter->addPath($path); $generated_linter->addPath($path); $generated_linter->addData($path, $this->loadData($path)); if (preg_match('/\\.java$/', $path)) { $java_text_linter->addPath($path); $java_text_linter->addData($path, $this->loadData($path)); } else { $text_linter->addPath($path); $text_linter->addData($path, $this->loadData($path)); } $spelling_linter->addPath($path); $spelling_linter->addData($path, $this->loadData($path)); } if (isset($cpp_linter) && isset($cpp_linter2) && preg_match('/\\.(cpp|c|cc|cxx|h|hh|hpp|hxx|tcc)$/', $path)) { $cpp_linter->addPath($path); $cpp_linter->addData($path, $this->loadData($path)); $cpp_linter2->addPath($path); $cpp_linter2->addData($path, $this->loadData($path)); } // Match *.py and contbuild config files if (preg_match('/(\\.(py|tw|smcprops)|^contbuild\\/configs\\/[^\\/]*)$/', $path)) { $space_count = 4; $real_path = $this->getFilePathOnDisk($path); $dir = dirname($real_path); do { if (file_exists($dir . '/.python2space')) { $space_count = 2; break; } $dir = dirname($dir); } while ($dir != '/' && $dir != '.'); if ($space_count == 4) { $cur_path_linter = $python_linter; } else { $cur_path_linter = $python_2space_linter; } $cur_path_linter->addPath($path); $cur_path_linter->addData($path, $this->loadData($path)); if (preg_match('/\\.tw$/', $path)) { $cur_path_linter->setCustomSeverityMap(array('E251' => ArcanistLintSeverity::SEVERITY_DISABLED)); } } } $name_linter = new ArcanistFilenameLinter(); $linters[] = $name_linter; foreach ($paths as $path) { $name_linter->addPath($path); } return $linters; }