-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
35 lines (33 loc) · 1.13 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
const log = require("fancy-log");
const PluginError = require("plugin-error");
const through = require("through2");
const TextLintEngine = require("textlint").TextLintEngine;
module.exports = function (options) {
options = options || {};
const textlint = new TextLintEngine(options);
const filePaths = [];
return through.obj(
function (file, enc, cb) {
filePaths.push(file.path);
this.push(file);
cb();
},
function (cb) {
const that = this;
textlint
.executeOnFiles(filePaths)
.then(function (results) {
if (textlint.isErrorResults(results)) {
log(textlint.formatResults(results));
that.emit("error", new PluginError("textlint", "Lint failed."));
}
})
.catch(function (error) {
that.emit("error", new PluginError("textlint", `Lint failed. \n${error.message}`));
})
.then(function () {
cb();
});
}
);
};