Module:Sandbox/Aidan9382/CodeAnalysis/doc: Difference between revisions
update for template entry point |
notes |
||
Line 7: | Line 7: | ||
== Usage == |
== Usage == |
||
This module can be required and used from the Debug console, like the following: <syntaxhighlight lang=lua inline>require("Module:Sandbox/Aidan9382/CodeAnalysis") |
This module can be required and used from the Debug console, like the following: <syntaxhighlight lang=lua inline>require("Module:Sandbox/Aidan9382/CodeAnalysis")()</syntaxhighlight> (The module entry point can be accessed directly without calling it via <code>.run</code>). The module will then log any behaviour it notices. The function can be provided an argument to specify a target page other than the current page. Valid inputs are the name of the wanted page as a string, or the mw.title object of the wanted page. |
||
This module can also be used via templates using <code>#invoke:</code>, like the following: <syntaxhighlight lang=wikitext inline>{{#invoke:Sandbox/Aidan9382/CodeAnalysis|main}}</syntaxhighlight>. The module will then produce a wikitable of anything it notes within the code. An argument can be provided to the first positional parameter to specify a certain page to analyse. |
This module can also be used via templates using <code>#invoke:</code>, like the following: <syntaxhighlight lang=wikitext inline>{{#invoke:Sandbox/Aidan9382/CodeAnalysis|main}}</syntaxhighlight>. The module will then produce a wikitable of anything it notes within the code. An argument can be provided to the first positional parameter to specify a certain page to analyse. |
Revision as of 11:41, 12 May 2023
This function provides basic analysis of module code, pointing out any unused variables or unexpected globals.
The code of this is mostly lifted from https://github.com/9382/Dump/tree/main/LuaObfuscator, which in turn lifts a lot of code from https://github.com/stravant/LuaMinify.
Usage
This module can be required and used from the Debug console, like the following: require("Module:Sandbox/Aidan9382/CodeAnalysis")()
(The module entry point can be accessed directly without calling it via .run
). The module will then log any behaviour it notices. The function can be provided an argument to specify a target page other than the current page. Valid inputs are the name of the wanted page as a string, or the mw.title object of the wanted page.
This module can also be used via templates using #invoke:
, like the following: {{#invoke:Sandbox/Aidan9382/CodeAnalysis|main}}
. The module will then produce a wikitable of anything it notes within the code. An argument can be provided to the first positional parameter to specify a certain page to analyse.
Examples
Basic code analysis for Module:Sandbox/Aidan9382/CodeAnalysis | |
---|---|
Scope | Message |
Scope starting line 124 | i is defined but never referenced
|
Entire script | 9 local variables called _ were defined but never referenced, likely intentionally
|
Entire script | Global variable print was referenced or defined, yet isn't a standard global
|
Basic code analysis for Module:Wikitext Parsing | |
---|---|
Scope | Message |
Main scope | startswith is defined but never referenced
|
Scope starting line 404 | Variable _ is referenced, despite the name implying it is unused
|
Entire script | 3 local variables called _ were defined but never referenced, likely intentionally
|