1 | var $, 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 |
|
15 | gulp = require('gulp');
|
16 |
|
17 | kleur = require('kleur');
|
18 |
|
19 | using = require('gulp-using');
|
20 |
|
21 | M = (function() {
|
22 | class M {
|
23 |
|
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 |
|
44 |
|
45 |
|
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 |
|
96 |
|
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 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
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 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | module.exports = async function(...arg) {
|
142 | var m;
|
143 | m = new M();
|
144 | await m.execute_(...arg);
|
145 | return this;
|
146 | };
|