-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add ClassNameShouldNotEndWithComponentRule
#2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
98c95e9 to
59baf89
Compare
ComponentClassNameShouldNotEndWithComponentRule ClassNameShouldNotEndWithComponentRule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a new PHPStan rule ClassNameShouldNotEndWithComponentRule that enforces a naming convention for Symfony UX Twig Components. The rule prevents developers from using redundant "Component" suffixes in class names since the #[AsTwigComponent] attribute already identifies the class as a component.
Key Changes
- Implements
ClassNameShouldNotEndWithComponentRuleto detect and report classes ending with "Component" suffix - Adds comprehensive test coverage with valid, invalid, and non-component test cases
- Updates README with documentation and examples following existing patterns
- Adds AGENTS.md file with detailed instructions for creating new PHPStan rules in this project
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule.php |
Main rule implementation that checks for "Component" suffix in Twig component class names |
tests/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule/ClassNameShouldNotEndWithComponentRuleTest.php |
Test suite with violation and no-violation test cases |
tests/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule/Fixture/InvalidComponentName.php |
Test fixture demonstrating invalid class name (AlertComponent) |
tests/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule/Fixture/ValidComponentName.php |
Test fixture demonstrating valid class name (Alert) |
tests/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule/Fixture/NotAComponent.php |
Test fixture for non-component class to ensure rule doesn't trigger |
tests/Rules/TwigComponent/ClassNameShouldNotEndWithComponentRule/config/configured_rule.neon |
PHPStan configuration for the test environment |
README.md |
Documentation for the new rule with examples showing both invalid and valid usage |
AGENTS.md |
Comprehensive guide for AI agents and developers on creating new PHPStan rules in this project |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (str_ends_with($classNameString, 'Component')) { | ||
| return [ | ||
| RuleErrorBuilder::message(sprintf('Twig component class "%s" should not end with "Component".', $classNameString)) | ||
| ->identifier('symfonyUX.twigComponent.classNameShouldNotEndWithComponent') |
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The identifier casing is inconsistent with other rules in this codebase. ForbiddenClassPropertyRule uses symfonyUX.twigComponent.forbiddenClassProperty (lowercase 'symfonyUX'), while ForbiddenAttributesPropertyRule uses SymfonyUX.TwigComponent.forbiddenAttributesProperty (uppercase 'SymfonyUX').
This rule follows the lowercase convention, but there should be consistency across all rules. Consider standardizing on one casing pattern (e.g., symfonyUX.twigComponent.classNameShouldNotEndWithComponent).
| ->identifier('symfonyUX.twigComponent.classNameShouldNotEndWithComponent') | |
| ->identifier('SymfonyUX.TwigComponent.classNameShouldNotEndWithComponent') |
59baf89 to
a9344a3
Compare
Proudly vibe-coded