Repository navigation
fix(rules): support grouped block syntax in custom rule parser - #1260
Open
AdamMagued wants to merge 1 commit into
Open
AdamMagued wants to merge 1 commit into
AdamMagued wants to merge 1 commit into
Conversation
Support arbitrary label names for grouped rule blocks in the custom rule parser. Previously, only labels starting with 'any' or 'seq' were recognized as block containers, causing other labeled blocks such as 'array_has_key: { ... }' to parse as standalone pattern nodes and fail to register grouped patterns. Also add LabelStmt and GotoStmt matching in phpgrep to avoid panics on unhandled AST nodes.
Fixes VKCOM#1241
This branch has not been deployed
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.
Summary
Fix custom rule parsing when grouped rules use custom label names such as
array_has_key: { ... }.Problem
In custom rule definitions, grouping patterns under a labeled block failed unless the label started with
anyorseq. When a user defined a grouped rule block with any other label name (for instance,array_has_key: { ... }oralways_true: { ... }),tryParseLabeledStmtreturnedfalse, nil. The parser treatedarray_has_key:as an independent rule pattern, registered a rule forir.LabelStmt, and dropped the child patterns in the statement block.When the linter encountered an
ir.LabelStmtnode,phpgrepattempted to match against the rule and panicked with:Changes
src/rules/parser.go): Default toparseAnymode for labeled blocks whose name does not begin withseq. All statements within labeled blocks parse as grouped rule patterns inheriting parent metadata.src/phpgrep/matcher.go): Handle*ir.LabelStmtand*ir.GotoStmtineqNodeto prevent unhandled node panics when evaluating code with labels or gotos.src/rules/parser_test.go: AddTestParser_GroupedRuleverifying rule registration from the issue Grouped rule fails to parse #1241 reproducer.src/tests/rules/multipattern_test.go: AddTestRuleGroupedBlockverifying end-to-end lint reports and label handling.src/phpgrep/matcher_test.go: Add positive and negative match test cases forLabelStmtandGotoStmt.Fixes #1241