* @group lint
*/
final class ArcanistLintRenderer {
+ private $showAutofixPatches = false;
+
+ public function setShowAutofixPatches($show_autofix_patches) {
+ $this->showAutofixPatches = $show_autofix_patches;
+ return $this;
+ }
+
public function renderLintResult(ArcanistLintResult $result) {
$messages = $result->getMessages();
$path = $result->getPath();
$lines = explode("\n", $result->getData());
$text = array();
- $text[] = phutil_console_format('**>>>** Lint for __%s__:', $path);
- $text[] = null;
+
foreach ($messages as $message) {
+ if (!$this->showAutofixPatches && $message->isAutofix()) {
+ continue;
+ }
+
if ($message->isError()) {
$color = 'red';
} else {
$text[] = $this->renderContext($message, $lines);
}
}
- $text[] = null;
- $text[] = null;
- return implode("\n", $text);
+ if ($text) {
+ $prefix = phutil_console_format("**>>>** Lint for __%s__:\n\n\n", $path);
+ return $prefix . implode("\n", $text);
+ } else {
+ return null;
+ }
}
protected function renderContext(
final class ArcanistLintSeverity {
const SEVERITY_ADVICE = 'advice';
+ const SEVERITY_AUTOFIX = 'autofix';
const SEVERITY_WARNING = 'warning';
const SEVERITY_ERROR = 'error';
const SEVERITY_DISABLED = 'disabled';
public static function getStringForSeverity($severity_code) {
static $map = array(
self::SEVERITY_ADVICE => 'Advice',
+ self::SEVERITY_AUTOFIX => 'Auto-Fix',
self::SEVERITY_WARNING => 'Warning',
self::SEVERITY_ERROR => 'Error',
self::SEVERITY_DISABLED => 'Disabled',
static $map = array(
self::SEVERITY_DISABLED => 10,
self::SEVERITY_ADVICE => 20,
+ self::SEVERITY_AUTOFIX => 25,
self::SEVERITY_WARNING => 30,
self::SEVERITY_ERROR => 40,
);
private $unresolvedMessages;
private $shouldAmendChanges = false;
+ private $shouldAmendWithoutPrompt = false;
+ private $shouldAmendAutofixesWithoutPrompt = false;
public function setShouldAmendChanges($should_amend) {
$this->shouldAmendChanges = $should_amend;
return $this;
}
+ public function setShouldAmendWithoutPrompt($should_amend) {
+ $this->shouldAmendWithoutPrompt = $should_amend;
+ return $this;
+ }
+
+ public function setShouldAmendAutofixesWithoutPrompt($should_amend) {
+ $this->shouldAmendAutofixesWithoutPrompt = $should_amend;
+ return $this;
+ }
+
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**lint** [__options__] [__paths__]
'apply-patches' => true,
),
),
+ 'amend-all' => array(
+ 'help' =>
+ 'When linting git repositories, amend HEAD with all patches '.
+ 'suggested by lint without prompting.',
+ ),
+ 'amend-autofixes' => array(
+ 'help' =>
+ 'When linting git repositories, amend HEAD with autofix '.
+ 'patches suggested by lint without prompting.',
+ ),
'*' => 'paths',
);
}
if ($this->getArgument('advice')) {
$engine->setMinimumSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
} else {
- $engine->setMinimumSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
+ $engine->setMinimumSeverity(ArcanistLintSeverity::SEVERITY_AUTOFIX);
}
// Propagate information about which lines changed to the lint engine.
$prompt_patches = true;
}
+ if ($this->getArgument('amend-all')) {
+ $this->shouldAmendChanges = true;
+ $this->shouldAmendWithoutPrompt = true;
+ }
+
+ if ($this->getArgument('amend-autofixes')) {
+ $prompt_autofix_patches = false;
+ $this->shouldAmendChanges = true;
+ $this->shouldAmendAutofixesWithoutPrompt = true;
+ } else {
+ $prompt_autofix_patches = true;
+ }
+
$wrote_to_disk = false;
switch ($this->getArgument('output')) {
break;
default:
$renderer = new ArcanistLintRenderer();
+ $renderer->setShowAutofixPatches($prompt_autofix_patches);
break;
}
+ $all_autofix = true;
+
foreach ($results as $result) {
- if (!$result->getMessages()) {
+ $result_all_autofix = $result->isAllAutofix();
+
+ if (!$result->getMessages() && !$result_all_autofix) {
continue;
}
- echo $renderer->renderLintResult($result);
+ if (!$result_all_autofix) {
+ $all_autofix = false;
+ }
+
+ $lint_result = $renderer->renderLintResult($result);
+ if ($lint_result) {
+ echo $lint_result;
+ }
if ($apply_patches && $result->isPatchable()) {
$patcher = ArcanistLintPatcher::newFromArcanistLintResult($result);
$old = $patcher->getUnmodifiedFileContent();
$new = $patcher->getModifiedFileContent();
- if ($prompt_patches) {
+ if ($prompt_patches &&
+ !($result_all_autofix && !$prompt_autofix_patches)) {
$old_file = $result->getFilePathOnDisk();
if (!Filesystem::pathExists($old_file)) {
$old_file = '/dev/null';
if ($wrote_to_disk &&
($repository_api instanceof ArcanistGitAPI) &&
$this->shouldAmendChanges) {
- $amend = phutil_console_confirm("Amend HEAD with lint patches?");
+
+ if ($this->shouldAmendWithoutPrompt ||
+ ($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) {
+ echo phutil_console_format(
+ "<bg:yellow>** LINT NOTICE **</bg> Automatically amending HEAD ".
+ "with lint patches.\n");
+ $amend = true;
+ } else {
+ $amend = phutil_console_confirm("Amend HEAD with lint patches?");
+ }
+
if ($amend) {
execx(
'(cd %s; git commit -a --amend -C HEAD)',