Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistLintWorkflow.php
| Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | return array( | ||||
| 'param' => 'format', | 'param' => 'format', | ||||
| 'help' => pht( | 'help' => pht( | ||||
| "With 'summary', show lint warnings in a more compact format. ". | "With 'summary', show lint warnings in a more compact format. ". | ||||
| "With 'json', show lint warnings in machine-readable JSON format. ". | "With 'json', show lint warnings in machine-readable JSON format. ". | ||||
| "With 'none', show no lint warnings. ". | "With 'none', show no lint warnings. ". | ||||
| "With 'compiler', show lint warnings in suitable for your editor. ". | "With 'compiler', show lint warnings in suitable for your editor. ". | ||||
| "With 'xml', show lint warnings in the Checkstyle XML format."), | "With 'xml', show lint warnings in the Checkstyle XML format."), | ||||
| ), | ), | ||||
| 'outfile' => array( | |||||
| 'param' => 'path', | |||||
| 'help' => pht( | |||||
| 'Output the linter results to a file. Defaults to stdout.'), | |||||
| ), | |||||
| 'only-new' => array( | 'only-new' => array( | ||||
| 'param' => 'bool', | 'param' => 'bool', | ||||
| 'supports' => array('git', 'hg'), // TODO: svn | 'supports' => array('git', 'hg'), // TODO: svn | ||||
| 'help' => pht( | 'help' => pht( | ||||
| 'Display only messages not present in the original code.'), | 'Display only messages not present in the original code.'), | ||||
| ), | ), | ||||
| 'engine' => array( | 'engine' => array( | ||||
| 'param' => 'classname', | 'param' => 'classname', | ||||
| ▲ Show 20 Lines • Show All 351 Lines • ▼ Show 20 Lines | switch ($this->getArgument('output')) { | ||||
| break; | break; | ||||
| default: | default: | ||||
| $renderer = new ArcanistConsoleLintRenderer(); | $renderer = new ArcanistConsoleLintRenderer(); | ||||
| $renderer->setShowAutofixPatches($prompt_autofix_patches); | $renderer->setShowAutofixPatches($prompt_autofix_patches); | ||||
| break; | break; | ||||
| } | } | ||||
| $all_autofix = true; | $all_autofix = true; | ||||
| $console->writeOut('%s', $renderer->renderPreamble()); | $tmp = null; | ||||
| if ($this->getArgument('outfile') !== null) { | |||||
| $tmp = id(new TempFile()) | |||||
| ->setPreserveFile(true); | |||||
| } | |||||
| $preamble = $renderer->renderPreamble(); | |||||
| if ($tmp) { | |||||
| Filesystem::appendFile($tmp, $preamble); | |||||
| } else { | |||||
| $console->writeOut('%s', $preamble); | |||||
| } | |||||
| foreach ($results as $result) { | foreach ($results as $result) { | ||||
| $result_all_autofix = $result->isAllAutofix(); | $result_all_autofix = $result->isAllAutofix(); | ||||
| if (!$result->getMessages() && !$result_all_autofix) { | if (!$result->getMessages() && !$result_all_autofix) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (!$result_all_autofix) { | if (!$result_all_autofix) { | ||||
| $all_autofix = false; | $all_autofix = false; | ||||
| } | } | ||||
| $lint_result = $renderer->renderLintResult($result); | $lint_result = $renderer->renderLintResult($result); | ||||
| if ($lint_result) { | if ($lint_result) { | ||||
| if ($tmp) { | |||||
| Filesystem::appendFile($tmp, $lint_result); | |||||
| } else { | |||||
| $console->writeOut('%s', $lint_result); | $console->writeOut('%s', $lint_result); | ||||
| } | } | ||||
| } | |||||
| if ($apply_patches && $result->isPatchable()) { | if ($apply_patches && $result->isPatchable()) { | ||||
| $patcher = ArcanistLintPatcher::newFromArcanistLintResult($result); | $patcher = ArcanistLintPatcher::newFromArcanistLintResult($result); | ||||
| $old_file = $result->getFilePathOnDisk(); | $old_file = $result->getFilePathOnDisk(); | ||||
| if ($prompt_patches && | if ($prompt_patches && | ||||
| !($result_all_autofix && !$prompt_autofix_patches)) { | !($result_all_autofix && !$prompt_autofix_patches)) { | ||||
| if (!Filesystem::pathExists($old_file)) { | if (!Filesystem::pathExists($old_file)) { | ||||
| Show All 19 Lines | foreach ($results as $result) { | ||||
| } | } | ||||
| $patcher->writePatchToDisk(); | $patcher->writePatchToDisk(); | ||||
| $wrote_to_disk = true; | $wrote_to_disk = true; | ||||
| $file_hashes[$old_file] = md5_file($old_file); | $file_hashes[$old_file] = md5_file($old_file); | ||||
| } | } | ||||
| } | } | ||||
| $console->writeOut('%s', $renderer->renderPostamble()); | $postamble = $renderer->renderPostamble(); | ||||
| if ($tmp) { | |||||
| Filesystem::appendFile($tmp, $postamble); | |||||
| Filesystem::rename($tmp, $this->getArgument('outfile')); | |||||
| } else { | |||||
| $console->writeOut('%s', $postamble); | |||||
| } | |||||
| if ($wrote_to_disk && $this->shouldAmendChanges) { | if ($wrote_to_disk && $this->shouldAmendChanges) { | ||||
| if ($this->shouldAmendWithoutPrompt || | if ($this->shouldAmendWithoutPrompt || | ||||
| ($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) { | ($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) { | ||||
| $console->writeOut( | $console->writeOut( | ||||
| "<bg:yellow>** %s **</bg> %s\n", | "<bg:yellow>** %s **</bg> %s\n", | ||||
| pht('LINT NOTICE'), | pht('LINT NOTICE'), | ||||
| pht('Automatically amending HEAD with lint patches.')); | pht('Automatically amending HEAD with lint patches.')); | ||||
| ▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines | |||||