|
1 | 1 | #!/usr/bin/env lua |
2 | 2 |
|
| 3 | +--[[ |
| 4 | +Based on luacheck: https://github.com/luarocks/luacheck |
| 5 | +
|
| 6 | +The MIT License (MIT) |
| 7 | +
|
| 8 | +Copyright (c) 2014 - 2018 Peter Melnichenko |
| 9 | +
|
| 10 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | +of this software and associated documentation files (the "Software"), to deal |
| 12 | +in the Software without restriction, including without limitation the rights |
| 13 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | +copies of the Software, and to permit persons to whom the Software is |
| 15 | +furnished to do so, subject to the following conditions: |
| 16 | +
|
| 17 | +The above copyright notice and this permission notice shall be included in all |
| 18 | +copies or substantial portions of the Software. |
| 19 | +
|
| 20 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | +SOFTWARE. |
| 27 | +]] |
| 28 | + |
3 | 29 | -- Monkey patch Luacheck (tested against version 0.23.0) to support Candran files |
4 | 30 | local candran = require("candran") |
5 | 31 | local util = require("candran.util") |
6 | 32 |
|
| 33 | +-- set a function upvalues (if several names are given, will go up the upvalue chain) |
| 34 | +local function setupvalue(fn, val, name, ...) |
| 35 | + for i=1, debug.getinfo(fn, "u").nups do |
| 36 | + local n, v = debug.getupvalue(fn, i) |
| 37 | + if n == name then |
| 38 | + if not ... then |
| 39 | + debug.setupvalue(fn, i, val) |
| 40 | + else |
| 41 | + setupvalue(v, val, ...) |
| 42 | + end |
| 43 | + end |
| 44 | + end |
| 45 | +end |
| 46 | + |
| 47 | +-- escape a string to be used as a pattern |
7 | 48 | local function escape(str) |
8 | 49 | return str:gsub("[^%w]", "%%%0") |
9 | 50 | end |
10 | 51 |
|
| 52 | +-- returns a pattern that find start and stop position of a token |
11 | 53 | local function pattern(token) |
12 | 54 | return "()"..escape(token).."()" |
13 | 55 | end |
14 | 56 |
|
| 57 | +-- token aliases |
15 | 58 | local tokenAlias = { |
16 | 59 | ["self"] = { "@", ":" } |
17 | 60 | } |
@@ -135,18 +178,6 @@ local function format_location(file, location, opts) |
135 | 178 | end |
136 | 179 | return res |
137 | 180 | end |
138 | | -local function setupvalue(fn, val, name, ...) |
139 | | - for i=1, debug.getinfo(fn, "u").nups do |
140 | | - local n, v = debug.getupvalue(fn, i) |
141 | | - if n == name then |
142 | | - if not ... then |
143 | | - debug.setupvalue(fn, i, val) |
144 | | - else |
145 | | - setupvalue(v, val, ...) |
146 | | - end |
147 | | - end |
148 | | - end |
149 | | -end |
150 | 181 | setupvalue(format.builtin_formatters.plain, format_location, "format_event", "format_location") |
151 | 182 |
|
152 | 183 | -- Fix some Luacheck messages and run |
|
0 commit comments