forked from pkulchenko/ZeroBranePackage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyzeall.lua
69 lines (61 loc) · 2.13 KB
/
analyzeall.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
68
69
-- Copyright 2014 Paul Kulchenko, ZeroBrane LLC; All rights reserved
local id = ID("analyzeall.analyzeall")
local function path2mask(s)
return s
:gsub('([%(%)%.%%%+%-%?%[%^%$%]])','%%%1') -- escape all special symbols
:gsub("%*", ".*") -- but expand asterisk into sequence of any symbols
:gsub("[\\/]","[\\\\/]") -- allow for any path
end
local function analyzeProject(self)
local frame = ide:GetMainFrame()
local menubar = ide:GetMenuBar()
ide:GetOutput():Erase()
ide:Print("Analyzing the project code.")
frame:Update()
local errors, warnings = 0, 0
local projectPath = ide:GetProject()
if projectPath then
local specs = self:GetConfig().ignore or {}
local masks = {}
for i in ipairs(specs) do masks[i] = "^"..path2mask(specs[i]).."$" end
for _, filePath in ipairs(FileSysGetRecursive(projectPath, true, "*.lua")) do
local checkPath = filePath:gsub(projectPath, "")
local ignore = false
for _, spec in ipairs(masks) do
ignore = ignore or checkPath:find(spec)
end
if not ignore then
local warn, err, line = AnalyzeFile(filePath)
if err then
ide:Print(err)
errors = errors + 1
elseif #warn > 0 then
for _, msg in ipairs(warn) do ide:Print(msg) end
warnings = warnings + #warn
end
ide:Yield() -- refresh the output with new results
end
end
end
ide:Print(("%s error%s and %s warning%s."):format(
errors > 0 and errors or 'no', errors == 1 and '' or 's',
warnings > 0 and warnings or 'no', warnings == 1 and '' or 's'
))
end
return {
name = "Analyze all files",
description = "Analyzes all files in a project.",
author = "Paul Kulchenko",
version = 0.42,
dependencies = "1.3",
onRegister = function(package)
local _, menu, analyzepos = ide:FindMenuItem(ID_ANALYZE)
if menu then
menu:Insert(analyzepos+1, id, TR("Analyze All")..KSC(id), TR("Analyze the project source code"))
menu:Connect(id, wx.wxEVT_COMMAND_MENU_SELECTED, function() return analyzeProject(package) end)
end
end,
onUnRegister = function(self)
ide:RemoveMenuItem(id)
end,
}