On Sunday, January 26, 2020 at 1:49:15 PM UTC+11, Shane H wrote:
>
> Hi all, I'm trying to learn how to write a linter (because long weekend, 
> etc)
>
> I looked at Fatih's very fine blog post (
> https://arslan.io/2019/06/13/using-go-analysis-to-write-a-custom-linter/) 
> as well as the one that precedes it, although I was a LOT lost reading that 
> one.
>
> Copying and pasting 
> https://github.com/fatih/addlint/blob/master/addcheck/addcheck.go got me 
> started, but the linter I have in mind needs to see strings, a trip to 
> https://golang.org/src/go/token/token.go and 
> https://golang.org/src/go/ast/ast.go showed me the possibilities. This  
> (fortunately?) made me switch priorities slightly, as I now want to write 
> something that is going to print each and every node (and this is where my 
> problems began).
>
> I used Fatih's run and render functions but discovered that an error is 
> being generated for the Doc comment, and I cannot see *why* 
> (ast.CommentGroup is fine in parts of the code.. except for `func (p 
> *printer) printNode(node interface{}) error`
>  (https://golang.org/src/go/printer/printer.go 
> <https://golang.org/src/go/printer/printer.go> line 1073), the format 
> node section (lines 1125 - 1155) take me to the unsupported label, which 
> generates an error
>
> My code (main.go, lencheck.go, and complete output can be found at 
> https://play.golang.org/p/olvJ64EDdKZ, please excuse the length of the 
> paste, I put *everything* in there)
>
> As you can see in my code there are 4 nodes that throw errors, and I don't 
> understand if 1) that is intended or 2) I am doing (or not doing as the 
> case may be) something to cause the issue.
>
>  Any help/pointers appreciated
>

I've ended up writing my own print method, that prints the text for the 
given node. I'm not 100% sure why the format node function is needed for 
certain nodes, but I also realised I could just print the comments out in 
my code fairly easily.

The reason I need to do it is because the first phase of writing my tool is 
'seeing' what the code is seeing, and reacting to.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/86889841-9f6a-46b3-9ff6-9aae231cfdf4%40googlegroups.com.

Reply via email to