-
Notifications
You must be signed in to change notification settings - Fork 0
/
NodePEP8Exec.js
90 lines (77 loc) · 2.83 KB
/
NodePEP8Exec.js
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
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global exports, require */
(function () {
"use strict";
var process = require('child_process'),
domainManager = null;
var childproc = null;
function pep8(binary, file) {
childproc = process.exec(binary + ' "' + file + '"', function (error, stdout, stderr) {
var result = [],
resultObj = {
"exitcode": childproc.exitCode,
"result": [],
"stdout": stdout,
"stderr": stderr
},
i;
if (childproc.exitCode === 0) {
/* Python OK */
domainManager.emitEvent("pep8", "update", JSON.stringify(resultObj));
return;
} else if (childproc.exitCode === 127) {
domainManager.emitEvent("pep8", "error", JSON.stringify(resultObj));
return;
}
var lines = stdout.split("\n");
for (i = 0; i < lines.length; i++) {
var line = lines[i];
if (line !== "") {
var pos = line.indexOf(":");
var filename = line.substring(0, pos);
var lpos = line.indexOf(":", pos + 1);
var lnumber = line.substring(pos + 1, lpos);
var cpos = line.indexOf(":", lpos + 1);
var cnumber = line.substring(lpos + 1, cpos);
var message = line.substring(line.lastIndexOf(":") + 1);
result.push({
"filename": "lala",
"line": lnumber,
"column": cnumber,
"message": message,
"original": line
});
}
}
resultObj.result = result;
var resultstr = JSON.stringify(resultObj);
domainManager.emitEvent("pep8", "update", resultstr);
});
}
function init(DomainManager) {
domainManager = DomainManager;
if (!domainManager.hasDomain("pep8")) {
domainManager.registerDomain("pep8", {major: 0, minor: 1});
}
domainManager.registerCommand(
"pep8", /* Domain name */
"pep8", /* Command name */
pep8, /* Command handler function */
false, /* This command is synchronous */
"Runs pep8 lint on a file",
["binary", "file"], /* parameters */
[]
);
domainManager.registerEvent(
"pep8",
"update",
["data"]
);
domainManager.registerEvent(
"pep8",
"error",
["data"]
);
}
exports.init = init;
}());