diff options
Diffstat (limited to 'src/luarocks/cmd/lint.lua')
-rw-r--r-- | src/luarocks/cmd/lint.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/luarocks/cmd/lint.lua b/src/luarocks/cmd/lint.lua new file mode 100644 index 00000000..c9ea45ea --- /dev/null +++ b/src/luarocks/cmd/lint.lua | |||
@@ -0,0 +1,53 @@ | |||
1 | |||
2 | --- Module implementing the LuaRocks "lint" command. | ||
3 | -- Utility function that checks syntax of the rockspec. | ||
4 | local lint = {} | ||
5 | |||
6 | local util = require("luarocks.util") | ||
7 | local download = require("luarocks.download") | ||
8 | local fetch = require("luarocks.fetch") | ||
9 | |||
10 | lint.help_summary = "Check syntax of a rockspec." | ||
11 | lint.help_arguments = "<rockspec>" | ||
12 | lint.help = [[ | ||
13 | This is a utility function that checks the syntax of a rockspec. | ||
14 | |||
15 | It returns success or failure if the text of a rockspec is | ||
16 | syntactically correct. | ||
17 | ]] | ||
18 | |||
19 | function lint.command(flags, input) | ||
20 | if not input then | ||
21 | return nil, "Argument missing. "..util.see_help("lint") | ||
22 | end | ||
23 | |||
24 | local filename = input | ||
25 | if not input:match(".rockspec$") then | ||
26 | local err | ||
27 | filename, err = download.download("rockspec", input:lower()) | ||
28 | if not filename then | ||
29 | return nil, err | ||
30 | end | ||
31 | end | ||
32 | |||
33 | local rs, err = fetch.load_local_rockspec(filename) | ||
34 | if not rs then | ||
35 | return nil, "Failed loading rockspec: "..err | ||
36 | end | ||
37 | |||
38 | local ok = true | ||
39 | |||
40 | -- This should have been done in the type checker, | ||
41 | -- but it would break compatibility of other commands. | ||
42 | -- Making 'lint' alone be stricter shouldn't be a problem, | ||
43 | -- because extra-strict checks is what lint-type commands | ||
44 | -- are all about. | ||
45 | if not rs.description.license then | ||
46 | util.printerr("Rockspec has no license field.") | ||
47 | ok = false | ||
48 | end | ||
49 | |||
50 | return ok, ok or filename.." failed consistency checks." | ||
51 | end | ||
52 | |||
53 | return lint | ||