UNPKG

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