From 258e47306680682e73d2b873b69fe7e616ae5490 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Tue, 22 Feb 2022 10:07:30 -0500 Subject: [PATCH] internal/lsp/source: disable the useany analyzer by default This analyzer was written at a time when any was only allowed in constraints, and usage of any vs interface{} was more likely to be confusing. Any is now allowed anywhere, and so it is inconsistent to suggest it only for constraints. However, we can't suggest any over interface{} everywhere, as that would be incredibly noisy. Perhaps we should remove this analyzer, but for now simply change it to off by default. Change-Id: Ib9726bdb835808d69827c6cd8e4a58dc5d83ad0e Reviewed-on: https://go-review.googlesource.com/c/tools/+/387614 Trust: Robert Findley Run-TryBot: Robert Findley gopls-CI: kokoro TryBot-Result: Gopher Robot Reviewed-by: Hyang-Ah Hana Kim --- gopls/doc/analyzers.md | 2 +- internal/lsp/source/api_json.go | 7 +++---- internal/lsp/source/options.go | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/gopls/doc/analyzers.md b/gopls/doc/analyzers.md index 121fa4964d..07f846db84 100644 --- a/gopls/doc/analyzers.md +++ b/gopls/doc/analyzers.md @@ -574,7 +574,7 @@ Another example is about non-pointer receiver: check for constraints that could be simplified to "any" -**Enabled by default.** +**Disabled by default. Enable it by setting `"analyses": {"useany": true}`.** ## **fillreturns** diff --git a/internal/lsp/source/api_json.go b/internal/lsp/source/api_json.go index 4742fb11f4..9af5bd64dd 100755 --- a/internal/lsp/source/api_json.go +++ b/internal/lsp/source/api_json.go @@ -406,7 +406,7 @@ var GeneratedAPIJSON = &APIJSON{ { Name: "\"useany\"", Doc: "check for constraints that could be simplified to \"any\"", - Default: "true", + Default: "false", }, { Name: "\"fillreturns\"", @@ -922,9 +922,8 @@ var GeneratedAPIJSON = &APIJSON{ Doc: "checks for unused writes\n\nThe analyzer reports instances of writes to struct fields and\narrays that are never read. Specifically, when a struct object\nor an array is copied, its elements are copied implicitly by\nthe compiler, and any element write to this copy does nothing\nwith the original object.\n\nFor example:\n\n\ttype T struct { x int }\n\tfunc f(input []T) {\n\t\tfor i, v := range input { // v is a copy\n\t\t\tv.x = i // unused write to field x\n\t\t}\n\t}\n\nAnother example is about non-pointer receiver:\n\n\ttype T struct { x int }\n\tfunc (t T) f() { // t is a copy\n\t\tt.x = i // unused write to field x\n\t}\n", }, { - Name: "useany", - Doc: "check for constraints that could be simplified to \"any\"", - Default: true, + Name: "useany", + Doc: "check for constraints that could be simplified to \"any\"", }, { Name: "fillreturns", diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go index 139ae7004d..c7c6228ad2 100644 --- a/internal/lsp/source/options.go +++ b/internal/lsp/source/options.go @@ -694,8 +694,8 @@ func (o *Options) Clone() *Options { ClientOptions: o.ClientOptions, InternalOptions: o.InternalOptions, Hooks: Hooks{ - GoDiff: o.Hooks.GoDiff, - ComputeEdits: o.Hooks.ComputeEdits, + GoDiff: o.GoDiff, + ComputeEdits: o.ComputeEdits, GofumptFormat: o.GofumptFormat, URLRegexp: o.URLRegexp, }, @@ -1265,7 +1265,7 @@ func defaultAnalyzers() map[string]*Analyzer { testinggoroutine.Analyzer.Name: {Analyzer: testinggoroutine.Analyzer, Enabled: true}, unusedparams.Analyzer.Name: {Analyzer: unusedparams.Analyzer, Enabled: false}, unusedwrite.Analyzer.Name: {Analyzer: unusedwrite.Analyzer, Enabled: false}, - useany.Analyzer.Name: {Analyzer: useany.Analyzer, Enabled: true}, + useany.Analyzer.Name: {Analyzer: useany.Analyzer, Enabled: false}, infertypeargs.Analyzer.Name: {Analyzer: infertypeargs.Analyzer, Enabled: true}, // gofmt -s suite: