Skip to content

Commit

Permalink
0.4.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterv committed May 31, 2014
1 parent 5bd474e commit 1aebb20
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 33 deletions.
56 changes: 40 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
luacheck is a simple static analyzer for Lua. It only looks for three things:

* non-standard global variables;
* unused local variables(except variable named `_`, which should be used as placeholder when avoiding an unused variable is impossible);
* unused local variables(except variable named `_`, which should be used as placeholder when avoiding an unused variable is impossible) and values;
* redefinitions of existing local variables in the same scope(e.g. `local a = 5; ... local a = 6`).

luacheck provides a command-line interface as well as a small library which can be used from another Lua program.
Expand Down Expand Up @@ -33,11 +33,12 @@ $ luacheck --help
```

```
Usage: luacheck [-g] [-r] [-u] [-a] [--globals [<global>] ...] [-c]
[-e] [--ignore <var> [<var>] ...] [--only <var> [<var>] ...]
[-l <limit>] [-q] [-h] <file> [<file>] ...
Usage: luacheck [-g] [-r] [-u] [-a] [-v] [--globals [<global>] ...]
[-c] [-e] [--ignore <var> [<var>] ...]
[--only <var> [<var>] ...] [-l <limit>] [-q] [-h]
<file> [<file>] ...
luacheck 0.3.0, a simple static analyzer for Lua.
luacheck 0.4.0, a simple static analyzer for Lua.
Arguments:
files List of files to check.
Expand All @@ -47,6 +48,8 @@ Options:
-r, --no-redefined Do not check for redefined variables.
-u, --no-unused Do not check for unused variables.
-a, --no-unused-args Do not check for unused arguments and loop variables.
-v, --no-unused-values
Do not check for unused values.
--globals [<global>] ...
Defined globals. Hyphen expands to standard globals.
-c, --compat Adjust globals for Lua 5.1/5.2 compatibility.
Expand All @@ -71,16 +74,25 @@ $ luacheck *.lua
Checking bad_code.lua Failure
bad_code.lua:3:16: unused variable helper
bad_code.lua:3:23: unused variable length argument
bad_code.lua:7:10: setting non-standard global variable embrace
bad_code.lua:8:10: variable opt was previously defined as an argument on line 7
bad_code.lua:9:11: accessing undefined variable hepler
Checking good_code.lua OK
Checking python_code.lua Syntax error
Total: 4 warnings / 1 error
Total: 5 warnings / 1 error in 3 files
```

In CLI, rockspecs(arguments ending with `.rockspec`) expand into `.lua` files mentioned in them, so that

```bash
$ luacheck path/to/rockspec/rockname-1.0-1.rockspec
```

is a shortcut for checking all `rockname`-related files.

CLI exits with `0` if no warnings or errors occured and with `1` otherwise.

## luacheck module
Expand All @@ -93,8 +105,9 @@ If the second argument is provided, it should be a table of options. Recognized

* `options.check_global` - should luacheck check for global access? Default: `true`.
* `options.check_redefined` - should luacheck check for redefined locals? Default: `true`.
* `options.check_unused` - should luacheck check for unused locals? Default: `true`.
* `options.check_unused` - should luacheck check for unused locals and values? Default: `true`.
* `options.check_unused_args` - should luacheck check for unused arguments and loop variables? Default: `true`.
* `options.check_unused_values` - should luacheck check for unused values? Default: `true`.
* `options.globals` - set of standard globals. Default: `_G`.
* `options.env_aware` - ignore globals is chunks with custom `_ENV`. Default: `true`.
* `options.ignore` - set of variables to ignore. Default: empty. Takes precedense over `options.only`.
Expand All @@ -109,6 +122,7 @@ report: {
global = <total number of warnings related to global variables>,
redefined = <total number of warnings related to redefined variables>,
unused = <total number of warnings related to unused variables>,
unused_value = <total number of warnings related to unused values>,
<file_report>, <file_report>, ...
}
Expand All @@ -118,15 +132,16 @@ file_report: {
global = <number of warnings related to global variables in this file>,
redefined = <number of warnings related to redefined variables in this file>,
unused = <number of warnings related to unused variables in this file>,
unused_value = <number of warnings related to unused values in this file>,
<warning>, <warning>, ...
} | {
file = <path to this file>,
error = "I/O" | "syntax"
}
warning: {
type = "global" | "redefined" | "unused",
subtype = "read" | "write" | "var" | "arg" | "loop",
type = "global" | "redefined" | "unused" | "unused_value",
subtype = "access" | "set" | "var" | "arg" | "loop" | "vararg",
name = <name of the related variable>,
line = <number of the line where the problem occured>,
column = <offset of the variable name in that line>,
Expand All @@ -150,11 +165,17 @@ prettyprint(report)
name = "helper",
subtype = "var",
type = "unused"
}, {
column = 23,
line = 3,
name = "...",
subtype = "vararg",
type = "unused"
}, {
column = 10,
line = 7,
name = "embrace",
subtype = "write",
subtype = "set",
type = "global"
}, {
column = 10,
Expand All @@ -168,29 +189,32 @@ prettyprint(report)
column = 11,
line = 9,
name = "hepler",
subtype = "read",
subtype = "access",
type = "global"
},
file = "bad_code.lua",
global = 2,
redefined = 1,
total = 4,
unused = 1
total = 5,
unused = 2,
unused_value = 0
}, {
file = "good_code.lua",
global = 0,
redefined = 0,
total = 0,
unused = 0
unused = 0,
unused_value = 0
}, {
error = "syntax",
file = "python_code.lua"
},
errors = 1,
global = 2,
redefined = 1,
total = 4,
unused = 1
total = 5,
unused = 2,
unused_value = 0
}
```

