This repository has been archived by the owner on Jan 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
76 lines (66 loc) · 1.97 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
var stylint = require('stylint');
var loaderUtils = require('loader-utils');
function lint(source, webpackConfig, queryConfig, webpack, callback) {
stylint(source, queryConfig)
.methods({
read: function() {
this.cache.files = [webpack.resource];
this.parse(null, [source]);
},
done: function() {
var result;
var message;
var emitter;
var failureType;
if (this.cache.errs.length > 0 || this.cache.warnings.length > 0) {
if (!this.state.quiet) {
result = [].concat(this.cache.errs, this.cache.warnings);
message = '\n' + result.join('\n\n') + '\n' + this.cache.msg;
emitter = this.cache.errs.length > 0 ? webpack.emitError : webpack.emitWarning;
if (emitter) {
emitter(message);
} else {
throw new Error(
'Your module system doesn\'t support emitWarning. ' +
'Update available? \n' +
message
);
}
} else {
failureType = this.cache.errs.length > 0 ? 'error' : 'warning';
throw new Error(
'Module failed because of a stylint ' + failureType + '.\n' +
this.cache.msg
);
}
}
this.resetOnChange();
}
})
.create({}, {
watch: webpackConfig.watch,
config: webpackConfig.config,
strict: webpackConfig.strict
});
if (callback) {
callback(null, source);
}
}
module.exports = function(source) {
var webpackConfig = this.options.stylint || {};
var queryConfig = this.query ? loaderUtils.parseQuery(this.query) : null;
var callback = this.async();
if (this.cacheable) {
this.cacheable();
}
if (!callback) {
lint(source, webpackConfig, queryConfig, this);
return source;
}
try {
lint(source, webpackConfig, queryConfig, this, callback);
} catch (error) {
callback(error);
}
};