| Age | Commit message (Collapse) | Author | 
|---|
|  | I decided I don't like the "go" prefix for a Go package name. It doesn't
make sense. Rename the module and package accordingly.
I do like the "go" prefix in the command line program, so leave it
there. | 
|  | I originally thought that I could save on the two additional
`ast.Inspect` calls in this file by using the `passes/inspect` library,
but it doesn't replace those calls. It seems to help more when you have
multiple analysers to run at once. Not sure how much it helps us here. | 
|  | I though I might need it when I first wrote the function. | 
|  | This is now handled. | 
|  | Now that the slice contains both assignment and declaration identifiers,
update the variable names to be more representative. | 
|  | Match the `varDeclarations` function splitting this into a more
self-contained block.
Also don't return in the loop to ensure we look at all assignments in
`assignStmt`. | 
|  | Declarations can include multiple identifiers. Return all of these from
the function and rename it accordingly. | 
|  | Treat these as shadowed variables and ignore them. | 
|  | * Add descriptive comments.
* Remove old in-progress code.
* Change the function name to `findLocalAssignments` which made more
  sense given what the function now does. | 
|  | In order to ignore shadowed variables, we first build a list of all
local assignments in the closure, and ignore any ident in that list. | 
|  |  | 
|  | Not working yet. Does print the right thing, but since we're also
matching `*ast.Ident`s, we must be getting the shadowed declarations as
Idents and including them in the reported diagnostics. | 
|  | We don't want to report shadowed variables. | 
|  | It doesn't need to be attached to the `funcScope` condition as it's a
separate check. Wasn't thinking carefully when I added the check. | 
|  |  | 
|  |  | 
|  |  | 
|  |  | 
|  | It's not used in `run()`, so we can move it here. | 
|  |  | 
|  | * Remove old in-progress code now that we have a working implementation.
* Add explanatory comments.
* Remove `assignmentsInFunc()` which is unused. | 
|  |  | 
|  | Remove old unused in-progress code. | 
|  |  | 
|  | Easier to use than `goStmt.Call.Args` because we don't have to handle
both `*ast.Expr` and `*ast.UnaryExpr`. | 
|  |  | 
|  | Otherwise we can get `*types.TypeName` identifiers, like the variable
types in the closure's argument list. We only want to inspect variables. | 
|  | These items don't pass our tests. | 
|  | This correctly ignores local variables. | 
|  | Report all variables declared in an outer scope.
This does match variables defined in the closure too. Will need to fix
that. | 
|  |  | 
|  |  | 
|  | For every identifier in the closure, check if it exists in an outer
scope. | 
|  |  | 
|  | If I had read the comment for `Scopes` in
https://godocs.io/go/types#Info I would have known that only a subset of
`ast.Node` can appear in the `Scopes` field. Tried ones until I ended up
with valid scopes.
Now that we have a valid scope, maybe we can find out if it's using
variables not declared within that scope. | 
|  | Just results in nil. | 
|  |  | 
|  | Discovered this existed. | 
|  | Not working, as `funcObj` is nil. | 
|  | Debugging and ideas for getting variables defined in this closure's
scope. | 
|  | Got this idea from a question by zhizhixiong
(https://stackoverflow.com/users/12073516/zhizhixiong) on Stack
Overflow:
https://stackoverflow.com/questions/66544145/how-to-find-the-declaration-of-an-ident-using-go-analysis
This seems to correctly print defines and assigns. It doesn't print the
`decl` variable though. | 
|  |  | 
|  | This field could maybe tell us whether it was a `:=` assignment
(token.DEFINE) or `=` (token.ASSIGN), but it seems like it's always
`token.DEFINE`. | 
|  | Turns out this only gets declarations like:
    var decl string
but not:
    decl := "a"
Is there a way to get the above one too? | 
|  | These should be reported as well, because they're shared references even
though they're passed as arguments.
This currently reports the variable name as "aStruct", will need to look
into how to correct that. | 
|  |  | 
|  | Turns out this isn't what we want, as assignments means assignments. I
was actually thinking of declarations. | 
|  |  | 
|  | Don't report variables that were passed as arguments to the closure. | 
|  |  |