leek / rector-filament
Rector rules for Filament v4 upgrades and code quality.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:rector-extension
pkg:composer/leek/rector-filament
Requires
- php: ^8.2
- rector/rector: ^2.0
Requires (Dev)
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2026-02-05 05:14:46 UTC
README
Rector rules for Filament v4 upgrades and code quality.
Install
composer require --dev leek/rector-filament
Usage
Option A: Set Provider (auto-detect Filament version)
use RectorFilament\Set\FilamentSetProvider; return RectorConfig::configure() ->withSetProviders(FilamentSetProvider::class) ->withComposerBased();
Option B: Explicit sets
use RectorFilament\Set\FilamentSetList; return RectorConfig::configure() ->withSets([ FilamentSetList::FILAMENT_40, FilamentSetList::FILAMENT_CODE_QUALITY, ]);
Available Sets
| Set | Constant | Description |
|---|---|---|
| Filament v4 | FilamentSetList::FILAMENT_40 |
Rules for upgrading to Filament v4 |
| Code Quality | FilamentSetList::FILAMENT_CODE_QUALITY |
Convention and bug-prevention rules |
Rules
Filament v4 (FILAMENT_40)
Namespace Changes
ActionsNamespaceRector
Updates action imports from Tables, Notifications, and Forms namespaces to Filament\Actions\*.
-use Filament\Tables\Actions\EditAction; -use Filament\Notifications\Actions\Action; -use Filament\Forms\Actions\Action; +use Filament\Actions\EditAction; +use Filament\Actions\Action; +use Filament\Actions\Action;
GetSetNamespaceRector
Updates Get and Set utility imports from Filament\Forms\* to Filament\Schemas\Components\Utilities\*.
-use Filament\Forms\Get; -use Filament\Forms\Set; +use Filament\Schemas\Components\Utilities\Get; +use Filament\Schemas\Components\Utilities\Set;
SchemaComponentsNamespaceRector
Updates layout component imports from Filament\Forms\Components\* to Filament\Schemas\Components\*.
-use Filament\Forms\Components\Fieldset; -use Filament\Forms\Components\Grid; -use Filament\Forms\Components\Section; -use Filament\Forms\Components\Split; -use Filament\Forms\Components\Tabs; -use Filament\Forms\Components\Wizard; +use Filament\Schemas\Components\Fieldset; +use Filament\Schemas\Components\Grid; +use Filament\Schemas\Components\Section; +use Filament\Schemas\Components\Split; +use Filament\Schemas\Components\Tabs; +use Filament\Schemas\Components\Wizard;
Method Renames
ActionFormToSchemaRector
Renames ->form() to ->schema() on Action, BulkAction, and Filter classes.
Action::make('export')
- ->form([
+ ->schema([
TextInput::make('name'),
])
->action(fn () => null);
TableActionsToRecordActionsRector
Renames ->actions() to ->recordActions() on Table.
$table - ->actions([ + ->recordActions([ EditAction::make(), ]);
BulkActionsToToolbarActionsRector
Transforms ->bulkActions([...]) to ->toolbarActions([BulkActionGroup::make([...])]) on Table.
$table - ->bulkActions([ - DeleteBulkAction::make(), - ]); + ->toolbarActions([ + BulkActionGroup::make([ + DeleteBulkAction::make(), + ]), + ]);
FiltersLayoutArgToMethodRector
Extracts the second argument of ->filters() into a chained ->filtersLayout() call.
$table - ->filters([ - Filter::make('active'), - ], layout: FiltersLayout::AboveContent); + ->filters([ + Filter::make('active'), + ]) + ->filtersLayout(FiltersLayout::AboveContent);
Closure Parameter Renames
ModelToRecordClosureParamRector
Renames $model to $record in Filament closure parameters.
Action::make('view')
- ->visible(function ($model) {
- return $model->is_active;
+ ->visible(function ($record) {
+ return $record->is_active;
});
LivewireComponentParamNameRector
Renames Livewire\Component type-hinted parameters to $livewire in Filament closures.
TextInput::make('name')
- ->visible(function (Component $component) {
- return $component->getData();
+ ->visible(function (Component $livewire) {
+ return $livewire->getData();
});
Code Quality (FILAMENT_CODE_QUALITY)
NullableAfterStateUpdatedStateRector
Makes $state parameter nullable in afterStateUpdated callbacks to prevent type errors when fields are cleared.
TextInput::make('name')
- ->afterStateUpdated(function (string $state) {
+ ->afterStateUpdated(function (?string $state) {
// ...
});
ModifyQueryUsingBuilderToQueryRector
Renames $builder to $query in modifyQueryUsing callbacks to follow Filament convention.
-->modifyQueryUsing(fn (Builder $builder) => $builder->where('active', true)) +->modifyQueryUsing(fn (Builder $query) => $query->where('active', true))
FilamentUtilityInjectionTypeRector
Adds proper type hints for Filament utility injection parameters ($get, $set, $record, $operation, $component, $livewire) in closures.
TextInput::make('name')
- ->visible(function ($get, $record) {
+ ->visible(function (Get $get, ?Model $record) {
return $get('type') === 'business';
});
License
MIT