1 | 'use strict';
|
2 |
|
3 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
4 |
|
5 | var path = _interopDefault(require('path'));
|
6 | var rollupPluginutils = require('rollup-pluginutils');
|
7 | var eslint = require('eslint');
|
8 |
|
9 | function normalizePath(id) {
|
10 | return path.relative(process.cwd(), id).split(path.sep).join('/');
|
11 | }
|
12 |
|
13 | function 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 |
|
54 | module.exports = eslint$1; |
\ | No newline at end of file |