-
Notifications
You must be signed in to change notification settings - Fork 1
/
leibniz.lua
67 lines (65 loc) · 2.76 KB
/
leibniz.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- this is an example configuration, consult: https://www.lua.org/manual/5.4/
-- or https://learnxinyminutes.com/docs/lua/ for syntax help and
-- src/rules.rs::Config for all available options
leibniz = {
disabled_rules = {
-- ignore sqleibniz specific diagnostics:
"NoContent", -- source file is empty
"NoStatements", -- source file contains no statements
"Unimplemented", -- construct is not implemented yet
"BadSqleibnizInstruction", -- source file contains a bad sqleibniz instruction
-- ignore sqlite specific diagnostics:
-- "UnknownKeyword", -- an unknown keyword was encountered
-- "UnterminatedString", -- a not closed string was found
-- "UnknownCharacter", -- an unknown character was found
-- "InvalidNumericLiteral", -- an invalid numeric literal was found
-- "InvalidBlob", -- an invalid blob literal was found (either bad hex data or incorrect syntax)
-- "Syntax", -- a structure with incorrect syntax was found
-- "Semicolon", -- a semicolon is missing
},
-- sqleibniz allows for writing custom rules with lua
hooks = {
{
-- summarises the hooks content
name = "idents should be lowercase",
-- instructs sqleibniz which node to execute the `hook` for
node = "literal",
-- sqleibniz calls the hook function once it encounters a node name
-- matching the hook.node content
--
-- The `node` argument holds the following fields:
--
--```
-- node: {
-- kind: string,
-- text: string,
-- children: node[],
-- }
--```
--
hook = function(node)
if node.kind == "ident" then
if string.match(node.text, "%u") then
-- returing an error passes the diagnostic to sqleibniz,
-- thus a pretty message with the name of the hook, the
-- node it occurs and the message passed to error() is
-- generated
error("All idents should be lowercase")
end
end
end
},
{
name = "idents shouldn't be longer than 12 characters",
node = "literal",
hook = function(node)
local max_size = 12
if node.kind == "ident" then
if string.len(node.text) >= max_size then
error("idents shouldn't be longer than " .. max_size .. " characters")
end
end
end
}
}
}