-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add exptostd linter #5259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add exptostd linter #5259
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package exptostd | ||
|
||
import ( | ||
"github.com/ldez/exptostd" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/goanalysis" | ||
) | ||
|
||
func New() *goanalysis.Linter { | ||
a := exptostd.NewAnalyzer() | ||
|
||
return goanalysis.NewLinter( | ||
a.Name, | ||
a.Doc, | ||
[]*analysis.Analyzer{a}, | ||
nil, | ||
).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package exptostd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golangci/golangci-lint/test/testshared/integration" | ||
) | ||
|
||
func TestFromTestdata(t *testing.T) { | ||
integration.RunTestdata(t) | ||
} | ||
|
||
func TestFix(t *testing.T) { | ||
integration.RunFix(t) | ||
} | ||
|
||
func TestFixPathPrefix(t *testing.T) { | ||
integration.RunFixPathPrefix(t) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//golangcitest:args -Eexptostd | ||
package testdata | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/exp/maps" // want `Import statement 'golang.org/x/exp/maps' can be replaced by 'maps'` | ||
"golang.org/x/exp/slices" // want `Import statement 'golang.org/x/exp/slices' can be replaced by 'slices'` | ||
) | ||
|
||
func _(m, a map[string]string) { | ||
maps.Clone(m) // want `golang.org/x/exp/maps.Clone\(\) can be replaced by maps.Clone\(\)` | ||
ldez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
maps.Equal(m, a) // want `golang.org/x/exp/maps.Equal\(\) can be replaced by maps.Equal\(\)` | ||
|
||
maps.EqualFunc(m, a, func(i, j string) bool { // want `golang.org/x/exp/maps.EqualFunc\(\) can be replaced by maps.EqualFunc\(\)` | ||
return true | ||
}) | ||
|
||
maps.Copy(m, a) // want `golang.org/x/exp/maps.Copy\(\) can be replaced by maps.Copy\(\)` | ||
|
||
maps.DeleteFunc(m, func(_, _ string) bool { // want `golang.org/x/exp/maps.DeleteFunc\(\) can be replaced by maps.DeleteFunc\(\)` | ||
return true | ||
}) | ||
|
||
maps.Clear(m) // want `golang.org/x/exp/maps.Clear\(\) can be replaced by clear\(\)` | ||
|
||
fmt.Println("Hello") | ||
} | ||
|
||
func _(a, b []string) { | ||
slices.Equal(a, b) | ||
slices.EqualFunc(a, b, func(_ string, _ string) bool { | ||
return true | ||
}) | ||
slices.Compare(a, b) | ||
slices.CompareFunc(a, b, func(_ string, _ string) int { | ||
return 0 | ||
}) | ||
slices.Index(a, "a") | ||
slices.IndexFunc(a, func(_ string) bool { | ||
return true | ||
}) | ||
slices.Contains(a, "a") | ||
slices.ContainsFunc(a, func(_ string) bool { | ||
return true | ||
}) | ||
slices.Insert(a, 0, "a", "b") | ||
slices.Delete(a, 0, 1) | ||
slices.DeleteFunc(a, func(_ string) bool { | ||
return true | ||
}) | ||
slices.Replace(a, 0, 1, "a") | ||
slices.Clone(a) | ||
slices.Compact(a) | ||
slices.CompactFunc(a, func(_ string, _ string) bool { | ||
return true | ||
}) | ||
slices.Grow(a, 2) | ||
slices.Clip(a) | ||
slices.Reverse(a) | ||
slices.Sort(a) | ||
slices.SortFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.SortStableFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.IsSorted(a) | ||
slices.IsSortedFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.Min(a) | ||
slices.MinFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.Max(a) | ||
slices.MaxFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.BinarySearch(a, "a") | ||
slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { | ||
return 0 | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
//golangcitest:args -Eexptostd | ||
package testdata | ||
|
||
/* | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
void myprint(char* s) { | ||
printf("%d\n", s); | ||
} | ||
*/ | ||
import "C" | ||
|
||
import ( | ||
"fmt" | ||
"unsafe" | ||
|
||
"golang.org/x/exp/maps" // want `Import statement 'golang.org/x/exp/maps' can be replaced by 'maps'` | ||
"golang.org/x/exp/slices" // want `Import statement 'golang.org/x/exp/slices' can be replaced by 'slices'` | ||
) | ||
|
||
func _() { | ||
cs := C.CString("Hello from stdio\n") | ||
C.myprint(cs) | ||
C.free(unsafe.Pointer(cs)) | ||
} | ||
|
||
func _(m, a map[string]string) { | ||
maps.Clone(m) // want `golang.org/x/exp/maps.Clone\(\) can be replaced by maps.Clone\(\)` | ||
|
||
maps.Equal(m, a) // want `golang.org/x/exp/maps.Equal\(\) can be replaced by maps.Equal\(\)` | ||
|
||
maps.EqualFunc(m, a, func(i, j string) bool { // want `golang.org/x/exp/maps.EqualFunc\(\) can be replaced by maps.EqualFunc\(\)` | ||
return true | ||
}) | ||
|
||
maps.Copy(m, a) // want `golang.org/x/exp/maps.Copy\(\) can be replaced by maps.Copy\(\)` | ||
|
||
maps.DeleteFunc(m, func(_, _ string) bool { // want `golang.org/x/exp/maps.DeleteFunc\(\) can be replaced by maps.DeleteFunc\(\)` | ||
return true | ||
}) | ||
|
||
maps.Clear(m) // want `golang.org/x/exp/maps.Clear\(\) can be replaced by clear\(\)` | ||
|
||
fmt.Println("Hello") | ||
} | ||
|
||
func _(a, b []string) { | ||
slices.Equal(a, b) | ||
slices.EqualFunc(a, b, func(_ string, _ string) bool { | ||
return true | ||
}) | ||
slices.Compare(a, b) | ||
slices.CompareFunc(a, b, func(_ string, _ string) int { | ||
return 0 | ||
}) | ||
slices.Index(a, "a") | ||
slices.IndexFunc(a, func(_ string) bool { | ||
return true | ||
}) | ||
slices.Contains(a, "a") | ||
slices.ContainsFunc(a, func(_ string) bool { | ||
return true | ||
}) | ||
slices.Insert(a, 0, "a", "b") | ||
slices.Delete(a, 0, 1) | ||
slices.DeleteFunc(a, func(_ string) bool { | ||
return true | ||
}) | ||
slices.Replace(a, 0, 1, "a") | ||
slices.Clone(a) | ||
slices.Compact(a) | ||
slices.CompactFunc(a, func(_ string, _ string) bool { | ||
return true | ||
}) | ||
slices.Grow(a, 2) | ||
slices.Clip(a) | ||
slices.Reverse(a) | ||
slices.Sort(a) | ||
slices.SortFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.SortStableFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.IsSorted(a) | ||
slices.IsSortedFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.Min(a) | ||
slices.MinFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.Max(a) | ||
slices.MaxFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.BinarySearch(a, "a") | ||
slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { | ||
return 0 | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//go:build go1.23 | ||
|
||
//golangcitest:args -Eexptostd | ||
package testdata | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/exp/maps" // want `Import statement 'golang.org/x/exp/maps' can be replaced by 'maps'` | ||
"golang.org/x/exp/slices" // want `Import statement 'golang.org/x/exp/slices' can be replaced by 'slices'` | ||
) | ||
|
||
func _(m, a map[string]string) { | ||
maps.Clone(m) // want `golang.org/x/exp/maps.Clone\(\) can be replaced by maps.Clone\(\)` | ||
|
||
maps.Keys(m) // want `golang.org/x/exp/maps.Keys\(\) can be replaced by slices.Collect\(maps.Keys\(\)\)` | ||
|
||
maps.Values(m) // want `golang.org/x/exp/maps.Values\(\) can be replaced by slices.Collect\(maps.Values\(\)\)` | ||
|
||
maps.Equal(m, a) // want `golang.org/x/exp/maps.Equal\(\) can be replaced by maps.Equal\(\)` | ||
|
||
maps.EqualFunc(m, a, func(i, j string) bool { // want `golang.org/x/exp/maps.EqualFunc\(\) can be replaced by maps.EqualFunc\(\)` | ||
return true | ||
}) | ||
|
||
maps.Copy(m, a) // want `golang.org/x/exp/maps.Copy\(\) can be replaced by maps.Copy\(\)` | ||
|
||
maps.DeleteFunc(m, func(_, _ string) bool { // want `golang.org/x/exp/maps.DeleteFunc\(\) can be replaced by maps.DeleteFunc\(\)` | ||
return true | ||
}) | ||
|
||
maps.Clear(m) // want `golang.org/x/exp/maps.Clear\(\) can be replaced by clear\(\)` | ||
|
||
fmt.Println("Hello") | ||
} | ||
|
||
func _(a, b []string) { | ||
slices.Equal(a, b) | ||
slices.EqualFunc(a, b, func(_ string, _ string) bool { | ||
return true | ||
}) | ||
slices.Compare(a, b) | ||
slices.CompareFunc(a, b, func(_ string, _ string) int { | ||
return 0 | ||
}) | ||
slices.Index(a, "a") | ||
slices.IndexFunc(a, func(_ string) bool { | ||
return true | ||
}) | ||
slices.Contains(a, "a") | ||
slices.ContainsFunc(a, func(_ string) bool { | ||
return true | ||
}) | ||
slices.Insert(a, 0, "a", "b") | ||
slices.Delete(a, 0, 1) | ||
slices.DeleteFunc(a, func(_ string) bool { | ||
return true | ||
}) | ||
slices.Replace(a, 0, 1, "a") | ||
slices.Clone(a) | ||
slices.Compact(a) | ||
slices.CompactFunc(a, func(_ string, _ string) bool { | ||
return true | ||
}) | ||
slices.Grow(a, 2) | ||
slices.Clip(a) | ||
slices.Reverse(a) | ||
slices.Sort(a) | ||
slices.SortFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.SortStableFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.IsSorted(a) | ||
slices.IsSortedFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.Min(a) | ||
slices.MinFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.Max(a) | ||
slices.MaxFunc(a, func(_, _ string) int { | ||
return 0 | ||
}) | ||
slices.BinarySearch(a, "a") | ||
slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { | ||
return 0 | ||
}) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.