Skip to content

Commit 17302e7

Browse files
committed
fix: address final 2 PR #47 review comments
- Remove unused htmlPaths variable from directory walk - Broaden reActionVar to capture lowercase/underscore dot-variables
1 parent e3b14bd commit 17302e7

2 files changed

Lines changed: 4 additions & 10 deletions

File tree

pkg/parser/html/analyzer.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ func (a *Analyzer) Analyze(ctx context.Context, path string) (*pkgParser.Result,
6464
// Single file: check for Go template syntax
6565
symbols = append(symbols, a.analyzeGoTemplates(path)...)
6666
} else {
67-
// Directory: single walk that collects HTML file paths.
68-
// GoTemplate analysis runs per-file during the walk,
69-
// so we avoid a second walk + double file reads.
70-
var htmlPaths []string
67+
// Directory: walk once for GoTemplate detection.
68+
// DOM analysis is done separately by AnalyzePaths below (different parser, different purpose).
7169
if walkErr := filepath.WalkDir(path, func(fp string, d fs.DirEntry, err error) error {
7270
if err != nil {
7371
logger.Instance.Debug("[HTML] walk entry error %s: %v", fp, err)
@@ -77,17 +75,13 @@ func (a *Analyzer) Analyze(ctx context.Context, path string) (*pkgParser.Result,
7775
return nil
7876
}
7977
if a.ca.isHTMLFile(d.Name()) {
80-
htmlPaths = append(htmlPaths, fp)
8178
symbols = append(symbols, a.analyzeGoTemplates(fp)...)
8279
}
8380
return nil
8481
}); walkErr != nil {
8582
// Log but don't fail — HTML DOM analysis may still succeed
8683
logger.Instance.Debug("[HTML] walk error for Go template detection: %v", walkErr)
8784
}
88-
// Use collected paths to avoid a second directory walk in AnalyzePaths
89-
_ = htmlPaths // paths used by walk above; AnalyzePaths will walk again for DOM but
90-
// GoTemplate detection is already done above per-file
9185
}
9286

9387
// Always run HTML DOM analysis too (Go templates contain HTML)

pkg/parser/html/gotemplate/analyzer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ var (
2424
reComment = regexp.MustCompile(`\{\{/\*.*?\*/\}\}`)
2525
// Matches any Go template action: {{ ... }}
2626
reAction = regexp.MustCompile(`\{\{(.+?)\}\}`)
27-
// Matches dot-variables anywhere inside an action (e.g. .Body in "{{ .Body | truncate 200 }}")
28-
reActionVar = regexp.MustCompile(`(\.[A-Z]\w*(?:\.[A-Z]\w*)*)`)
27+
// Matches dot-variables anywhere inside an action — includes lowercase/underscore (e.g. .user, .items, .Title)
28+
reActionVar = regexp.MustCompile(`(\.[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)`)
2929
// Custom funcs: {{ funcName ... }} where funcName is not a keyword.
3030
reCustomFunc = regexp.MustCompile(`\{\{-?\s*([a-zA-Z]\w+)\s+`)
3131

0 commit comments

Comments
 (0)