modfile: support autolambda directive - #159
Conversation
Parse the `autolambda name(n), ...` directive in gox.mod and store the results in Project.AutoLambdas (command => number of non-lambda arguments before the trailing implicit lambda). Multiple entries may appear in one directive or across multiple autolambda lines within a project. Fixes #158
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #159 +/- ##
==========================================
+ Coverage 76.96% 81.23% +4.26%
==========================================
Files 11 10 -1
Lines 890 906 +16
==========================================
+ Hits 685 736 +51
+ Misses 186 151 -35
Partials 19 19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Review: autolambda directive parser
The change is clean and well-structured: parseAutoLambdas is a pure, testable function, isIdent is the right choice over parseSymbol (autolambda names are lowercase method names), strconv.Atoi correctly rejects overflow and non-numeric input while the explicit nArgs < 0 check handles negatives, and the error paths are thoroughly tested. Build and the new tests pass locally.
Two concrete findings are left inline. Additional minor observations below.
Minor observations (non-blocking):
modfile/rule.go:95— theAutoLambdasfield comment ("number of parameters before auto lambda") is terse; expanding it to explain what the count controls would help future readers.isIdentrestricts command names to ASCII[A-Za-z_][A-Za-z0-9_]*, stricter than the underlying modfile tokenizer. Almost certainly intentional, but worth confirming XGo command names are never non-ASCII.- No test pins the duplicate-name semantics (same name within one directive or across two
autolambdadirectives). Whatever behavior is chosen for the inline finding below, add a test to lock it in.
Resolves #158.
What
Adds support for the
autolambdadirective ingox.modand stores the parsed result inProject.AutoLambdas.Each
name(n)entry maps a command's identifier to the number of non-lambda arguments that appear before the (implicit) trailing lambda.Details
autolambdacase inparseVerb(modfile/rule.go), placed after the existingpackdirective.projectdefinition (consistent withclass/import/pack).autolambdalines within the same project; all entries merge intoProject.AutoLambdas.gox.modtoken stream (the tokenizer splits(,)and,into separate tokens), with descriptive error messages for malformed entries.Tests
Added to
modfile/rule_test.go:TestParseAutoLambda— single directive with multiple entries.TestParseMultiAutoLambda— entries spread across multiple lines.TestParseNoAutoLambda— absence leavesAutoLambdasnil.TestParseAutoLambdaErr— error cases (before project, missing args, malformedname(n), invalid number, missing separators, trailing comma).go test ./...andgo vet ./modfile/pass.go.mod/go.sumare unchanged.