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{
|
svc, err := foo.NewService(ctx, db, logger, foo.Config{
|
||||||
Interval: 10 * time.Second,
|
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.
|
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)
|
return nil, fmt.Errorf("cannot build search URL: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := json.Marshal(firecrawlRequest{
|
body, err := json.Marshal(
|
||||||
Query: query,
|
firecrawlRequest{
|
||||||
Limit: maxResults,
|
Query: query,
|
||||||
})
|
Limit: maxResults,
|
||||||
|
},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot marshal request: %w", err)
|
return nil, fmt.Errorf("cannot marshal request: %w", err)
|
||||||
}
|
}
|
||||||
@@ -132,11 +134,14 @@ func firecrawlSearch(
|
|||||||
|
|
||||||
results := make([]searchResult, 0, len(fcResp.Data.Web))
|
results := make([]searchResult, 0, len(fcResp.Data.Web))
|
||||||
for _, r := range fcResp.Data.Web {
|
for _, r := range fcResp.Data.Web {
|
||||||
results = append(results, searchResult{
|
results = append(
|
||||||
Title: r.Title,
|
results,
|
||||||
URL: r.URL,
|
searchResult{
|
||||||
Snippet: r.Description,
|
Title: r.Title,
|
||||||
})
|
URL: r.URL,
|
||||||
|
Snippet: r.Description,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return results, nil
|
return results, nil
|
||||||
|
|||||||
@@ -306,18 +306,21 @@ func findMergeGroups(
|
|||||||
// Sort: heuristic first, then descending specificity (more fixed
|
// Sort: heuristic first, then descending specificity (more fixed
|
||||||
// characters), then descending coverage, then template name for a
|
// characters), then descending coverage, then template name for a
|
||||||
// fully deterministic order.
|
// fully deterministic order.
|
||||||
sort.Slice(candidates, func(i, j int) bool {
|
sort.Slice(
|
||||||
if candidates[i].isHeuristic != candidates[j].isHeuristic {
|
candidates,
|
||||||
return candidates[i].isHeuristic
|
func(i, j int) bool {
|
||||||
}
|
if candidates[i].isHeuristic != candidates[j].isHeuristic {
|
||||||
if candidates[i].fixedChars != candidates[j].fixedChars {
|
return candidates[i].isHeuristic
|
||||||
return candidates[i].fixedChars > candidates[j].fixedChars
|
}
|
||||||
}
|
if candidates[i].fixedChars != candidates[j].fixedChars {
|
||||||
if len(candidates[i].patterns) != len(candidates[j].patterns) {
|
return candidates[i].fixedChars > candidates[j].fixedChars
|
||||||
return len(candidates[i].patterns) > len(candidates[j].patterns)
|
}
|
||||||
}
|
if len(candidates[i].patterns) != len(candidates[j].patterns) {
|
||||||
return candidates[i].key.template < candidates[j].key.template
|
return len(candidates[i].patterns) > len(candidates[j].patterns)
|
||||||
})
|
}
|
||||||
|
return candidates[i].key.template < candidates[j].key.template
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
assigned := make(map[*coredata.TrackerPattern]bool)
|
assigned := make(map[*coredata.TrackerPattern]bool)
|
||||||
groups := make(map[mergeGroupKey][]*coredata.TrackerPattern)
|
groups := make(map[mergeGroupKey][]*coredata.TrackerPattern)
|
||||||
@@ -598,9 +601,12 @@ func (h *patternAnalysisHandler) adoptUncategorisedPatterns(
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(globPatterns, func(i, j int) bool {
|
sort.Slice(
|
||||||
return len(globPatterns[i].Pattern) > len(globPatterns[j].Pattern)
|
globPatterns,
|
||||||
})
|
func(i, j int) bool {
|
||||||
|
return len(globPatterns[i].Pattern) > len(globPatterns[j].Pattern)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
exactMatchType := coredata.TrackerPatternMatchTypeExact
|
exactMatchType := coredata.TrackerPatternMatchTypeExact
|
||||||
var uncategorisedExact coredata.TrackerPatterns
|
var uncategorisedExact coredata.TrackerPatterns
|
||||||
|
|||||||
@@ -251,10 +251,13 @@ RETURNING id, (xmax = 0) AS inserted
|
|||||||
Inserted bool
|
Inserted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := pgx.CollectExactlyOneRow(rows, func(row pgx.CollectableRow) (upsertResult, error) {
|
res, err := pgx.CollectExactlyOneRow(
|
||||||
var r upsertResult
|
rows,
|
||||||
return r, row.Scan(&r.ID, &r.Inserted)
|
func(row pgx.CollectableRow) (upsertResult, error) {
|
||||||
})
|
var r upsertResult
|
||||||
|
return r, row.Scan(&r.ID, &r.Inserted)
|
||||||
|
},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gid.GID{}, false, fmt.Errorf("cannot collect upsert result: %w", err)
|
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 {
|
func normalizeDomain(s string) string {
|
||||||
s = strings.TrimSpace(s)
|
s = strings.TrimSpace(s)
|
||||||
|
|
||||||
s = strings.Map(func(r rune) rune {
|
s = strings.Map(
|
||||||
if r == '\u200b' || r == '\ufeff' {
|
func(r rune) rune {
|
||||||
return -1
|
if r == '\u200b' || r == '\ufeff' {
|
||||||
}
|
return -1
|
||||||
return r
|
}
|
||||||
}, s)
|
return r
|
||||||
|
},
|
||||||
|
s,
|
||||||
|
)
|
||||||
|
|
||||||
if idx := strings.Index(s, " or "); idx != -1 {
|
if idx := strings.Index(s, " or "); idx != -1 {
|
||||||
s = s[:idx]
|
s = s[:idx]
|
||||||
|
|||||||
Reference in New Issue
Block a user