forked from bline/coffeelint-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (23 loc) · 890 Bytes
/
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
const fs = require('fs');
const loaderUtils = require('loader-utils');
const coffeelint = require('coffeelint').lint;
const chalk = require('chalk');
module.exports = function(source) {
this.cacheable && this.cacheable();
let appDirectory = fs.realpathSync(process.cwd());
let sourceFileName = loaderUtils.getRemainingRequest(this)
.replace(`${appDirectory}/`, '');
let path = './coffeelint.json';
let file = fs.readFileSync(path, 'utf8');
let config = JSON.parse(file);
this.addDependency(path);
let errs = coffeelint(source, config);
errs.forEach((e) => {
let message = `${e.message} @ ${sourceFileName}:${e.lineNumber}`;
this.emitError(chalk.yellow(`CoffeeLint error: ${message}`));
});
if (errs.length && process.env.NODE_ENV === 'production') {
throw new Error(chalk.red('CoffeeLint failed on style errors.'));
}
return source;
};