laravel / pint

Laravel Pint is an opinionated PHP code style fixer for minimalists.
https://laravel.com/docs/pint
MIT License
2.75k stars 138 forks source link

What if `pint` could correct array type hints in the docblocks #276

Closed adrianb93 closed 3 months ago

adrianb93 commented 3 months ago

Feature suggestion ✌️

What if pint could correct array type hints in the docblocks.

I only recently discovered that instead of doing this:

/** @var array<class-string> */
public array $events;

// or this

/** @var array<int, class-string> */
public array $events;

That I should do this:

/** @var list<class-string> */
public array $events;

Examples

Where the rule should apply:

# Before
/** @var array<class-string> */
public array $events;

# After
/** @var list<class-string> */
public array $events;

Caveat where the rule shouldn't apply:

I don't think we should assume this is a list just because the key is an integer.

# Before
/** @var array<int, class-string> */
public array $events;

# After
/** @var array<int, class-string> */
public array $events;

I don't think no specificity should mean it's a list:

# Before
/** @var array */
public array $events;

# After
/** @var array */
public array $events;
crynobone commented 3 months ago

Hi there,

Laravel preset prefers array over list and that has been the standard for now. You may be able to add custom rules to allow this if it's available via php-cs-fixer