From 4805105a3a8d777ea549f95266029c9a2b6003b9 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 18 Oct 2018 22:10:33 -0400 Subject: [PATCH] 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 --- go/analysis/doc.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/go/analysis/doc.go b/go/analysis/doc.go index 5f96774a..7ea78079 100644 --- a/go/analysis/doc.go +++ b/go/analysis/doc.go @@ -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