-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (37 loc) · 1.01 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
'use strict';
const stylint = require('stylint');
class Stylinter {
constructor(config) {
this.config = config.plugins.stylint || undefined;
}
lint(data, path) {
let errors;
let warnings;
// do the lint
stylint(path, this.config).methods({
read() {
this.cache.filesLen = 1;
this.cache.fileNo = 1;
this.cache.file = path;
this.cache.files = [path];
this.parse(null, [data]);
},
done() {
errors = this.cache.errs;
warnings = this.cache.warnings;
},
}).create();
const hasWarnings = warnings.length > 0;
const hasErrors = errors.length > 0;
if (!hasWarnings && !hasErrors) return Promise.resolve();
let msg = `Stylint reported:\n ${errors}`;
if (hasWarnings) {
msg = `warn: ${warnings} ${msg}`;
}
return Promise.reject(msg);
}
}
Stylinter.prototype.brunchPlugin = true;
Stylinter.prototype.type = 'stylesheet';
Stylinter.prototype.extension = 'styl';
module.exports = Stylinter;