1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix issue ideas

This commit is contained in:
Matt Brown 2018-01-05 13:22:48 -05:00 committed by Matthew Brown
parent 93fcaf38ef
commit 53d8c7ba52
2 changed files with 39 additions and 4 deletions

View File

@ -254,6 +254,11 @@ class ProjectChecker
*/ */
private $replace_code = false; private $replace_code = false;
/**
* @var bool
*/
private $fix_code = false;
const TYPE_CONSOLE = 'console'; const TYPE_CONSOLE = 'console';
const TYPE_JSON = 'json'; const TYPE_JSON = 'json';
const TYPE_EMACS = 'emacs'; const TYPE_EMACS = 'emacs';
@ -1002,7 +1007,15 @@ class ProjectChecker
} }
} }
if ($this->update_docblocks || $this->replace_code) { if ($this->replace_code) {
foreach ($this->files_to_report as $file_path) {
$this->updateFile($file_path, true);
}
} elseif ($this->update_docblocks) {
foreach ($this->files_to_report as $file_path) {
$this->updateFile($file_path, true);
}
} elseif ($this->fix_code) {
foreach ($this->files_to_report as $file_path) { foreach ($this->files_to_report as $file_path) {
$this->updateFile($file_path, true); $this->updateFile($file_path, true);
} }
@ -2082,4 +2095,12 @@ class ProjectChecker
{ {
$this->replace_code = true; $this->replace_code = true;
} }
/**
* @return void
*/
public function fixCodeAfterCompletion()
{
$this->fix_code = true;
}
} }

View File

@ -14,9 +14,10 @@ $options = getopt(
'f:mhvc:ir:', 'f:mhvc:ir:',
[ [
'help', 'debug', 'config:', 'monochrome', 'show-info:', 'diff', 'help', 'debug', 'config:', 'monochrome', 'show-info:', 'diff',
'file:', 'self-check', 'update-docblocks', 'output-format:', 'file:', 'self-check', 'add-docblocks', 'output-format:',
'find-dead-code', 'init', 'find-references-to:', 'root:', 'threads:', 'find-dead-code', 'init', 'find-references-to:', 'root:', 'threads:',
'report:', 'clear-cache', 'no-cache', 'version', 'plugin:', 'replace-code', 'report:', 'clear-cache', 'no-cache', 'version', 'plugin:', 'replace-code',
'fix-code',
] ]
); );
@ -81,8 +82,8 @@ Options:
--self-check --self-check
Psalm checks itself Psalm checks itself
--update-docblocks --add-docblocks
Adds correct return types to the given file(s) Adds correct docblock return types to the given file(s)
--output-format=console --output-format=console
Changes the output format. Possible values: console, json, xml Changes the output format. Possible values: console, json, xml
@ -113,6 +114,9 @@ Options:
--replace-code --replace-code
Processes any plugin code replacements and updates the code accordingly Processes any plugin code replacements and updates the code accordingly
--fix-issues=IssueType1,IssueType2
If any issues that can be fixed automatically, Psalm will update the codebase
HELP; HELP;
exit; exit;
@ -418,6 +422,16 @@ if (isset($options['replace-code'])) {
$project_checker->replaceCodeAfterCompletion(); $project_checker->replaceCodeAfterCompletion();
} }
if (isset($options['fix-issues'])) {
if (!is_string($options['fix-issues']) || !$options['fix-issues']) {
die('Expecting a comma-separated string of issues' . PHP_EOL);
}
$issues = explode(',', $options['fix-issues']);
$project_checker->fixIssuesAfterCompletion($issues);
}
/** @psalm-suppress MixedArgument */ /** @psalm-suppress MixedArgument */
\Psalm\IssueBuffer::setStartTime(microtime(true)); \Psalm\IssueBuffer::setStartTime(microtime(true));