vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.55k stars 660 forks source link

Feature Request: Psalm code altering for `UnusedPsalmSuppress` #8206

Open boesing opened 2 years ago

boesing commented 2 years ago

I was recently wondering why there is no UnusedPsalmSuppress issue fixer available.

Did anyone ever tried to implement that and stopped working on it due to its complexity? If not, I'd love to work on that. If so, please let me know 👍🏼

Thanks in advance.

psalm-github-bot[bot] commented 2 years ago

Hey @boesing, can you reproduce the issue on https://psalm.dev ?

orklah commented 2 years ago

From what I see, it should be possible.

UnusedPsalmSuppress are handled in there:https://github.com/vimeo/psalm/blob/b4fdc3e326fea865de49827f723a2703bb18617a/src/Psalm/Internal/Codebase/Analyzer.php#L315

The method seem to know the starting position, the end position of the docblock so it should be enough to add a FileReplacement to the buffer

AndrolGenhald commented 2 years ago

Ninja'd again :laughing:

The method seem to know the starting position, the end position of the docblock so it should be enough to add a FileReplacement to the buffer

/s/FileReplacement/FileManipulation/

But yeah, I don't think it should be too hard, though I haven't done much with the fixer stuff so I wouldn't know too well.

boesing commented 2 years ago

Hm, usually, psalm-suppress is used like this:

/** @psalm-suppress WhateverIssueToBeSuppressed Lorem ipsum dolor met */

If we now manipulate the file, it might end-up in this:

/** */

Should this be handled by the psalter as well (so that we drop it)?

orklah commented 2 years ago

Yeah, ideally, we should be able to detect the docblock is now empty and remove it. Beware, the docblock could have comments unrelated to the suppression