-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.js
55 lines (46 loc) · 1.51 KB
/
eslint.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
import fs from 'fs-extra';
import path from 'path';
/**
* Provides Gulp tasks for working with ESLint.
*
* The following tasks are defined:
*
* `eslint` - Runs ESLint with the given source glob with the `.eslintrc` file defined in the root path.
*
* @param {object} gulp - An instance of Gulp.
* @param {object} options - Optional parameters
*/
export default function(gulp, options)
{
// The root path of the project being operated on via all tasks.
const rootPath = options.rootPath;
// The source glob defining all sources.
const srcGlob = options.srcGlob;
try
{
// Require is used here to avoid ES6 hoisted imports.
const CLIEngine = require('eslint').CLIEngine;
const cli = new CLIEngine();
if (fs.statSync(`${rootPath}${path.sep}.eslintrc`).isFile())
{
/**
* Runs ESLint with the given source glob with the `.eslintrc` file defined in the root path.
*/
gulp.task('eslint', () =>
{
if (!Array.isArray(srcGlob))
{
console.log(`eslint task error: 'options.srcGlob' is not an 'array'.`);
process.exit(1);
}
const report = cli.executeOnFiles(srcGlob);
const formatter = cli.getFormatter();
console.log(formatter(report.results));
// Exit on errors.
if (report.errorCount > 0) { process.exit(1); }
});
options.loadedTasks.push('eslint');
}
}
catch (err) { /* ... */ }
}