You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/_sources/cli.txt
+18-5Lines changed: 18 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ Command line interface
5
5
6
6
* Given a file, ``luacheck`` will check it.
7
7
* Given ``-``, ``luacheck`` will check stdin.
8
-
* Given a directory, ``luacheck`` will check all files with ``.lua`` extension within it. This feature requires `luafilesystem <http://keplerproject.github.io/luafilesystem/>`_ (installed automatically if LuaRocks was used to install Luacheck).
8
+
* Given a directory, ``luacheck`` will check all files with ``.lua`` extension within it. This feature requires `LuaFileSystem <http://keplerproject.github.io/luafilesystem/>`_ (installed automatically if LuaRocks was used to install Luacheck).
9
9
* Given a rockspec (a file with ``.rockspec`` extension), ``luacheck`` will check all files with ``.lua`` extension mentioned in the rockspec in ``build.install.lua``, ``build.install.bin`` and ``build.modules`` tables.
10
10
11
11
The output of ``luacheck`` consists of separate reports for each checked file and ends with a summary::
@@ -21,6 +21,9 @@ The output of ``luacheck`` consists of separate reports for each checked file an
21
21
22
22
Checking src/good_code.lua OK
23
23
Checking src/python_code.lua Syntax error
24
+
25
+
spec/samples/python_code.lua:1:6: expected '=' near '__future__'
26
+
24
27
Checking src/unused_code.lua Failure
25
28
26
29
src/unused_code.lua:3:18: unused argument baz
@@ -55,8 +58,6 @@ Option Meaning
55
58
``-u`` | ``--no-unused`` Filter out warnings related to unused variables and values.
56
59
``-r`` | ``--no-redefined`` Filter out warnings related to redefined variables.
57
60
``-a`` | ``--no-unused-args`` Filter out warnings related to unused arguments and loop variables.
58
-
``-v`` | ``--no-unused-values`` Filter out warnings related to unused values.
59
-
``--no-unset`` Filter out warnings related to unset variables.
60
61
``-s`` | ``--no-unused-secondaries`` Filter out warnings related to unused variables set together with used ones.
61
62
62
63
See :ref:`secondaryvaluesandvariables`
@@ -91,21 +92,24 @@ Option Meaning
91
92
``--enable | -o <patt> [<patt>] ...`` Do not filter out warnings matching patterns.
92
93
``--only | -o <patt> [<patt>] ...`` Filter out warnings not matching patterns.
93
94
``--no-inline`` Disable inline options.
94
-
``-l <limit>`` | ``--limit <limit>`` Exit with 0 if there are ``<limit>`` or less warnings (default: ``0``).
95
95
``--config <config>`` Path to custom configuration file (default: ``.luacheckrc``).
96
96
``--no-config`` Do not look up custom configuration file.
97
+
``--cache [<cache>]`` Path to cache file. (default: ``.luacheckcache``). See :ref:`cache`
Unless already anchored, patterns matching variable names are anchored at both sides and patterns matching warning codes are anchored at their beginnings. This allows to filter warnings by category (e.g. ``--only 1`` focuses ``luacheck`` on global-related warnings).
132
+
127
133
Formatters
128
134
----------
129
135
130
136
CLI option ``--formatter`` allows selecting a custom formatter for ``luacheck`` output. A custom formatter is a Lua module returning a function with three arguments: report as returned by ``luacheck`` module (see :ref:`report`), array of file names and table of options. Options contain values assigned to ``quiet``, ``color``, ``limit``, ``codes`` and ``formatter`` options in CLI or config. Formatter function must return a string.
137
+
138
+
.. _cache:
139
+
140
+
Caching
141
+
-------
142
+
143
+
If LuaFileSystem is available, Luacheck can cache results of checking files. On subsequent checks, only files which have changed since the last check will be rechecked, improving run time significantly. Changing options (e.g. defining additional globals) does not invalidate cache. Caching can be enabled by using ``--cache <cache>`` option or ``cache`` config option. Using ``--cache`` without an argument or setting ``cache`` config option to ``true`` sets ``.luacheckcache`` as the cache file. Note that ``--cache`` must be used every time ``luacheck`` is run, not on the first run only.
An example of a config which makes ``luacheck`` ensure that only globals from the portable intersection of Lua 5.1, Lua 5.2, Lua 5.3 and LuaJIT 2.0 are used, as well as disables detection of unused arguments:
Copy file name to clipboardExpand all lines: doc/_sources/module.txt
+9-6Lines changed: 9 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,25 @@
1
1
Luacheck module
2
2
===============
3
3
4
-
``luacheck`` module is a single function. Use ``local luacheck = require "luacheck"`` to import it.
4
+
Use ``local luacheck = require "luacheck"`` to import ``luacheck`` module. It contains the following functions:
5
5
6
-
The first argument of the function should be an array. Each element should be either a file name (string) or an open file handle, in which case ``luacheck`` will read it till EOF and close it.
6
+
* ``luacheck.get_report(source)``: Given source string, returns analysis data (an array) or nil and syntax error table (table with fields ``line``, ``column``, ``offset``, ``msg``).
7
+
* ``luacheck.process_reports(reports, options)``: Processes array of analysis reports and applies options. ``reports[i]`` uses ``options``, ``options[i]``, ``options[i][1]``, ``options[i][2]``, ... as options, overriding each other in that order. Options table is a table with fields similar to config options; see :ref:`options`. Analysis reports with field ``error`` are ignored. ``process_reports`` returns final report, see :ref:`report`.
8
+
* ``luacheck.check_strings(sources, options)``: Checks array of sources using options, returns final report. Tables in ``sources`` array are ignored.
9
+
* ``luacheck.check_files(files, options)``: Checks array of files using options, returns final report. Open file handles can passed instead of filenames, in which case they will be read till EOF and closed.
7
10
8
-
The second argument, if present, should be a table of options. See :ref:`options`.
11
+
``luacheck._VERSION`` contains Luacheck version as a string in ``MAJOR.MINOR.PATCH`` format.
9
12
10
-
When checking ``n``-th file, ``luacheck`` will try to combine ``options[n]`` and entries from its array part with general options, similarly to how per file config tables overwrite main config table.
13
+
Using ``luacheck`` as a function is equivalent to calling ``luacheck.check_files``.
11
14
12
15
.. _report:
13
16
14
17
Report format
15
18
-------------
16
19
17
-
The ``luacheck`` function returns a report. A report is an array of file reports plus fields ``warnings`` and ``errors`` containing total number of warnings and errors, correspondingly.
20
+
A final report is an array of file reports plus fields ``warnings`` and ``errors`` containing total number of warnings and errors, correspondingly.
18
21
19
-
A file report is an array of warnings. If an error occured while checking a file, its report will only have ``error`` field containing ``"I/O"`` or ``"syntax"``.
22
+
A file report is an array of warnings. If an error occured while checking a file, its report will have ``error`` field containing ``"I/O"`` or ``"syntax"``. In case of syntax error, ``line`` (number), ``colunmn`` (number), ``offset`` (number) and ``msg`` (string) fields are also present.
20
23
21
24
A warning is a table with field ``code`` indicating the type of warning (see :doc:`warnings`), and fields ``line`` and ``column`` pointing to the source of the warning. Absence of ``code`` field indicates that the warning is related to a broken inline configuration comment; then, ``invalid`` field marks comments with invalid syntax, and ``unpaired`` field marks unpaired push/pop comments.
Copy file name to clipboardExpand all lines: doc/_sources/warnings.txt
+8-3Lines changed: 8 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,9 @@ Code Description
29
29
421 Shadowing a local variable.
30
30
422 Shadowing an argument.
31
31
423 Shadowing a loop variable.
32
+
431 Shadowing an upvalue.
33
+
432 Shadowing an upvalue argument.
34
+
433 Shadowing an upvalue loop variable.
32
35
511 Unreachable code.
33
36
512 Loop can be executed at most once.
34
37
521 Unused label.
@@ -62,8 +65,8 @@ Modules
62
65
63
66
Files can be marked as modules using ``-m``/``--module`` CLI option or ``module`` config option to simulate semantics of the deprecated `module <http://www.lua.org/manual/5.1/manual.html#pdf-module>`_ function. Globals implicitly defined inside a module are considired part of its interface, are not visible outside and are not reported as unused. Assignments to other globals are not allowed, even to defined ones.
64
67
65
-
Unused variables and values
66
-
----------------------------
68
+
Unused variables and values
69
+
---------------------------
67
70
68
71
Luacheck generates warnings for all unused local variables except one named ``_``. It also detects variables which are set but never accessed or accessed but never set.
69
72
@@ -109,7 +112,7 @@ Warnings related to unused secondary values and variables can be removed using `
109
112
Shadowing declarations
110
113
----------------------
111
114
112
-
Luacheck detects declarations of local variables shadowing previous declarations in the same closure, unless the variable is named ``_``. If the previous declaration is in the same scope as the new one, it is called redefining.
115
+
Luacheck detects declarations of local variables shadowing previous declarations, unless the variable is named ``_``. If the previous declaration is in the same scope as the new one, it is called redefining.
113
116
114
117
Note that it is **not** necessary to define a new local variable when overwriting an argument:
115
118
@@ -127,6 +130,8 @@ Note that it is **not** necessary to define a new local variable when overwritin
127
130
Control flow and data flow issues
128
131
---------------------------------
129
132
133
+
The following control flow and data flow issues are detected:
134
+
130
135
* Unreachable code and loops that can be executed at most once (e.g. due to an unconditional break);
0 commit comments