Skip to content

Commit 3a3c169

Browse files
vikblomfindleyr
authored andcommitted
gopls/internal/lsp/source: refresh embeddirective analyzer docs
Bring the analyzer documentation up to speed. Include the recently added feature to check the declaration following the directive. Also fix typo in package comment. Updates golang/go#50262 Change-Id: I0e7a8de0ba10cd414251afe1e9c65ded2090f408 Reviewed-on: https://go-review.googlesource.com/c/tools/+/513895 Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> gopls-CI: kokoro <[email protected]>
1 parent 03562de commit 3a3c169

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

gopls/doc/analyzers.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,14 @@ buildtag analyzer.
141141

142142
## **embed**
143143

144-
check for //go:embed directive import
144+
check //go:embed directive usage
145145

146-
This analyzer checks that the embed package is imported when source code contains //go:embed comment directives.
147-
The embed package must be imported for //go:embed directives to function.import _ "embed".
146+
This analyzer checks that the embed package is imported if //go:embed
147+
directives are present, providing a suggested fix to add the import if
148+
it is missing.
149+
150+
This analyzer also checks that //go:embed directives precede the
151+
declaration of a single variable.
148152

149153
**Enabled by default.**
150154

gopls/internal/lsp/analysis/embeddirective/embeddirective.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
// Package embeddirective defines an Analyzer that validates //go:embed directives.
6-
// The analyzer defers fixes to it's parent source.Analyzer.
6+
// The analyzer defers fixes to its parent source.Analyzer.
77
package embeddirective
88

99
import (
@@ -14,10 +14,14 @@ import (
1414
"golang.org/x/tools/go/analysis"
1515
)
1616

17-
const Doc = `check for //go:embed directive import
17+
const Doc = `check //go:embed directive usage
1818
19-
This analyzer checks that the embed package is imported when source code contains //go:embed comment directives.
20-
The embed package must be imported for //go:embed directives to function.import _ "embed".`
19+
This analyzer checks that the embed package is imported if //go:embed
20+
directives are present, providing a suggested fix to add the import if
21+
it is missing.
22+
23+
This analyzer also checks that //go:embed directives precede the
24+
declaration of a single variable.`
2125

2226
var Analyzer = &analysis.Analyzer{
2327
Name: "embed",

gopls/internal/lsp/source/api_json.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)