diff --git a/gopls/doc/analyzers.md b/gopls/doc/analyzers.md index c6893a6be3a..8f470e25d25 100644 --- a/gopls/doc/analyzers.md +++ b/gopls/doc/analyzers.md @@ -141,10 +141,14 @@ buildtag analyzer. ## **embed** -check for //go:embed directive import +check //go:embed directive usage -This analyzer checks that the embed package is imported when source code contains //go:embed comment directives. -The embed package must be imported for //go:embed directives to function.import _ "embed". +This analyzer checks that the embed package is imported if //go:embed +directives are present, providing a suggested fix to add the import if +it is missing. + +This analyzer also checks that //go:embed directives precede the +declaration of a single variable. **Enabled by default.** diff --git a/gopls/internal/lsp/analysis/embeddirective/embeddirective.go b/gopls/internal/lsp/analysis/embeddirective/embeddirective.go index 8cc4ea57443..b7efe4753d4 100644 --- a/gopls/internal/lsp/analysis/embeddirective/embeddirective.go +++ b/gopls/internal/lsp/analysis/embeddirective/embeddirective.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Package embeddirective defines an Analyzer that validates //go:embed directives. -// The analyzer defers fixes to it's parent source.Analyzer. +// The analyzer defers fixes to its parent source.Analyzer. package embeddirective import ( @@ -14,10 +14,14 @@ import ( "golang.org/x/tools/go/analysis" ) -const Doc = `check for //go:embed directive import +const Doc = `check //go:embed directive usage -This analyzer checks that the embed package is imported when source code contains //go:embed comment directives. -The embed package must be imported for //go:embed directives to function.import _ "embed".` +This analyzer checks that the embed package is imported if //go:embed +directives are present, providing a suggested fix to add the import if +it is missing. + +This analyzer also checks that //go:embed directives precede the +declaration of a single variable.` var Analyzer = &analysis.Analyzer{ Name: "embed", diff --git a/gopls/internal/lsp/source/api_json.go b/gopls/internal/lsp/source/api_json.go index 60103b0a1b2..153cb7d6e9a 100644 --- a/gopls/internal/lsp/source/api_json.go +++ b/gopls/internal/lsp/source/api_json.go @@ -280,7 +280,7 @@ var GeneratedAPIJSON = &APIJSON{ }, { Name: "\"embed\"", - Doc: "check for //go:embed directive import\n\nThis analyzer checks that the embed package is imported when source code contains //go:embed comment directives.\nThe embed package must be imported for //go:embed directives to function.import _ \"embed\".", + Doc: "check //go:embed directive usage\n\nThis analyzer checks that the embed package is imported if //go:embed\ndirectives are present, providing a suggested fix to add the import if\nit is missing.\n\nThis analyzer also checks that //go:embed directives precede the\ndeclaration of a single variable.", Default: "true", }, { @@ -979,7 +979,7 @@ var GeneratedAPIJSON = &APIJSON{ }, { Name: "embed", - Doc: "check for //go:embed directive import\n\nThis analyzer checks that the embed package is imported when source code contains //go:embed comment directives.\nThe embed package must be imported for //go:embed directives to function.import _ \"embed\".", + Doc: "check //go:embed directive usage\n\nThis analyzer checks that the embed package is imported if //go:embed\ndirectives are present, providing a suggested fix to add the import if\nit is missing.\n\nThis analyzer also checks that //go:embed directives precede the\ndeclaration of a single variable.", Default: true, }, {