From f45d5df211489e7fa65e61928a0179f8a12f1001 Mon Sep 17 00:00:00 2001 From: Johan Brandhorst Date: Tue, 17 Sep 2019 12:24:06 +0100 Subject: [PATCH] internal/lsp/source: add sortslice analyzer The sortslice analyzer warns the user when they're using a non-slice parameter to sort.Slice. It can also suggest fixes for 3 different cases of misuse: 1. The parameter is a pointer to a slice. 2. The parameter is an array 3. The parameter is a function with no arguments that returns a slice. Change-Id: If6327b19ab3c476cf17ca3c5fd75bc43bb8683e9 Reviewed-on: https://go-review.googlesource.com/c/tools/+/195898 Run-TryBot: Johan Brandhorst TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/source/diagnostics.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/lsp/source/diagnostics.go b/internal/lsp/source/diagnostics.go index 2e5306b177..6271dba523 100644 --- a/internal/lsp/source/diagnostics.go +++ b/internal/lsp/source/diagnostics.go @@ -26,6 +26,7 @@ import ( "golang.org/x/tools/go/analysis/passes/nilfunc" "golang.org/x/tools/go/analysis/passes/printf" "golang.org/x/tools/go/analysis/passes/shift" + "golang.org/x/tools/go/analysis/passes/sortslice" "golang.org/x/tools/go/analysis/passes/stdmethods" "golang.org/x/tools/go/analysis/passes/structtag" "golang.org/x/tools/go/analysis/passes/tests" @@ -355,6 +356,8 @@ var Analyzers = []*analysis.Analyzer{ unreachable.Analyzer, unsafeptr.Analyzer, unusedresult.Analyzer, + // Non-vet analyzers + sortslice.Analyzer, } func runAnalyses(ctx context.Context, view View, cph CheckPackageHandle, disabledAnalyses map[string]struct{}, report func(a *analysis.Analyzer, diag analysis.Diagnostic) error) error {