Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion blink/internal/fixer/rules/symplify_docblock3.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ import (
"regexp"
"sort"
"strings"
"sync"

"blink/internal/token"
"blink/internal/tokens"
)

// fpntTypoReCache memoizes the per-typo-name @param patterns, which are
// otherwise recompiled on every fpntFixTypos call. Keyed by typo name.
var fpntTypoReCache sync.Map

func fpntTypoRe(typoName string) *regexp.Regexp {
if re, ok := fpntTypoReCache.Load(typoName); ok {
return re.(*regexp.Regexp)
}
re := regexp.MustCompile(`@param(.*?)(` + regexp.QuoteMeta(typoName) + `\b)`)
fpntTypoReCache.Store(typoName, re)
return re
}

// --- FixParamNameTypo: correct a @param variable name to match the real argument ---

type FixParamNameTypo struct{}
Expand Down Expand Up @@ -132,7 +146,7 @@ func fpntFixTypos(argumentNames []string, missArg, paramNames map[int]string, co
if !ok {
continue
}
re := regexp.MustCompile(`@param(.*?)(` + regexp.QuoteMeta(typoName) + `\b)`)
re := fpntTypoRe(typoName)
content = replaceFirstFunc(content, re, func(groups []string) string {
paramName := groups[2]
if done, exists := replaced[paramName]; exists && !done {
Expand Down
15 changes: 9 additions & 6 deletions blink/internal/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ func newFormatter(w io.Writer) formatter {
return formatter{w: w, width: width, color: color}
}

// relativePath resolves an absolute file path against the current working
// directory, matching ECS's StaticRelativeFilePathHelper output.
func relativePath(path string) string {
cwd, err := os.Getwd()
if err != nil {
// relativePath resolves an absolute file path against cwd, matching ECS's
// StaticRelativeFilePathHelper output. An empty cwd yields the path unchanged.
func relativePath(cwd, path string) string {
if cwd == "" {
return path
}
rel, err := filepath.Rel(cwd, path)
Expand All @@ -104,9 +103,13 @@ func (f formatter) reportFileDiffs(results []runner.FileResult) {
}
f.newLine(1)

cwd, err := os.Getwd()
if err != nil {
cwd = ""
}
for i, r := range results {
f.newLine(2)
f.writeln(f.bold(fmt.Sprintf("%d) %s", i+1, relativePath(r.Path))))
f.writeln(f.bold(fmt.Sprintf("%d) %s", i+1, relativePath(cwd, r.Path))))
f.newLine(1)
f.writeln(f.formatDiff(r.Diff))
f.newLine(1)
Expand Down
Loading