Skip to content

Clean up unused imports removes imports used by attributes #3

@jackolas-lock

Description

@jackolas-lock

The VSCode extension that uses this package has been invaluable to me. I particularly like the feature that automatically removes unused packages. However, I've discovered it will remove imports used by attributes.

Steps to reproduce:

  1. Add an attribute to a class or function which requires an import
  2. Run the package with php-imports.unused.enable set to true
  3. The import used by the attribute is removed.

Example:

<?php

namespace App\Http\Controllers;

use App\Http\Resources\CareerResource;
use App\Models\Career;
use Illuminate\Http\Request;
use Vyuldashev\LaravelOpenApi\Attributes as OpenApi;

#[OpenApi\PathItem] // This attribute uses the OpenApi import above.
class CareerController extends Controller
{
    /**
     * Display a listing of the resource.
     */
     #[OpenApi\Operation] // This attribute also uses the OpenApi import above.
    public function index()
    {
        return Career->get();
    }
}

In this example, the use Vyuldashev\LaravelOpenApi\Attributes as OpenApi; is removed, even though it is necessary by those attributes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions