Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psalm errorBaseline config not respected when given paths #10624

Closed
gready-hub opened this issue Jan 31, 2024 · 4 comments · Fixed by #10628
Closed

Psalm errorBaseline config not respected when given paths #10624

gready-hub opened this issue Jan 31, 2024 · 4 comments · Fixed by #10628
Labels

Comments

@gready-hub
Copy link

Hi there. I've found this to break how the error baseline is used. Due to the removal of the trailing / from the config path Psalm does not locate the files from the error baseline due too this one missing character.

Either the generate baseline needs to add the prefix or we need to remove the prefix / when checking if the path is in the $issues_baseline map.

From src/Psalm/Internal/Cli/Psalm.php

        if ($paths_to_check !== null) {
            $filtered_issue_baseline = [];
            foreach ($paths_to_check as $path_to_check) {
                // These two lines below are the problem... 
                $path_to_check = substr($path_to_check, strlen($config->base_dir));
                if (isset($issue_baseline[$path_to_check])) {
                    $filtered_issue_baseline[$path_to_check] = $issue_baseline[$path_to_check];
                }
            }
            $issue_baseline = $filtered_issue_baseline;
        }

This resolves the issue I have been experiencing... Either increment by one or remove prefix / prior.

// ...
$path_to_check = substr($path_to_check, strlen($config->base_dir) + 1);
// ...

Originally posted by @gready-hub in #10542 (comment)

@gready-hub
Copy link
Author

gready-hub commented Jan 31, 2024

Sample of our psalm baseline and psalm config if that's needed but I think it's clear already.

Latest baseline:

<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.21.0@04ba9358e3f7d14a9dc3edd4e814a9d51d8c637f">
  <file src="admin-scripts/test-user/configure-test-users.php">
    <InvalidCast>
      <code>$currencyId</code>
      <code>$field</code>
      <code>$field</code>
      <code>$field</code>
      <code>$key</code>

Previous baseline (no change):

<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.19.0@06b71be009a6bd6d81b9811855d6629b9fe90e1b">
  <file src="admin-scripts/test-user/configure-test-users.php">
    <InvalidCast>
      <code>$currencyId</code>
      <code>$field</code>
      <code>$field</code>
      <code>$field</code>
      <code>$key</code>
<?xml version="1.0"?>

<psalm
    autoloader="public/lib/common.php"
    errorBaseline="psalm-baseline.xml"
    errorLevel="1"
    findUnusedBaselineEntry="false"
    findUnusedCode="true"
    phpVersion="8.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="https://getpsalm.org/schema/config"
    xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
    <plugins>
        <pluginClass class="Psalm\FreelancerPsalmPlugin\Plugin"/>
        <pluginClass class="Psalm\MockeryPlugin\Plugin"/>
        <pluginClass class="CuyZ\Valinor\QA\Psalm\ValinorPsalmPlugin"/>
    </plugins>

    <projectFiles>
        <!-- Included paths... everything! -->
        <directory name="."/>

        <ignoreFiles allowMissingFiles="true">
            <!-- External -->
            <directory name="vendor"/>

@gready-hub gready-hub reopened this Jan 31, 2024
@gready-hub gready-hub changed the title Psalm errorBaseline config not respected Psalm errorBaseline config not respected when given paths Jan 31, 2024
@weirdan
Copy link
Collaborator

weirdan commented Jan 31, 2024

To clarify:

$path_to_check = '/a/b/c.php';
$config->base_dir = '/a/b';
$baseline_path = 'c.php'; // but checked against /c.php

Is that the correct problem description?

@weirdan weirdan added the bug label Jan 31, 2024
@gready-hub
Copy link
Author

gready-hub commented Feb 1, 2024

Looks correct to me.

FYI I'm running a composer patch successfully with a similar fix from the issue summary with 5.21.0, works when specifying file paths & without.

@gready-hub
Copy link
Author

tyvm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants