fix: correct persistent variable detection with underscores#549
Open
Venshard wants to merge 1 commit into
Open
fix: correct persistent variable detection with underscores#549Venshard wants to merge 1 commit into
Venshard wants to merge 1 commit into
Conversation
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
Fixes #532
Fixes a bug in the linter where persistent variables containing multiple underscores (e.g.,
persistent.show_map_debug) are incorrectly flagged as undefined when they appear at the end of a line or before certain non-alphabetic characters.The Problem
The
rxPersistentCheckregex insrc/diagnostics.tsuses a trailing anchor[^a-zA-Z]to identify the end of a persistent variable reference.Because
_(underscore) is a word character (\w) but not an alphabetic character ([a-zA-Z]), the regex engine backtracks when it encounters an underscore it can't skip, or when the variable is at the end of a line.Reproduction Case
Consider the following line of code:
=after the variable satisfies[^a-zA-Z], so it matchesshow_map_debugcorrectly.debug.show_map_debugin(\w+), but then fails to find[^a-zA-Z].show_mapin(\w+)._(from_debug) as the[^a-zA-Z]character.persistent.show_map, which hasn't been defined, and throws a warning.The Fix
Updated the regex to use a positive lookahead
(?=[^a-zA-Z0-9_]|$). This ensures that the capture group(\w+)only matches the full identifier by asserting that it is followed by either a non-identifier character (like space, colon, or equals) or the end of the line.The updated regex is:
This prevents the regex engine from backtracking and matching partial identifiers (like
show_mapfromshow_map_debug) just to satisfy the trailing character requirement.