go/analysis: doc: explain how to report diagnostics in raw text files
Change-Id: I6b31e6f4b61948e459faf5a1ada18de69741b947
Reviewed-on: https://go-review.googlesource.com/c/143299
Reviewed-by: Michael Matloob <matloob@golang.org>
diff --git a/go/analysis/doc.go b/go/analysis/doc.go
index 5f96774a..7ea7807 100644
--- a/go/analysis/doc.go
+++ b/go/analysis/doc.go
@@ -205,6 +205,18 @@
The optional Category field is a short identifier that classifies the
kind of message when an analysis produces several kinds of diagnostic.
+Most Analyzers inspect typed Go syntax trees, but a few, such as asmdecl
+and buildtag, inspect the raw text of Go source files or even non-Go
+files such as assembly. To report a diagnostic against a line of a
+raw text file, use the following sequence:
+
+ content, err := ioutil.ReadFile(filename)
+ if err != nil { ... }
+ tf := fset.AddFile(filename, -1, len(content))
+ tf.SetLinesForContent(content)
+ ...
+ pass.Reportf(tf.LineStart(line), "oops")
+
Modular analysis with Facts