A macro to inspect global variables used in a function?

Note that @code_warntype will show any type instability in red. This implies that if you have included any global variable, the result will include some red line.

In case your question is more general about forgetting to add variables, it’s probably a symptom that you have long functions. This means that if you have long functions, it’s probably better if you split them into smaller functions.
Overall, it’s always recommend to have self contained functions. As for parameters, you can handle them by having a tuple of them that you unpack in the first line of the function. Alternatively, you could define the parameters globally as const if you know they won’t change their value.

edit: maybe this package that forces you to write stable functions can be helpful?