-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
113 lines (91 loc) · 3.05 KB
/
index.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"use babel";
import { CompositeDisposable } from "atom";
import { dirname } from "path";
const linterName = "linter-joker";
let jokerExecutablePath;
let lintsOnChange;
export default {
activate() {
require("atom-package-deps").install("linter-joker");
this.subscriptions = new CompositeDisposable();
this.subscriptions.add(
atom.config.observe(`${linterName}.jokerExecutablePath`, value => {
jokerExecutablePath = value;
})
);
this.subscriptions.add(
atom.config.observe(`${linterName}.lintsOnChange`, value => {
lintsOnChange = value;
})
);
},
deactivate() {
this.subscriptions.dispose();
},
provideLinter() {
const helpers = require("atom-linter");
return {
name: "joker",
scope: "file", // or 'project'
lintsOnChange: lintsOnChange,
grammarScopes: ["source.clojure"],
lint(textEditor) {
const editorPath = textEditor.getPath();
const editorText = textEditor.getText();
const [extension] = editorPath.match(/\.\w+$/gi) || [];
// console.log("linter-joker: file extension", extension);
const command =
extension === ".clj"
? "--lintclj"
: extension === ".cljs"
? "--lintcljs"
: extension === ".edn" || extension === ".joker"
? "--lintedn"
: extension === ".joke" ? "--lintjoker" : "--lintclj";
return helpers
.exec(jokerExecutablePath, [command, "-"], {
cwd: dirname(editorPath),
uniqueKey: linterName,
stdin: editorText,
stream: "both"
})
.then(function(data) {
if (!data) {
// console.log("linter-joker: process killed", data);
return null;
}
const { exitCode, stdout, stderr } = data;
// console.log("linter-joker: data", data);
if (exitCode === 1 && stderr) {
const regex = /[^:]+:(\d+):(\d+): ([\s\S]+)/;
const messages = stderr
.split(/[\r\n]+/)
.map(function(joke) {
const exec = regex.exec(joke);
if (!exec) {
// console.log("linter-joker: failed exec", joke);
return null;
}
const line = Number(exec[1]);
const excerpt = exec[3];
return {
severity: excerpt.startsWith("Parse warning:")
? "warning"
: "error",
location: {
file: editorPath,
position: helpers.generateRange(textEditor, line - 1)
},
excerpt: `${excerpt}`
};
})
.filter(m => m); // filter out null messages
// console.log("linter-joker: messages", messages);
return messages;
}
return [];
});
}
};
}
};