Search by

hihaho / rector-rules

hihaho

Hihaho Rector rules for auto-fixing code conventions

Package info

github.com/hihaho/rector-rules

Homepage

Documentation

Type:rector-extension

pkg:composer/hihaho/rector-rules

Statistics

Installs: 46 861

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 1

1.2.1 2026-11-09 19:10 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub PHPStan Action Status Total Downloads License

Laravel conventions slip in ways a linter can only report: a table string where a model class belongs, a relation referenced as a magic string. The comment lands in review, and the fix waits for someone to do it by hand. These Rector rules do the rewrite instead, enforcing the Hihaho Development Guidelines as an automated pass.

-$this->assertDatabaseHas('users', ['email' => $email]);
+$this->assertDatabaseHas(\App\Models\User::class, ['email' => $email]);

Installation

composer require hihaho/rector-rules --dev

Requires PHP ^8.3 and Rector ^2.6, and is tested against Laravel 12 and 13.

Usage

Enable the sets you want in rector.php:

use Hihaho\RectorRules\Set\HihahoSetList;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([__DIR__ . '/app', __DIR__ . '/database', __DIR__ . '/routes', __DIR__ . '/tests'])
    ->withSets([
        HihahoSetList::ALL, // or pick per set: CODE_QUALITY, ELOQUENT, NAMING, ROUTING, MIGRATIONS, IMPORTS, TESTING
    ]);

Then dry-run before you apply:

vendor/bin/rector process --dry-run

The routing rules only touch files under a routes/ directory and the migration rules only files under a migrations/ directory, so withPaths() has to reach them.

Documentation

Read the full documentation at hihaho.github.io/rector-rules.

Getting started

  • Why hihaho/rector-rules?: what the rules rewrite, what they refuse to guess at, and when another tool fits better
  • Installation: requirements, enabling a set, and the paths the location-gated sets need
  • Getting started: one dry run, reading the diff, and keeping the codebase clean in CI

Rule sets

  • Code quality: named flag arguments, dropped default arguments, config()->set(), nullsafe removal
  • Eloquent: #[CollectedBy] and #[ObservedBy] conversions, nested eager loading, relation constants
  • Naming: the suffix each base class implies, and the classes left alone
  • Routing: route-path normalization and fluent route groups
  • Migrations: INSTANT DDL, self-contained migrations, and the opt-in flag-column conversion
  • Imports: aliasing the imports whose short names collide
  • Testing: table strings as model classes, and assertModelExists()

Opt-in rules. Each sits outside every set and is a no-op until registered by FQN.

For the static-analysis counterparts, the rules that report but don't rewrite, see hihaho/phpstan-rules.

Covered by upstream Rector

Some rules in hihaho/phpstan-rules have no counterpart here, because the fix already ships upstream. Enable the upstream set.

PHPStan rule Upstream set Notes
onlyAllowFacadeAliasInBlade LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES Rewrites use Route; to use Illuminate\Support\Facades\Route;, and its siblings
use RectorLaravel\Set\LaravelSetList; // driftingly/rector-laravel

->withSets([LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES])

Testing

composer test

Runs the full Pest suite. composer qa runs the other three CI gates in one go: Pint, Rector and PHPStan. It does not run the tests, so run both before pushing.

Changelog

See CHANGELOG.md.

Contributing

Pull requests and issues are welcome. CONTRIBUTING.md covers the local setup, the fixture format, and what CI checks.

Security

Please report security issues privately. SECURITY.md explains how.

Credits

License

MIT. See LICENSE.