diff --git a/docs/README.md b/docs/README.md index 15e2ec264..2d7171d4f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,7 +19,7 @@ Psalm also has a few features to make it perform as well as possible on large co Wherever possible Psalm will run its analysis in parallel to save time. Useful for large codebases, it has a massive impact on performance. - **Incremental checks**
- When using the `--diff` command line option, Psalm will only analyse files that have changed *and* files that reference them. + By default Psalm only analyses files that have changed and files that reference those changed files. ## Example output diff --git a/docs/running_psalm/command_line_usage.md b/docs/running_psalm/command_line_usage.md index d5492fc60..e2f97a4e6 100644 --- a/docs/running_psalm/command_line_usage.md +++ b/docs/running_psalm/command_line_usage.md @@ -30,10 +30,11 @@ Psalm has a couple of command-line options that will result in faster builds: - `--threads=[n]` to run Psalm’s analysis in a number of threads - `--diff` which only checks files you’ve updated since the last run (and their dependents). -- `--diff-methods` which only checks methods you’ve updated since the last run (and their dependents). + +In Psalm 4 `--diff` is turned on by default (you can disable it with `--no-diff`). Data from the last run is stored in the *cache directory*, which may be set in [configuration](./configuration.md). If you are running Psalm on a build server, you may want to configure the server to ensure that the cache directory is preserved between runs. -Running them together (e.g. `--threads=8 --diff --diff-methods`) will result in the fastest possible Psalm run. +Running them together (e.g. `--threads=8 --diff`) will result in the fastest possible Psalm run. diff --git a/docs/running_psalm/installation.md b/docs/running_psalm/installation.md index 801bcd8d2..da19f34b2 100644 --- a/docs/running_psalm/installation.md +++ b/docs/running_psalm/installation.md @@ -1,6 +1,6 @@ # Installation -The latest version of Psalm requires PHP >= 7.1 and [Composer](https://getcomposer.org/). +The latest version of Psalm requires PHP >= 7.3 and [Composer](https://getcomposer.org/). ```bash composer require --dev vimeo/psalm diff --git a/src/command_functions.php b/src/command_functions.php index ded3087aa..01fa3892a 100644 --- a/src/command_functions.php +++ b/src/command_functions.php @@ -317,8 +317,8 @@ Basic configuration: --threads=INT If greater than one, Psalm will run analysis on multiple threads, speeding things up. - --diff - Runs Psalm in diff mode, only checking files that have changed since last run (and their dependents) + --no-diff + Turns off Psalm’s diff mode, checks all files regardless of whether they've changed --diff-methods Only checks methods that have changed since last run (and their dependents) diff --git a/src/psalm.php b/src/psalm.php index 88c16014d..7e066b14f 100644 --- a/src/psalm.php +++ b/src/psalm.php @@ -83,7 +83,6 @@ $valid_long_options = [ 'debug-performance', 'debug-emitted-issues', 'diff', - 'diff-methods', 'disable-extension:', 'find-dead-code::', 'find-unused-code::', @@ -94,6 +93,7 @@ $valid_long_options = [ 'init', 'memory-limit:', 'monochrome', + 'no-diff', 'no-cache', 'no-reflection-cache', 'no-file-cache', @@ -483,7 +483,9 @@ $show_info = isset($options['show-info']) ? $options['show-info'] === 'true' || $options['show-info'] === '1' : false; -$is_diff = isset($options['diff']); +$is_diff = !isset($options['no-diff']) + && !isset($options['set-baseline']) + && !isset($options['update-baseline']); /** @var false|'always'|'auto' $find_unused_code */ $find_unused_code = false; @@ -680,67 +682,59 @@ if ($find_references_to) { } if (isset($options['set-baseline']) && is_string($options['set-baseline'])) { - if ($is_diff) { - fwrite(STDERR, 'Cannot set baseline in --diff mode' . PHP_EOL); - } else { - fwrite(STDERR, 'Writing error baseline to file...' . PHP_EOL); + fwrite(STDERR, 'Writing error baseline to file...' . PHP_EOL); - ErrorBaseline::create( - new \Psalm\Internal\Provider\FileProvider, - $options['set-baseline'], - IssueBuffer::getIssuesData(), - $config->include_php_versions_in_error_baseline || isset($options['include-php-versions']) - ); + ErrorBaseline::create( + new \Psalm\Internal\Provider\FileProvider, + $options['set-baseline'], + IssueBuffer::getIssuesData(), + $config->include_php_versions_in_error_baseline || isset($options['include-php-versions']) + ); - fwrite(STDERR, "Baseline saved to {$options['set-baseline']}."); + fwrite(STDERR, "Baseline saved to {$options['set-baseline']}."); - update_config_file( - $config, - $path_to_config ?? $current_dir, - $options['set-baseline'] - ); + update_config_file( + $config, + $path_to_config ?? $current_dir, + $options['set-baseline'] + ); - fwrite(STDERR, PHP_EOL); - } + fwrite(STDERR, PHP_EOL); } $issue_baseline = []; if (isset($options['update-baseline'])) { - if ($is_diff) { - fwrite(STDERR, 'Cannot update baseline in --diff mode' . PHP_EOL); - } else { - $baselineFile = Config::getInstance()->error_baseline; + $baselineFile = Config::getInstance()->error_baseline; - if (empty($baselineFile)) { - die('Cannot update baseline, because no baseline file is configured.' . PHP_EOL); - } - - try { - $issue_current_baseline = ErrorBaseline::read( - new \Psalm\Internal\Provider\FileProvider, - $baselineFile - ); - $total_issues_current_baseline = ErrorBaseline::countTotalIssues($issue_current_baseline); - - $issue_baseline = ErrorBaseline::update( - new \Psalm\Internal\Provider\FileProvider, - $baselineFile, - IssueBuffer::getIssuesData(), - $config->include_php_versions_in_error_baseline || isset($options['include-php-versions']) - ); - $total_issues_updated_baseline = ErrorBaseline::countTotalIssues($issue_baseline); - - $total_fixed_issues = $total_issues_current_baseline - $total_issues_updated_baseline; - - if ($total_fixed_issues > 0) { - echo str_repeat('-', 30) . "\n"; - echo $total_fixed_issues . ' errors fixed' . "\n"; - } - } catch (\Psalm\Exception\ConfigException $exception) { - fwrite(STDERR, 'Could not update baseline file: ' . $exception->getMessage() . PHP_EOL); - exit(1); + if (empty($baselineFile)) { + die('Cannot update baseline, because no baseline file is configured.' . PHP_EOL); + } + + try { + $issue_current_baseline = ErrorBaseline::read( + new \Psalm\Internal\Provider\FileProvider, + $baselineFile + ); + $total_issues_current_baseline = ErrorBaseline::countTotalIssues($issue_current_baseline); + + $issue_baseline = ErrorBaseline::update( + new \Psalm\Internal\Provider\FileProvider, + $baselineFile, + IssueBuffer::getIssuesData(), + $config->include_php_versions_in_error_baseline || isset($options['include-php-versions']) + ); + $total_issues_updated_baseline = ErrorBaseline::countTotalIssues($issue_baseline); + + $total_fixed_issues = $total_issues_current_baseline - $total_issues_updated_baseline; + + if ($total_fixed_issues > 0) { + echo str_repeat('-', 30) . "\n"; + echo $total_fixed_issues . ' errors fixed' . "\n"; } + } catch (\Psalm\Exception\ConfigException $exception) { + fwrite(STDERR, 'Could not update baseline file: ' . $exception->getMessage() . PHP_EOL); + exit(1); } }