Expand Down
56 changes: 40 additions & 16 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1>

<ul>
<li>non-standard global variables; </li>
<li>unused local variables(except variable named <code>_</code>, which should be used as placeholder when avoiding an unused variable is impossible); </li>
<li>unused local variables(except variable named <code>_</code>, which should be used as placeholder when avoiding an unused variable is impossible) and values; </li>
<li>redefinitions of existing local variables in the same scope(e.g. <code>local a = 5; ... local a = 6</code>). </li>
</ul><p>luacheck provides a command-line interface as well as a small library which can be used from another Lua program. </p>

Expand All @@ -61,11 +61,12 @@ <h2>
<div class="highlight highlight-bash"><pre><span class="nv">$ </span>luacheck --help
</pre></div>

<pre><code>Usage: luacheck [-g] [-r] [-u] [-a] [--globals [&lt;global&gt;] ...] [-c]
[-e] [--ignore &lt;var&gt; [&lt;var&gt;] ...] [--only &lt;var&gt; [&lt;var&gt;] ...]
[-l &lt;limit&gt;] [-q] [-h] &lt;file&gt; [&lt;file&gt;] ...
<pre><code>Usage: luacheck [-g] [-r] [-u] [-a] [-v] [--globals [&lt;global&gt;] ...]
[-c] [-e] [--ignore &lt;var&gt; [&lt;var&gt;] ...]
[--only &lt;var&gt; [&lt;var&gt;] ...] [-l &lt;limit&gt;] [-q] [-h]
&lt;file&gt; [&lt;file&gt;] ...

luacheck 0.3.0, a simple static analyzer for Lua.
luacheck 0.4.0, a simple static analyzer for Lua.

Arguments:
files List of files to check.
Expand All @@ -75,6 +76,8 @@ <h2>
-r, --no-redefined Do not check for redefined variables.
-u, --no-unused Do not check for unused variables.
-a, --no-unused-args Do not check for unused arguments and loop variables.
-v, --no-unused-values
Do not check for unused values.
--globals [&lt;global&gt;] ...
Defined globals. Hyphen expands to standard globals.
-c, --compat Adjust globals for Lua 5.1/5.2 compatibility.
Expand All @@ -97,16 +100,24 @@ <h2>
<pre><code>Checking bad_code.lua Failure

bad_code.lua:3:16: unused variable helper
bad_code.lua:3:23: unused variable length argument
bad_code.lua:7:10: setting non-standard global variable embrace
bad_code.lua:8:10: variable opt was previously defined as an argument on line 7
bad_code.lua:9:11: accessing undefined variable hepler

Checking good_code.lua OK
Checking python_code.lua Syntax error

Total: 4 warnings / 1 error
Total: 5 warnings / 1 error in 3 files
</code></pre>

<p>In CLI, rockspecs(arguments ending with <code>.rockspec</code>) expand into <code>.lua</code> files mentioned in them, so that</p>

<div class="highlight highlight-bash"><pre><span class="nv">$ </span>luacheck path/to/rockspec/rockname-1.0-1.rockspec
</pre></div>

<p>is a shortcut for checking all <code>rockname</code>-related files. </p>

<p>CLI exits with <code>0</code> if no warnings or errors occured and with <code>1</code> otherwise. </p>

