pixee / codemodder-python

Python implementation of the Codemodder framework
GNU Affero General Public License v3.0
38 stars 10 forks source link

`harden-pyyaml` codemod adds import that already exists #517

Closed drdavella closed 7 months ago

drdavella commented 7 months ago

In this example, the harden-pyyaml codemod adds import yaml even though it already exists. I'm not sure whether this is a bug with LibCST, with this codemod specifically, or with Codemodder more generally, so it bears some additional investigation:

https://github.com/unitedstates/congress-legislators/pull/922/files

andrecsilva commented 7 months ago

This is happening because the default behavior of libcst's add import visitor will always try to the add the import at the top of the file if it is not there, regardless if the import appears in any other line.

So this will always be an issue. However, I think I can mitigate this issue for this particular case.