Closed superbiche closed 10 months ago
Thanks @superbiche
We might need to add another visitor to clean these up:
public function leaveNode(Node $node)
{
if ($node instanceof Node\Stmt\Use_) {
foreach ($node->uses as $use) {
if ($use->name->toString() === $this->className) {
// The class has already been imported
return NodeTraverser::REMOVE_NODE;
}
}
}
}
ArrayParametersOverViewWith
has an example of how we might create a new visitor with the leaveNode
method.
Hi,
When a file
use
s theEloquent
facade andIlluminate\Database\Eloquent\Model
, theFullyQualifiedFacades
formatter fixes theEloquent
facade import by importingIlluminate\Database\Eloquent\Model
another time, resulting in a duplicateuse
statement.Example:
Before fix:
Run
./vendor/bin/duster fix --using=tlint
After fix:
I don't know if subsequent tools will fix this, but I suppose it's better if Tlint doesn't create invalid PHP code when formatting.
Maybe just checking if a FQN import of the same class exists in the file would be enough.
Let me know if you want me to give a short at a PR handling this.
Cheers and thanks for your work on this project and Duster <3