Skip to content

a rule to replace append with slices.Concat#1701

Description

@alexandear

Is your feature request related to a problem? Please describe.

Sometimes multiple appends can be simplified with the one slices.Concat.

Describe the solution you'd like

A new rule that transforms the following code:

// https://github.com/simonw/sqlite-scanner/blob/3e590d461861c7c0b1e0d22483abd1ecdb46d1ea/main_test.go#L18
content := append(append([]byte{}, sqliteMagic...), []byte("lengthy payload")...)

// https://github.com/golangci/golangci-lint/blob/f54365bc92856d453f8c7c4684022b5d4efa0cb1/pkg/result/processors/nolint_filter.go#L188-L189
allRanges := append([]ignoredRange{}, inlineRanges...)
allRanges = append(allRanges, e.expandedRanges...)

to the following:

// 1
content := slices.Concat(sqliteMagic, []byte("lengthy payload"))

// 2
allRanges := slices.Concat(inlineRanges, e.expandedRanges)

Metadata

Metadata

Assignees

No one assigned

    Labels

    rule proposalIssue proposing a new rule

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions