fix(convex-lint): scan to handler: instead of a fixed 300-char window - #15
Open
milehighideas wants to merge 1 commit into
Open
fix(convex-lint): scan to handler: instead of a fixed 300-char window#15milehighideas wants to merge 1 commit into
milehighideas wants to merge 1 commit into
Conversation
The soft-warning pass scanned a fixed 300-char window after each `fn({`
to look for `args:`/`returns:`. A large `args:`/`returns:` validator
pushes `returns:` past the window, producing a false "missing `returns:`"
advisory on functions that do declare it.
Scan up to the function's `handler:` key instead (always present, and
declared after args/returns); fall back to 300 chars if none is found.
Hard-deny rules are untouched.
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.
Fix false-positive "missing
returns:" advisory in convex-lint.mjsRepo:
get-convex/convex-backend-skillFile:
hooks/convex-lint.mjsProblem
The PreToolUse
convex-linthook emits a false-positive advisory:…on functions that do declare
returns:. It fires whenever a function'sargs:(and/orreturns:) validator is large enough that thereturns:keysits more than ~300 characters after the
fn({opening.Root cause
The soft-warning pass scans a fixed 300-character window after each
function-open match:
A function with a sizable
argsobject (nestedv.object, several optionalfields) pushes
returns:past char 300, so the regex never sees it. Exampleoffsets from a real file:
returns:at char 501 and 406 from therespective
internalMutation({— both beyond the window, both falsely flagged.Fix
Scan up to the function's
handler:key instead of a fixed window. Every Convexobject-form function has exactly one
handler:, declared afterargs/returns,so the region before it is precisely the validator block — regardless of size.
Fall back to 300 chars if no
handler:is found.while ((m = objectFormRe.exec(projected)) !== null) { - const head = projected.slice(m.index, m.index + 300); + // Scan the function's option object up to its `handler:` key (every Convex + // function object has one, declared after args/returns) instead of a + // fixed-size window. A large `args:`/`returns:` validator can push + // `returns:` well past a 300-char window, producing a false "missing + // `returns:`" advisory. Fall back to 300 chars if no handler is found. + const rest = projected.slice(m.index); + const handlerIdx = rest.search(/\bhandler\s*:/); + const head = handlerIdx === -1 ? rest.slice(0, 300) : rest.slice(0, handlerIdx); const missing = []; if (!/\bargs\s*:/.test(head)) missing.push("`args:`"); if (!/\breturns\s*:/.test(head)) missing.push("`returns:`");Verification
argsblock and areturns:validator → no longerflagged (was a false positive before).
returns:(even with a largeargsblock) → stillcorrectly flagged (no false-negative regression).
returns: v.null()→ silent, as expected.The change is confined to the advisory pass; the two hard-deny rules
(
.filteron a db query, positional function syntax) are untouched.