-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlintbug.js
More file actions
161 lines (134 loc) · 4.98 KB
/
lintbug.js
File metadata and controls
161 lines (134 loc) · 4.98 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
152
153
154
155
156
157
158
159
160
161
//-------------------------------------------------------------------------------
// Common Modules
//-------------------------------------------------------------------------------
var bugcore = require('bugcore');
var bugflow = require('bugflow');
var buildbug = require('buildbug');
//-------------------------------------------------------------------------------
// Simplify References
//-------------------------------------------------------------------------------
var enableModule = buildbug.enableModule;
var TypeUtil = bugcore.TypeUtil;
var $series = bugflow.$series;
var $task = bugflow.$task;
//-------------------------------------------------------------------------------
// Enable Modules
//-------------------------------------------------------------------------------
var lintbug = enableModule("lintbug");
//-------------------------------------------------------------------------------
// Script
//-------------------------------------------------------------------------------
lintbug.lintTask("ensureUpperCaseRequireAnnotations", function(lintFile, callback) {
});
lintbug.lintTask("fixExportAndRemovePackageAnnotations", function(lintFile, callback) {
var fileContents = lintFile.getFileContents();
var packageAnnotationRegex = /\/\/(\s*)@Package\('([\w|\.]*)'\)(\s*)\n/;
var packageName = undefined;
fileContents = fileContents.replace(packageAnnotationRegex, function(match, p1, p2, p3, offset, string) {
if (!packageName) {
packageName = p2;
} else {
throw new Error("More than one @Package annotation in file '" + lintFile.getFilePath().getAbsolutePath() + "'");
}
return "";
});
if (packageName) {
var exportAnnotationRegex = /(\s*)\/\/(\s*)@Export\((['"])(\w*)(['"])\)(\s*)\n/g;
fileContents = fileContents.replace(exportAnnotationRegex, function(match, p1, p2, p3, p4, p5, p6, offset, string) {
return p1 + "//" + p2 + "@Export(" + p3 + packageName + "." + p4 + p5 + ")" + p6 + "\n";
});
}
lintFile.setFileContents(fileContents);
callback();
});
lintbug.lintTask("orderAnnotationsInFile", function(lintFile, callback) {
var _this = this;
var fileContents = "";
$series([
$task(function(flow) {
var lines = fileContents.split("\n");
_this.sortRequireAnnotationLines(lines);
flow.complete();
})
]).execute(callback);
});
lintbug.lintTask("orderBugPackRequiresInFile", function(jsFilePath, callback) {
//var Class = bugpack.require('Class');
});
lintbug.lintTask("sortRequireAnnotationLines", function(lines) {
var _this = this;
var requireAnnotationStartIndex = -1;
var requireAnnotationStopIndex = -1;
var requireAnnotationRegex = new RegExp("\\s*//\\s*@Require\\('(\\w|\\.)*'\\)");
var requireLines = [];
//find start
for (var i = 0, size = lines.length; i < size; i++) {
var line = lines[i];
if (line.match(requireAnnotationRegex)) {
requireAnnotationStartIndex = i;
break;
}
}
if (requireAnnotationStartIndex > -1) {
requireAnnotationStopIndex = requireAnnotationStartIndex;
for (var i2 = requireAnnotationStartIndex, size2 = lines.length; i2 < size2; i2++) {
var line = lines[i];
var results = line.match(requireAnnotationRegex);
requireLines.push({
line: line,
requireName: results[1]
});
if (results) {
requireAnnotationStopIndex = i2;
}
}
}
//var results = line.match(/\s*\/\/\s*@([a-zA-Z][0-9a-zA-Z]*)(?:\((.+)?\))?\s*/);
/*if (results) {
var annotation = {
name: results[1]
};
var argumentsString = results[2];
if (argumentsString !== undefined) {
annotation.arguments = _this.parseArguments(argumentsString);
}
annotations.push(annotation);
}*/
//var requireLines = lines.splice(requireAnnotationStartIndex, requireAnnotationStopIndex - requireAnnotationStartIndex);
requireLines.sort(function(a, b) {
});
});
/**
* @private
* @param {string} argumentsString
* @return {Array.<(string|number)>}
*/
var parseArguments = function(argumentsString) {
var args = [];
var parts = argumentsString.split(',');
parts.forEach(function(part) {
var results = part.match(/\s*('|")(.*?)\1\s*/);
if (results) {
args.push(results[2]);
} else {
var num = parseFloat(part);
if (isNaN(num)) {
throw new Error("Could not parse parameter '" + part + "'");
}
args.push(num);
}
});
return args;
};
/**
* @private
* @param {string} text
* @return {string}
*/
var parseString = function(text) {
var results = text.match(/\s*('|")(.*?)\1\s*/);
if (results) {
return results[2];
}
return null;
};