stdlib

package module
v0.0.0-...-951b2b2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2025 License: MIT Imports: 15 Imported by: 0

README

stdlib

Go Reference CI Go Report Card

A static analysis tool for Go that detects usage of functions from third-party libraries and suggests replacements using standard library functions or built-in language features. It leverages Go’s analysis package to provide automated refactorings and improvement suggestions.

Usage

# Install
go install github.com/abemedia/stdlib/cmd/stdlib@latest

# Use
stdlib ./...

Replacements

Expand the sections below to see the supported replacements for each package.

github.com/samber/lo
Chunk

Before:

result := lo.Chunk(slice, size)

After:

result := slices.Chunk(slice, size)
Drop

Before:

a := []int{0, 1, 2, 3, 4, 5}
b := lo.Drop(a, 2)

After:

a := []int{0, 1, 2, 3, 4, 5}
b := a[2:]
DropRight

Before:

a := []int{0, 1, 2, 3, 4, 5}
b := lo.DropRight(a, 2)

After:

a := []int{0, 1, 2, 3, 4, 5}
b := a[:len(a)-2]
Contains

Before:

if lo.Contains(slice, target) {
    // do something
}

After:

if slices.Contains(slice, target) {
    // do something
}
ContainsBy

Before:

if lo.ContainsBy(slice, func(item int) bool {
    return item > 10
}) {
    // do something
}

After:

if slices.ContainsFunc(slice, func(item int) bool {
    return item > 10
}) {
    // do something
}
IndexOf

Before:

idx := lo.IndexOf(slice, target)

After:

idx := slices.Index(slice, target)
Min

Before:

min := lo.Min(slice)

After:

min := slices.Min(slice)
MinBy

Before:

min := lo.MinBy(slice, func(a, b int) bool {
    return a < b
})

After:

min := slices.MinFunc(slice, func(a, b int) int {
    return cmp.Compare(a, b)
})
Max

Before:

max := lo.Max(slice)

After:

max := slices.Max(slice)
MaxBy

Before:

max := lo.MaxBy(slice, func(a, b int) bool {
    return a > b
})

After:

max := slices.MaxFunc(slice, func(a, b int) int {
    return cmp.Compare(a, b)
})
IsSorted

Before:

if lo.IsSorted(slice) {
    // do something
}

After:

if slices.IsSorted(slice) {
    // do something
}
IsSortedByKey

Before:

sorted := lo.IsSortedByKey(slice, func(a string) string {
	return a
})

After:

sorted := slices.IsSortedFunc(slice, func(a, next string) int {
	return cmp.Compare(a, next)
})
Flatten

Before:

flattened := lo.Flatten(sliceOfSlices)

After:

flattened := slices.Concat(sliceOfSlices...)
Keys

Before:

keys := lo.Keys(m)

After:

keys := maps.Keys(m)
Values

Before:

values := lo.Values(m)

After:

values := maps.Values(m)
CoalesceOrEmpty

Before:

result := lo.CoalesceOrEmpty(s1, s2, s3)

After:

result := cmp.Or(s1, s2, s3)
RuneLength

Before:

n := lo.RuneLength(s)

After:

n := utf8.RuneCountInString(s)
github.com/samber/lo/mutable
Reverse

Before:

lo.Reverse(slice)

After:

slices.Reverse(slice)

Documentation

Overview

Package stdlib detects uses of functions that can be replaced by the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAnalyzer

func NewAnalyzer() *analysis.Analyzer

NewAnalyzer creates a new analyzer that detects uses of functions that can be replaced by standard library functions.

Types

This section is empty.

Directories

Path Synopsis
cmd
stdlib
Package main contains the stdlib command.
Package main contains the stdlib command.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL