jessegall / code-commandments
A Laravel package for enforcing code commandments through prophets who judge and absolve transgressions
Installs: 126
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/jessegall/code-commandments
Requires
- php: ^8.2
- illuminate/console: ^10.0|^11.0|^12.0
- illuminate/filesystem: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- nikic/php-parser: ^5.0
- symfony/finder: ^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
README
This is a personal tool I built for my own projects. It's public in case others find it useful, but it's tailored to my specific coding standards and workflow.
A Laravel package for enforcing code commandments through prophets who judge and absolve transgressions.
Installation
composer require --dev jessegall/code-commandments
Publish the configuration file:
php artisan vendor:publish --tag=commandments-config
Sacred Terminology
| Technical Term | Biblical Term |
|---|---|
| Violation | Sin / Transgression |
| Fix/Auto-fix | Repent / Absolution |
| Warning | Prophecy |
| Validator | Prophet |
| Validator class | [Name]Prophet |
| Validators folder | Prophets/ |
| Pass | Righteous / Blessed |
| Fail | Sinful / Fallen |
| Review | Confession |
| Mark as reviewed | Absolve |
| Groups | Scrolls |
Commands
Judge the Codebase
# Judge all scrolls php artisan commandments:judge # Judge a specific scroll php artisan commandments:judge --scroll=backend # Judge with a specific prophet php artisan commandments:judge --prophet=NoRawRequest # Judge a specific file php artisan commandments:judge --file=app/Http/Controllers/UserController.php # Judge multiple specific files (comma-separated) php artisan commandments:judge --files=app/Models/User.php,app/Services/AuthService.php # Mark files as absolved after manual review php artisan commandments:judge --absolve
Seek Absolution (Auto-fix)
# Auto-fix all sins that can be absolved php artisan commandments:repent # Preview what would be fixed php artisan commandments:repent --dry-run # Fix a specific file php artisan commandments:repent --file=app/Http/Controllers/UserController.php # Fix multiple specific files (comma-separated) php artisan commandments:repent --files=app/Models/User.php,app/Services/AuthService.php
Read the Scripture (List Commandments)
# List all prophets php artisan commandments:scripture # List with detailed descriptions php artisan commandments:scripture --detailed # List prophets from a specific scroll php artisan commandments:scripture --scroll=frontend
Summon a New Prophet
# Create a new backend prophet php artisan make:prophet NoMagicNumbers --scroll=backend # Create a new frontend prophet php artisan make:prophet NoInlineStyles --scroll=frontend --type=frontend # Create a prophet that can auto-fix php artisan make:prophet NoUnusedImports --repentable # Create a prophet that requires manual review php artisan make:prophet ComplexLogicReview --confession
Claude Code Integration
Install hooks to automatically judge your code when using Claude Code:
php artisan commandments:install-hooks
This will:
- Show the scripture (commandments) when starting a Claude Code session
- Run the judge command after Claude completes work
- Distinguish between sins (must fix) and warnings (review and absolve)
Configuration
Configure your scrolls in config/commandments.php:
return [ 'scrolls' => [ 'backend' => [ 'path' => app_path(), 'extensions' => ['php'], 'exclude' => ['Console/Kernel.php'], 'thresholds' => [ 'max_method_lines' => 15, 'max_private_methods' => 3, // For ControllerPrivateMethodsProphet 'min_method_lines' => 3, // Minimum lines for a method to count ], 'prophets' => [ \JesseGall\CodeCommandments\Prophets\Backend\NoRawRequestProphet::class, // Add more prophets... ], ], 'frontend' => [ 'path' => resource_path('js'), 'extensions' => ['vue', 'ts', 'js'], 'thresholds' => [ 'max_vue_lines' => 200, ], 'prophets' => [ \JesseGall\CodeCommandments\Prophets\Frontend\CompositionApiProphet::class, // Add more prophets... ], ], ], 'confession' => [ 'tablet_path' => storage_path('commandments/confessions.json'), ], ];
Built-in Prophets
Backend (PHP)
- NoRawRequestProphet - Thou shalt not access raw request data
- NoJsonResponseProphet - Thou shalt not return raw JSON responses
- NoHasMethodInControllerProphet - Thou shalt not use has() in controllers
- NoEventDispatchProphet - Thou shalt use event() helper for dispatching
- NoRecordThatOutsideAggregateProphet - Thou shalt not use recordThat() outside aggregates
- NoValidatedMethodProphet - Thou shalt not use validated() method
- NoInlineValidationProphet - Thou shalt not use inline validation
- TypeScriptAttributeProphet - Thou shalt use #[TypeScript] on Resources
- ReadonlyDataPropertiesProphet - Thou shalt not declare readonly properties in Data class body
- FormRequestTypedGettersProphet - Thou shalt use typed getters in FormRequest
- HiddenAttributeProphet - Thou shalt hide sensitive model attributes
- NoCustomFromModelProphet - Thou shalt not use custom fromModel methods
- ControllerPrivateMethodsProphet - Thou shalt not have too many private methods in controllers
- KebabCaseRoutesProphet - Thou shalt use kebab-case for route URIs
- ConstructorDependencyInjectionProphet - Thou shalt inject dependencies via constructor
Frontend (Vue/TypeScript)
- NoFetchAxiosProphet - Thou shalt not use fetch() or axios directly
- TemplateVForProphet - Thou shalt wrap v-for in template elements
- TemplateVIfProphet - Thou shalt wrap v-if/v-else in template elements
- RouterHardcodedUrlsProphet - Thou shalt not hardcode URLs in router calls
- WayfinderRoutesProphet - Thou shalt not hardcode URLs in href attributes
- CompositionApiProphet - Thou shalt use Composition API
- ArrowFunctionAssignmentsProphet - Thou shalt use const arrow functions
- SwitchCaseProphet - Thou shalt not use switch statements
- LongVueFilesProphet - Thou shalt keep Vue files concise
- LongTsFilesProphet - Thou shalt keep TypeScript files concise
- RepeatingPatternsProphet - Thou shalt not repeat template patterns
- ScriptFirstProphet - Thou shalt put script before template
- PropsTypeScriptProphet - Thou shalt type props with TypeScript
- EmitsTypeScriptProphet - Thou shalt type emits with TypeScript
- InlineEmitTransformProphet - Thou shalt not transform data in emit handlers
- InlineTypeCastingProphet - Thou shalt not type cast in templates
- WatchIfPatternProphet - Thou shalt not use watch with if conditions
- PageDataAccessProphet - Thou shalt use typed page props
- DeepNestingProphet - Thou shalt not deeply nest template elements
- StyleOverridesProphet - Thou shalt not override child component styles
- ExplicitDefaultSlotProphet - Thou shalt use explicit default slots
- MultipleSlotDefinitionsProphet - Thou shalt type slots with defineSlots
- ConditionalArrayBuildingProphet - Consider disabled flags pattern for array building
- SwitchCheckboxVModelProphet - Thou shalt use v-model on Switch/Checkbox
- LoopsWithIndexedStateProphet - Review indexed state in loops (requires confession)
- ContentLikePropsProphet - Review content-like props (requires confession)
- InlineDialogProphet - Review inline dialog definitions (requires confession)
Creating Custom Prophets
<?php namespace App\Prophets\Backend; use JesseGall\CodeCommandments\Commandments\PhpCommandment; use JesseGall\CodeCommandments\Results\Judgment; class NoMagicNumbersProphet extends PhpCommandment { public function description(): string { return 'Thou shalt not use magic numbers'; } public function detailedDescription(): string { return 'Magic numbers should be extracted to named constants...'; } public function judge(string $filePath, string $content): Judgment { $ast = $this->parse($content); if ($ast === null) { return $this->skip('Unable to parse PHP file'); } // Your judgment logic here... return $this->righteous(); } }
Vue/TypeScript Auto-fixing
For Vue and TypeScript auto-fixing, install the Node.js dependencies:
cd vendor/jessegall/code-commandments/node
npm install
Testing
./vendor/bin/phpunit
License
MIT License