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

Allow suppressing a psalm issue for a single Attribute or parameter #10894

Open
annervisser opened this issue Apr 10, 2024 · 1 comment
Open

Comments

@annervisser
Copy link
Contributor

When using attributes on a class, there is no way to ignore an issue for just one attribute.
Currently, the only option is to ignore the error type for the WHOLE class.

  • A way to ignore an issue for a single attribute would solve this particular issue.
  • A way to ignore an issue for just a specific parameter would allow more fine-grained suppressing for this case but also any suppresses on functions and methods.

As far as I can tell this is also not possible using the config issueHandlers, since InvalidArgument wants a referencedFunction. I haven't been able to get that to work for an Attribute

https://psalm.dev/r/312d1075f3

Copy link

I found these snippets:

https://psalm.dev/r/312d1075f3
<?php

#[Attribute(Attribute::TARGET_CLASS)]
final class Attribute1 {
    public function __construct(string $input) {}
}

#[Attribute(Attribute::TARGET_CLASS)]
final class Attribute2 {
    public function __construct(string $input) {}
}

// The InvalidArgument on Attribute1 should not be suppressed:
#[Attribute1(false)]
// I want to suppress the argument on Attribute2:
#[Attribute2(false)]
class Example {
	public function method1(string $input): array {
        // This InvalidArgument should not be suppressed:
        return array_values($input);
    }
}
Psalm output (using commit ef3b018):

ERROR: InvalidArgument - 14:14 - Argument 1 of Attribute1::__construct cannot be false, string value expected

ERROR: InvalidArgument - 16:14 - Argument 1 of Attribute2::__construct cannot be false, string value expected

ERROR: InvalidArgument - 20:29 - Argument 1 of array_values expects array<array-key, mixed>, but string provided

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

No branches or pull requests

1 participant