UNPKG

3.45 kBJavaScriptView Raw
1var $, M, gulp, kleur, using;
2
3$ = {};
4
5$.source_ = require('../dist/source_');
6
7$.getExtname = require('../dist/getExtname');
8
9$.type = require('../dist/type');
10
11$.info = require('../dist/info');
12
13$.i = require('../dist/i');
14
15gulp = require('gulp');
16
17kleur = require('kleur');
18
19using = require('gulp-using');
20
21M = (function() {
22 class M {
23 // '.ts': 'lintTs_'
24 async execute_(source) {
25 var extname, i, len, listSource, method;
26 listSource = (await $.source_(source));
27 for (i = 0, len = listSource.length; i < len; i++) {
28 source = listSource[i];
29 extname = $.getExtname(source);
30 method = this.mapMethod[extname];
31 method || (function() {
32 throw new Error(`lint_/error: invalid extname '${extname}'`);
33 })();
34 await this[method](source);
35 }
36 return this;
37 }
38
39 async lintCoffee_(source) {
40 await new Promise(function(resolve) {
41 var lint;
42 lint = require('gulp-coffeelint');
43 // does not know why
44 // have to put 'on()' before 'pipe()'
45 // strange
46 return gulp.src(source).on('end', function() {
47 return resolve();
48 }).pipe(using()).pipe(lint()).pipe(lint.reporter());
49 });
50 return this;
51 }
52
53 async lintMd_(source) {
54 await new Promise(function(resolve) {
55 var lint, option;
56 lint = require('markdownlint');
57 option = {
58 files: source
59 };
60 return lint(option, function(err, result) {
61 var filename, i, item, len, list, listMsg;
62 if (err) {
63 throw new Error(err);
64 }
65 for (filename in result) {
66 list = result[filename];
67 if ('array' !== $.type(list)) {
68 continue;
69 }
70 filename = $.info().renderPath(filename);
71 $.i(kleur.magenta(filename));
72 for (i = 0, len = list.length; i < len; i++) {
73 item = list[i];
74 listMsg = [];
75 listMsg.push(kleur.gray(`#${item.lineNumber}`));
76 if (item.errorContext) {
77 listMsg.push(`< ${kleur.red(item.errorContext)} >`);
78 }
79 if (item.ruleDescription) {
80 listMsg.push(item.ruleDescription);
81 }
82 $.i(listMsg.join(' '));
83 }
84 }
85 return resolve();
86 });
87 });
88 return this;
89 }
90
91 async lintStyl_(source) {
92 await new Promise(function(resolve) {
93 var lint;
94 lint = require('gulp-stylint');
95 // just like coffee
96 // also have to put 'on()' before 'pipe()'
97 return gulp.src(source).on('end', function() {
98 return resolve();
99 }).pipe(using()).pipe(lint()).pipe(lint.reporter());
100 });
101 return this;
102 }
103
104 };
105
106 /*
107 mapMethod
108
109 execute_(source)
110 lintCoffee_(source)
111 lintMd_(source)
112 lintStyl_(source)
113 lintTs_(source)
114 */
115 M.prototype.mapMethod = {
116 '.coffee': 'lintCoffee_',
117 '.md': 'lintMd_',
118 '.styl': 'lintStyl_'
119 };
120
121 return M;
122
123}).call(this);
124
125
126// lintTs_: (source) ->
127
128// await new Promise (resolve) ->
129
130// lint = require 'gulp-tslint'
131
132// gulp.src source
133// .pipe using()
134// .pipe lint()
135// .pipe lint.report()
136// .on 'end', -> resolve()
137
138// @ # return
139
140// return
141module.exports = async function(...arg) {
142 var m;
143 m = new M();
144 await m.execute_(...arg);
145 return this;
146};