-
Notifications
You must be signed in to change notification settings - Fork 14
/
.eslintplugin.js
44 lines (35 loc) · 1.4 KB
/
.eslintplugin.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
function fixMessage(m, offset) {
if (offset) {
m.line += offset.lines;
if (typeof m.endLine === 'number') m.endLine += offset.lines;
if (m.fix) m.fix.range = m.fix.range.map(c => c + offset.chars);
}
return m;
}
module.exports = {
processors: {
// assign to the file extension you want (.js, .jsx, .html, etc.)
".js": {
// takes text of the file and filename
preprocess: function(text, filename) {
if (!this.offset) this.offset = {}
if (filename.indexOf('/resource/translators/') < 0) return [text];
const translator = text.match(/^([\s\S]+?\r?\n}(\r?\n)+)([\s\S]+)/);
this.offset[filename] = {
lines: translator[1].split('\n').length - 1,
chars: translator[1].length,
}
return [translator[3]];
},
// takes a Message[][] and filename
postprocess: function(messages, filename) {
// `messages` argument contains two-dimensional array of Message objects
// where each top-level array item contains array of lint messages related
// to the text that was returned in array from preprocess() method
// you need to return a one-dimensional array of the messages you want to keep
return messages[0].map(m => fixMessage(m, this.offset[filename]));
},
supportsAutofix: true
}
}
};