<h2>
Expand All @@ -124,10 +135,12 @@ <h2>
<li>
<code>options.check_redefined</code> - should luacheck check for redefined locals? Default: <code>true</code>. </li>
<li>
<code>options.check_unused</code> - should luacheck check for unused locals? Default: <code>true</code>. </li>
<code>options.check_unused</code> - should luacheck check for unused locals and values? Default: <code>true</code>. </li>
<li>
<code>options.check_unused_args</code> - should luacheck check for unused arguments and loop variables? Default: <code>true</code>. </li>
<li>
<code>options.check_unused_values</code> - should luacheck check for unused values? Default: <code>true</code>. </li>
<li>
<code>options.globals</code> - set of standard globals. Default: <code>_G</code>. </li>
<li>
<code>options.env_aware</code> - ignore globals is chunks with custom <code>_ENV</code>. Default: <code>true</code>. </li>
Expand All @@ -143,6 +156,7 @@ <h2>
global = &lt;total number of warnings related to global variables&gt;,
redefined = &lt;total number of warnings related to redefined variables&gt;,
unused = &lt;total number of warnings related to unused variables&gt;,
unused_value = &lt;total number of warnings related to unused values&gt;,
&lt;file_report&gt;, &lt;file_report&gt;, ...
}

Expand All @@ -152,15 +166,16 @@ <h2>
global = &lt;number of warnings related to global variables in this file&gt;,
redefined = &lt;number of warnings related to redefined variables in this file&gt;,
unused = &lt;number of warnings related to unused variables in this file&gt;,
unused_value = &lt;number of warnings related to unused values in this file&gt;,
&lt;warning&gt;, &lt;warning&gt;, ...
} | {
file = &lt;path to this file&gt;,
error = "I/O" | "syntax"
}

warning: {
type = "global" | "redefined" | "unused",
subtype = "read" | "write" | "var" | "arg" | "loop",
type = "global" | "redefined" | "unused" | "unused_value",
subtype = "access" | "set" | "var" | "arg" | "loop" | "vararg",
name = &lt;name of the related variable&gt;,
line = &lt;number of the line where the problem occured&gt;,
column = &lt;offset of the variable name in that line&gt;,
Expand All @@ -182,11 +197,17 @@ <h2>
name = "helper",
subtype = "var",
type = "unused"
}, {
column = 23,
line = 3,
name = "...",
subtype = "vararg",
type = "unused"
}, {
column = 10,
line = 7,
name = "embrace",
subtype = "write",
subtype = "set",
type = "global"
}, {
column = 10,
Expand All @@ -200,29 +221,32 @@ <h2>
column = 11,
line = 9,
name = "hepler",
subtype = "read",
subtype = "access",
type = "global"
},
file = "bad_code.lua",
global = 2,
redefined = 1,
total = 4,
unused = 1
total = 5,
unused = 2,
unused_value = 0
}, {
file = "good_code.lua",
global = 0,
redefined = 0,
total = 0,
unused = 0
unused = 0,
unused_value = 0
}, {
error = "syntax",
file = "python_code.lua"
},
errors = 1,
global = 2,
redefined = 1,
total = 4,
unused = 1
total = 5,
unused = 2,
unused_value = 0
}
</code></pre>

Expand Down
40 changes: 40 additions & 0 deletions rockspecs/luacheck-0.4.0-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package = "luacheck"
version = "0.4.0-1"
source = {
url = "git://github.com/mpeterv/luacheck.git",
tag = "0.4.0"
}
description = {
summary = "A simple static analyzer",
detailed = [[
luacheck only looks for three things: non-standard global variables, unused local variables and redefinitions of existing local variables in the same scope.
luacheck provides a command-line interface as well as a small library which can be used from another Lua program.
]],
homepage = "https://github.com/mpeterv/luacheck",
license = "MIT/X11"
}
dependencies = {
"lua >= 5.1, < 5.3",
"metalua-parser >= 0.7.3-2",
"checks >= 1.0",
"argparse >= 0.2.0",
"ansicolors >= 1.0-1"
}
build = {
type = "builtin",
modules = {
luacheck = "src/luacheck.lua",
["luacheck.scan"] = "src/luacheck/scan.lua",
["luacheck.check"] = "src/luacheck/check.lua",
["luacheck.get_report"] = "src/luacheck/get_report.lua",
["luacheck.expand_rockspec"] = "src/luacheck/expand_rockspec.lua",
["luacheck.format"] = "src/luacheck/format.lua"
},
install = {
bin = {
luacheck = "bin/luacheck.lua"
}
},
copy_directories = {"spec", "doc"}
}
2 changes: 1 addition & 1 deletion src/luacheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local get_report = require "luacheck.get_report"
-- `options.check_unused` - should luacheck check for unused locals? Default: true.
-- `options.check_unused_args` - should luacheck check for unused arguments and
-- iterator variables? Default: true.
-- `options.check_unused_value` - should luacheck check for unused values? Default: true.
-- `options.check_unused_values` - should luacheck check for unused values? Default: true.
-- `options.globals` - set of standard globals. Default: _G.
-- `options.env_aware` - ignore globals is chunks with custom _ENV. Default: true.
-- `options.ignore` - set of variables to ignore. Default: empty.
Expand Down

0 comments on commit 1aebb20

Please sign in to comment.