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