UNPKG

1.28 kBJavaScriptView Raw
1'use strict';
2
3function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
5var path = _interopDefault(require('path'));
6var rollupPluginutils = require('rollup-pluginutils');
7var eslint = require('eslint');
8
9function normalizePath(id) {
10 return path.relative(process.cwd(), id).split(path.sep).join('/');
11}
12
13function eslint$1(options) {
14 if ( options === void 0 ) options = {};
15
16 var cli = new eslint.CLIEngine(options);
17 var formatter = options.formatter;
18
19 if (typeof formatter !== 'function') {
20 formatter = cli.getFormatter(formatter || 'stylish');
21 }
22
23 var filter = rollupPluginutils.createFilter(
24 options.include,
25 options.exclude || 'node_modules/**'
26 );
27
28 return {
29 name: 'eslint',
30
31 transform: function transform(code, id) {
32 var file = normalizePath(id);
33 if (cli.isPathIgnored(file) || !filter(id)) {
34 return null;
35 }
36
37 var report = cli.executeOnText(code, file);
38 if (!report.errorCount && !report.warningCount) {
39 return null;
40 }
41
42 var result = formatter(report.results);
43 if (result) {
44 console.log(result);
45 }
46
47 if (options.throwError) {
48 throw Error('Warnings or errors were found');
49 }
50 }
51 };
52}
53
54module.exports = eslint$1;
\No newline at end of file