Add RuleConventionsTest to enforce rule registration conventions#992
Open
mglaman wants to merge 4 commits into
Open
Add RuleConventionsTest to enforce rule registration conventions#992mglaman wants to merge 4 commits into
mglaman wants to merge 4 commits into
Conversation
Adds tests/src/RuleConventionsTest.php which parses rules.neon, extension.neon, and bleedingEdge.neon and asserts that every rule is toggleable: registered via conditionalTags with a boolean default under parameters.drupal.rules, opt-in rules enabled in bleedingEdge.neon, and no new rules added directly under rules:. Graduated rules (default true) are tracked via an explicit allowlist. Fixes the pre-existing convention violation surfaced by the test: pluginManagerInspectionRule was opt-in (false default) but missing from bleedingEdge.neon. Adds AGENTS.md documenting the conventions for contributors and agents, and nette/neon as a dev dependency for parsing the neon files. Closes #971 https://claude.ai/code/session_01AAChSrMEaL4S6st2ET2JRF
The rule is too unreliable to enable for bleeding-edge users. Instead of adding it to bleedingEdge.neon, record the deliberate exception in RuleConventionsTest::OPT_IN_RULES_EXCLUDED_FROM_BLEEDING_EDGE so the conventions test stays green and the exclusion is explicit and documented. Reverts the earlier bleedingEdge.neon addition and documents the exception mechanism in AGENTS.md. https://claude.ai/code/session_01AAChSrMEaL4S6st2ET2JRF
Drop the separate AGENTS.md and document the toggleable-rule conventions in the existing CLAUDE.md instead. Update RuleConventionsTest failure messages to point at CLAUDE.md. https://claude.ai/code/session_01AAChSrMEaL4S6st2ET2JRF
Access the preg_match capture group only inside the `=== 1` branch so PHPStan can prove the offset exists, instead of relying on an assertSame that does not narrow the matches array. https://claude.ai/code/session_01AAChSrMEaL4S6st2ET2JRF
There was a problem hiding this comment.
Pull request overview
This PR adds an automated PHPUnit guardrail to enforce this repository’s PHPStan rule registration conventions (toggleable rules via conditionalTags + parameters.drupal.rules, and a frozen legacy rules: list), and documents the conventions for contributors.
Changes:
- Add
RuleConventionsTestthat parsesrules.neon,extension.neon, andbleedingEdge.neonto enforce rule toggleability conventions. - Add
nette/neon(dev) dependency to decode NEON config in tests. - Document rule registration conventions in
CLAUDE.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/src/RuleConventionsTest.php | New PHPUnit test enforcing rule registration/toggleability conventions across NEON configs. |
| composer.json | Adds nette/neon to require-dev for NEON parsing in tests. |
| CLAUDE.md | Documents the rule registration conventions and graduation workflow. |
Comments suppressed due to low confidence (2)
tests/src/RuleConventionsTest.php:115
- The test name
testConditionalRulesHaveFalseDefaultInExtensionNeonis misleading because the body explicitly allows (and asserts)truedefaults for parameters listed in GRADUATED_RULES. Rename the test to reflect the actual convention being enforced (e.g., “conditional rules have a boolean default; non-graduated default false”).
public function testConditionalRulesHaveFalseDefaultInExtensionNeon(): void
{
$defaults = $this->extensionRuleDefaults();
foreach ($this->conditionalRuleParameters() as $parameter) {
tests/src/RuleConventionsTest.php:167
- The comment says graduated rules “must not be listed in bleedingEdge.neon”, but the test currently just
continues when the default isn’tfalseand never asserts absence in$bleedingEdge. Add an assertion that graduated (default true) rule parameters are not present in bleedingEdge.neon so the convention is actually enforced.
foreach ($this->conditionalRuleParameters() as $parameter) {
if (!array_key_exists($parameter, $defaults) || $defaults[$parameter] !== false) {
// Graduated rules (default `true`) are already on by default and
// must not be listed in bleedingEdge.neon.
continue;
Comment on lines
+82
to
+86
| private const OPT_IN_RULES_EXCLUDED_FROM_BLEEDING_EDGE = [ | ||
| // PluginManagerInspectionRule is currently too unreliable to enable by | ||
| // default for bleeding-edge users. | ||
| 'pluginManagerInspectionRule', | ||
| ]; |
Comment on lines
+34
to
+38
| ## Rule Registration Conventions | ||
|
|
||
| Every rule must be **toggleable**. Never add a new rule directly under `rules:` | ||
| in `rules.neon` — that section is frozen for legacy rules and | ||
| `tests/src/RuleConventionsTest.php` fails if it grows. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds tests/src/RuleConventionsTest.php which parses rules.neon,
extension.neon, and bleedingEdge.neon and asserts that every rule is
toggleable: registered via conditionalTags with a boolean default under
parameters.drupal.rules, opt-in rules enabled in bleedingEdge.neon, and
no new rules added directly under rules:. Graduated rules (default
true) are tracked via an explicit allowlist.
Fixes the pre-existing convention violation surfaced by the test:
pluginManagerInspectionRule was opt-in (false default) but missing from
bleedingEdge.neon.
Adds AGENTS.md documenting the conventions for contributors and agents,
and nette/neon as a dev dependency for parsing the neon files.
Closes #971
https://claude.ai/code/session_01AAChSrMEaL4S6st2ET2JRF