Repository: tighten/tlint (php)

Issue:
PHP 8 Attributes are recognized as unused import
Given the following file:
```php
<?php

namespace App\Utility\Game\DTO;

use Spatie\DataTransferObject\Attributes\Strict;
use Spatie\DataTransferObject\DataTransferObject;

#[Strict]
class UnitDTO extends DataTransferObject
{
    /** @var string[] */
    public array $possible_orders;
    public string $space;
}
```

I'm getting the following error:
```
Lints for /home/alexw/Code/dnw/zenvoy/app/Utility/Game/DTO/UnitDTO.php
============
! There should be no unused imports.
5 : `use Spatie\DataTransferObject\Attributes\Strict;`
```

I would expect tlint to recognize imports. I will try to provide a fix for this. 

Pull request:
No unused import attribute fix
Currently if an attribute is defined and imported the NoUnusedImports-Rule detects an error. This PR fixes #242.

Patch:
diff --git a/src/Concerns/IdentifiesImports.php b/src/Concerns/IdentifiesImports.php
index 726efcf..bc64806 100644
--- a/src/Concerns/IdentifiesImports.php
+++ b/src/Concerns/IdentifiesImports.php
@@ -36,6 +36,14 @@ trait IdentifiesImports
                 }
             }
 
+            if (property_exists($node, 'attrGroups')){
+                foreach ($node->attrGroups as $group){
+                    foreach ($group->attrs as $attribute){
+                        $used[] = $attribute->name->toString();
+                    }
+                }
+            }
+
             if ($node instanceof Node\Stmt\UseUse) {
                 if (! in_array($node->name->toString(), $groupUseStatements)) {
                     $useStatements[] = $node;
diff --git a/src/TLint.php b/src/TLint.php
index 4349345..ae032aa 100644
--- a/src/TLint.php
+++ b/src/TLint.php
@@ -12,7 +12,7 @@ class TLint
 
     public function __construct()
     {
-        $this->parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, new Lexer);
+        $this->parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
     }
 
     public function lint(BaseLinter $linter)


Test patch:
diff --git a/tests/Linting/Linters/NoUnusedImportsTest.php b/tests/Linting/Linters/NoUnusedImportsTest.php
index b0382da..4e2caad 100644
--- a/tests/Linting/Linters/NoUnusedImportsTest.php
+++ b/tests/Linting/Linters/NoUnusedImportsTest.php
@@ -606,4 +606,37 @@ file;
 
         $this->assertEmpty((new TLint)->lint(new NoUnusedImports($file)));
     }
+
+    /** @test */
+    function does_not_trigger_when_import_uses_attribute()
+    {
+        $file = <<<'file'
+<?php
+
+use We\Are\Strict;
+use Attribute\On\Property\One;
+use Attribute\On\Property\Two;
+use Attribute\On\Property\Three;
+use Atrribute\On\Method;
+
+#[Strict]
+class Test
+{
+    #[One,Two]
+    public string $foo;
+    #[Three]
+    public string $bar;
+    
+    #[Method]
+    public function doIt(): void {
+    
+    }
 }
+file;
+
+        $this->assertEmpty((new TLint)->lint(new NoUnusedImports($file)));
+    }
+
+
+}
+