Fix incorrect invalidConfigPath diagnostic when a theme() call spans multiple lines - #1606
Open
Megoos wants to merge 2 commits into
Open
Fix incorrect invalidConfigPath diagnostic when a theme() call spans multiple lines#1606Megoos wants to merge 2 commits into
Megoos wants to merge 2 commits into
Conversation
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported placeholder changelog reference has been replaced with the correct PR #1606 link. Reviews (2): Last reviewed commit: "Update CHANGELOG with PR link" | Re-trigger Greptile |
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.
Problem
A
theme(…)call wrapped across multiple lines is reported as invalid, even though the same path resolves fine on a single line:Note the quotes and the newline that leaked into the path. This is easy to hit in codebases with long token names, since Prettier wraps the call as soon as the line exceeds
printWidth, and the only workaround is turning offinvalidConfigPathentirely — which also hides real typos.Cause
findHelperFunctionsInRangetrims whitespace and quotes off the extracted path with:match()without thegflag returns[fullMatch, ...groups], so.lengthis the number of entries — always 1 — not the length of the match. Each trim step therefore moves the boundary by exactly one character.There are two trim passes, so up to two whitespace characters per side happen to work — which is why single-line calls were fine, and why this looks like a "multi-line" bug even though newlines have nothing to do with it (
theme( 'colors.red.500' )breaks on one line too). A newline plus indentation is always past that limit.Once whitespace is left over,
/^['"]+/stops matching so the quotes survive too, and that mangled path is what gets validated. The same mistake skewsranges.path, so the squiggle lands on the indentation instead of the path.Worth knowing when testing: the false positive only reproduces on v3, which looks the path up directly with
dlv. On v4 the path is resolved by compiling[--custom:theme(<path>)], and Tailwind's own parser tolerates the stray whitespace and quotes — so a valid path still resolves there, and the bug only surfaces on a genuine typo, as a mangled message and a wrong range.Fix
Use
?.[0].lengthso the matched length is used. Applies to all four whitespace/quote trims.Test plan
Helper functions can span multiple linesinfind.test.ts— covering a wrapped call and one with a default value, asserting both the extracted path and the reported ranges. It fails before this change and passes after it.tailwindcss-language-servicetest suite — all tests pass..bis flagged while.ais not, after it neither is. A real typo in the wrapped path is still reported, now underlining the path itself.