Enforce multiline rule for single multiline arguments
Update go-style guide and cursor rule to clarify that even a single argument spanning multiple lines must break after the opening parenthesis. Fix six violations across the branch. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -106,6 +106,33 @@ t.Run(
|
||||
svc, err := foo.NewService(ctx, db, logger, foo.Config{
|
||||
Interval: 10 * time.Second,
|
||||
})
|
||||
|
||||
// Bad — single multiline argument starts on the opening ( line
|
||||
body, err := json.Marshal(firecrawlRequest{
|
||||
Query: query,
|
||||
Limit: maxResults,
|
||||
})
|
||||
|
||||
// Good — single multiline argument: break after (, trailing comma, ) alone
|
||||
body, err := json.Marshal(
|
||||
firecrawlRequest{
|
||||
Query: query,
|
||||
Limit: maxResults,
|
||||
},
|
||||
)
|
||||
|
||||
// Bad — function literal starts on the opening ( line
|
||||
sort.Slice(items, func(i, j int) bool {
|
||||
return items[i].Name < items[j].Name
|
||||
})
|
||||
|
||||
// Good — function literal on its own line
|
||||
sort.Slice(
|
||||
items,
|
||||
func(i, j int) bool {
|
||||
return items[i].Name < items[j].Name
|
||||
},
|
||||
)
|
||||
```
|
||||
|
||||
The same rule applies to **method calls** `x.M(a1, …)` — the receiver is already bound; the rule applies to the **argument list** after the method name.
|
||||
|
||||
@@ -91,10 +91,12 @@ func firecrawlSearch(
|
||||
return nil, fmt.Errorf("cannot build search URL: %w", err)
|
||||
}
|
||||
|
||||
body, err := json.Marshal(firecrawlRequest{
|
||||
Query: query,
|
||||
Limit: maxResults,
|
||||
})
|
||||
body, err := json.Marshal(
|
||||
firecrawlRequest{
|
||||
Query: query,
|
||||
Limit: maxResults,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot marshal request: %w", err)
|
||||
}
|
||||
@@ -132,11 +134,14 @@ func firecrawlSearch(
|
||||
|
||||
results := make([]searchResult, 0, len(fcResp.Data.Web))
|
||||
for _, r := range fcResp.Data.Web {
|
||||
results = append(results, searchResult{
|
||||
Title: r.Title,
|
||||
URL: r.URL,
|
||||
Snippet: r.Description,
|
||||
})
|
||||
results = append(
|
||||
results,
|
||||
searchResult{
|
||||
Title: r.Title,
|
||||
URL: r.URL,
|
||||
Snippet: r.Description,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
|
||||
@@ -306,18 +306,21 @@ func findMergeGroups(
|
||||
// Sort: heuristic first, then descending specificity (more fixed
|
||||
// characters), then descending coverage, then template name for a
|
||||
// fully deterministic order.
|
||||
sort.Slice(candidates, func(i, j int) bool {
|
||||
if candidates[i].isHeuristic != candidates[j].isHeuristic {
|
||||
return candidates[i].isHeuristic
|
||||
}
|
||||
if candidates[i].fixedChars != candidates[j].fixedChars {
|
||||
return candidates[i].fixedChars > candidates[j].fixedChars
|
||||
}
|
||||
if len(candidates[i].patterns) != len(candidates[j].patterns) {
|
||||
return len(candidates[i].patterns) > len(candidates[j].patterns)
|
||||
}
|
||||
return candidates[i].key.template < candidates[j].key.template
|
||||
})
|
||||
sort.Slice(
|
||||
candidates,
|
||||
func(i, j int) bool {
|
||||
if candidates[i].isHeuristic != candidates[j].isHeuristic {
|
||||
return candidates[i].isHeuristic
|
||||
}
|
||||
if candidates[i].fixedChars != candidates[j].fixedChars {
|
||||
return candidates[i].fixedChars > candidates[j].fixedChars
|
||||
}
|
||||
if len(candidates[i].patterns) != len(candidates[j].patterns) {
|
||||
return len(candidates[i].patterns) > len(candidates[j].patterns)
|
||||
}
|
||||
return candidates[i].key.template < candidates[j].key.template
|
||||
},
|
||||
)
|
||||
|
||||
assigned := make(map[*coredata.TrackerPattern]bool)
|
||||
groups := make(map[mergeGroupKey][]*coredata.TrackerPattern)
|
||||
@@ -598,9 +601,12 @@ func (h *patternAnalysisHandler) adoptUncategorisedPatterns(
|
||||
return false, nil
|
||||
}
|
||||
|
||||
sort.Slice(globPatterns, func(i, j int) bool {
|
||||
return len(globPatterns[i].Pattern) > len(globPatterns[j].Pattern)
|
||||
})
|
||||
sort.Slice(
|
||||
globPatterns,
|
||||
func(i, j int) bool {
|
||||
return len(globPatterns[i].Pattern) > len(globPatterns[j].Pattern)
|
||||
},
|
||||
)
|
||||
|
||||
exactMatchType := coredata.TrackerPatternMatchTypeExact
|
||||
var uncategorisedExact coredata.TrackerPatterns
|
||||
|
||||
@@ -251,10 +251,13 @@ RETURNING id, (xmax = 0) AS inserted
|
||||
Inserted bool
|
||||
}
|
||||
|
||||
res, err := pgx.CollectExactlyOneRow(rows, func(row pgx.CollectableRow) (upsertResult, error) {
|
||||
var r upsertResult
|
||||
return r, row.Scan(&r.ID, &r.Inserted)
|
||||
})
|
||||
res, err := pgx.CollectExactlyOneRow(
|
||||
rows,
|
||||
func(row pgx.CollectableRow) (upsertResult, error) {
|
||||
var r upsertResult
|
||||
return r, row.Scan(&r.ID, &r.Inserted)
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return gid.GID{}, false, fmt.Errorf("cannot collect upsert result: %w", err)
|
||||
}
|
||||
|
||||
@@ -344,12 +344,15 @@ var domainValidRe = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z]$`)
|
||||
func normalizeDomain(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
s = strings.Map(func(r rune) rune {
|
||||
if r == '\u200b' || r == '\ufeff' {
|
||||
return -1
|
||||
}
|
||||
return r
|
||||
}, s)
|
||||
s = strings.Map(
|
||||
func(r rune) rune {
|
||||
if r == '\u200b' || r == '\ufeff' {
|
||||
return -1
|
||||
}
|
||||
return r
|
||||
},
|
||||
s,
|
||||
)
|
||||
|
||||
if idx := strings.Index(s, " or "); idx != -1 {
|
||||
s = s[:idx]
|
||||
|
||||
Reference in New Issue
Block a user