Skip to content

Commit

Permalink
gopls/internal/lsp/source: refresh embeddirective analyzer docs
Browse files Browse the repository at this point in the history
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 <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
  • Loading branch information
vikblom authored and findleyr committed Jul 28, 2023
1 parent 03562de commit 3a3c169
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
10 changes: 7 additions & 3 deletions gopls/doc/analyzers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**

Expand Down
12 changes: 8 additions & 4 deletions gopls/internal/lsp/analysis/embeddirective/embeddirective.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/lsp/source/api_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a3c169

Please sign in to comment.