tighten/tlint-plugin

Logic for ImportFacades incorrect

Closed this issue · 3 comments

We have a Config Model in our Models folder that is called within another Model class, but tlint thinks it's an Alias because there is no import statement (as they are in the same folder).

So code should probably check if there is any import statement to begin with, as my guess is that it has a predefined facades list it checks agains, and then checks if the facade is imported.

@danijelk You are correct that this is how it is implemented (https://github.com/tightenco/tlint/blob/master/src/Linters/ImportFacades.php#L13)

Can you provider a minimal code example that reproduces this behavior that we can use as a test case?

Had a repo for a bug in phpunit that I reused, sorry for beeing lazy, but the test is valid enough
https://github.com/danijelk/phpunit_8_4_2_bug

 ./vendor/bin/tlint lint tests/FooTest.php

Lints for /Volumes/c/development/phpunit_8_4_2_bug/tests/FooTest.php
============
! Import facades (don't use aliases).
11 : `        $config = Config::where();`

Issue is that the logic on line 68 doesn't account for the Class in use to be just another random class in the project.

It could be solved by either checking the $useNames for a class that ends with {$node->class->toString()}, or to check if the $useNames is using the global provider "use $classname"