-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathLinter.lc
More file actions
151 lines (131 loc) · 4.53 KB
/
Linter.lc
File metadata and controls
151 lines (131 loc) · 4.53 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?livecode
local sErrorsList
local sLastLine
local sTempFile
Lint
command Lint
local tScope, tLCCompile, tModulePaths, theArgument, tFilename, tLCIDirectory
local tIndex
repeat for each element theArgument in the commandArguments
split theArgument with "="
switch theArgument[1]
case "-scope"
put theArgument[2] into tScope
break
case "-explicitVariables"
set the explicitVariables to theArgument[2]
break
case "-modulePaths"
split theArgument[2] with ";"
repeat with tIndex = 1 to the number of elements in theArgument[2]
if there is a folder theArgument[2][tIndex] then
put " --modulepath " & theArgument[2][tIndex] after tModulePaths
end if
end repeat
break
case "-lcCompile"
put theArgument[2] into tLCCompile
break
case "-filepath"
set the itemDelimiter to slash
put item -1 of theArgument[2] into tFilename
put item 1 to -2 of theArgument[2] & "/.lci" into tLCIDirectory
put " --modulepath " & tLCIDirectory before tModulePaths
set the itemDelimiter to comma
break
end switch
end repeat
read from stdin until empty
local tScript
put it into tScript
put the scriptParsingErrors into sErrorsList
split sErrorsList with return
create script only stack "TestScript"
local tErrors
switch tScope
case ".source.livecodescript"
local tLineOffset = 0
-- check for script only
if word 1 of tScript is "script" then
put 1 into tLineOffset
end if
if tLineOffset is 1 then
delete line 1 of tScript
end if
set the script of stack "TestScript" to tScript
put the result into tErrors
split tErrors with return
repeat with tIndex = 1 to the number of elements in tErrors
if tErrors[tIndex] is not empty then
split tErrors[tIndex] with ","
local tMessage
put sErrorsList[tErrors[tIndex][1]] into tMessage
if tMessage is not empty then
if tErrors[tIndex][4] is not empty then
put " (" & item 4 of tErrors[tIndex][4] & ")" after tMessage
end if
write tErrors[tIndex][2] + tLineOffset, tErrors[tIndex][3], tMessage & linefeed to stdout
end if
end if
end repeat
break
case ".source.iRev"
-- can't lint a whole web app...
replace "include" with "# include" in tScript
replace "require" with "# require" in tScript
-- ensure it throws an error so it's not exectuted
put return & quote after tScript
put the number of lines of tScript into sLastLine
SaveToTempFile tScript
include sTempFile
break
case ".source.lcb"
if there is not a folder tLCIDirectory then
create folder tLCIDirectory
end if
SaveToTempFile tScript
set the hideConsoleWindows to true
put shell(tLCCompile & tModulePaths & " -- " & sTempFile) into tErrors
split tErrors with return
repeat with tIndex = 1 to the number of elements of tErrors
if the platform is "Win32" and char 2 to 3 of tErrors[tIndex] is ":/" then
split tErrors[tIndex] with ":"
write tErrors[tIndex][3], tErrors[tIndex][4], tErrors[tIndex][5] & linefeed to stdout
else
split tErrors[tIndex] with ":"
write tErrors[tIndex][2], tErrors[tIndex][3], tErrors[tIndex][4] & linefeed to stdout
end if
end repeat
DeleteTempFile
break
end switch
write linefeed to stdout
end Lint
command SaveToTempFile pScript
put the temporary folder & slash & uuid() into sTempFile
put pScript into url ("binfile:" & sTempFile)
end SaveToTempFile
command DeleteTempFile
delete file sTempFile
end DeleteTempFile
command scriptExecutionError pStack, pFiles
split pStack with return
local tIndex
repeat with tIndex = 2 to the number of elements in pStack
if item 1 of pStack[tIndex] is 730 then
exit repeat
end if
if item 2 of pStack[tIndex] is not 0 and item 2 of pStack[tIndex] is not sLastLine then
local tMessage
put sErrorsList[item 1 of pStack[tIndex]] into tMessage
if tMessage is not empty then
if item 4 of pStack[tIndex] is not empty then
put " (" & item 4 of pStack[tIndex] & ")" after tMessage
end if
write item 2 of pStack[tIndex], item 3 of pStack[tIndex], tMessage & linefeed to stdout
end if
end if
end repeat
DeleteTempFile
write linefeed to stdout
end scriptExecutionError