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>
This commit is contained in:
Alan Donovan 2018-10-18 22:10:33 -04:00
parent 8dacc032e7
commit 4805105a3a
1 changed files with 12 additions and 0 deletions

View File

@ -205,6 +205,18 @@ Diagnostic is defined as:
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