Skip to content

Commit 4f1695b

Browse files
committed
style(project): apply eslint-hahow
1 parent 99c4545 commit 4f1695b

8 files changed

+2385
-231
lines changed

.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["hahow"]
3+
}

.vscode/extensions.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
3+
}

.vscode/settings.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"jshint.enable": false,
4+
"eslint.enable": true,
5+
"eslint.autoFixOnSave": true,
6+
"prettier.eslintIntegration": true,
7+
"prettier.singleQuote": true
8+
}

lib/index.js

+99-74
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
'use strict'
2+
13
// Module Requirements
2-
var _ = require('lodash'),
3-
fs = require('fs'),
4-
through = require('through'),
5-
proc = require('child_process'),
6-
join = require('path').join,
7-
PluginError = require('gulp-util').PluginError;
4+
const _ = require('lodash')
5+
const fs = require('fs')
6+
const through = require('through')
7+
const proc = require('child_process')
8+
const join = require('path').join
9+
const PluginError = require('gulp-util').PluginError
810

911
/**
1012
* Returns a stream to use with Gulp which executes the passed files as Mocha
@@ -17,88 +19,111 @@ var _ = require('lodash'),
1719
*/
1820
module.exports = function (ops, coverage) {
1921
// Default ops
20-
ops = ops || {};
22+
ops = ops || {}
2123
// Setup
22-
var ist = ops.istanbul;
23-
var output = ops.output;
24+
let ist = ops.istanbul
25+
let output = ops.output
2426
// Using istanbul? Use _mocha, otherwise use mocha in order to support full node options (e.g., --debug-brk)
25-
var bin = ops.bin || join(require.resolve('mocha'), '..', 'bin', ist ? '_mocha' : 'mocha');
26-
var env = _.extend(_.clone(process.env), ops.env || {});
27-
var cwd = ops.cwd;
28-
var execPath = ops.execPath || process.execPath;
29-
ops = _.omit(ops, ['bin', 'env', 'istanbul', 'cwd', 'execPath']);
27+
let bin =
28+
ops.bin ||
29+
join(require.resolve('mocha'), '..', 'bin', ist ? '_mocha' : 'mocha')
30+
let env = _.extend(_.clone(process.env), ops.env || {})
31+
let cwd = ops.cwd
32+
let execPath = ops.execPath || process.execPath
33+
ops = _.omit(ops, ['bin', 'env', 'istanbul', 'cwd', 'execPath'])
3034

3135
// Create stream
32-
var stream = through(function (file) {
33-
this._files.push(file.path);
34-
}, function () {
35-
// make sure there are files to test
36-
if (this._files.length === 0) {
37-
this.emit('end');
38-
return;
39-
};
36+
let stream = through(
37+
function (file) {
38+
this._files.push(file.path)
39+
},
40+
function () {
41+
// make sure there are files to test
42+
if (this._files.length === 0) {
43+
this.emit('end')
44+
return
45+
}
4046

41-
// Save refernce to this (bindless context cheat)
42-
var that = this;
47+
// Save refernce to this (bindless context cheat)
48+
let that = this
4349

44-
// Parse arguments
45-
var args = parseArgs(ops);
46-
// Using istanbul?
47-
if (ist) {
48-
args.unshift('--', bin);
49-
// The non-standard location of istanbul's bin makes me a wee bit nervous. Find it by inspecting package.json.
50-
bin = ist.bin || join(require.resolve('istanbul'), '..', require('istanbul/package.json').bin.istanbul);
51-
// If the value for istanbul is literally true, just keep the arguments array. Otherwise, parse istanbul options.
52-
args = ist === true ? args : parseArgs(_.omit(ist, ['bin'])).concat(args);
53-
args.unshift('cover');
54-
}
55-
// Execute Mocha, stdin and stdout are inherited
56-
this._child = proc.fork(bin, args.concat(this._files), {cwd: cwd, env: env, execPath: execPath, silent: !!output});
57-
// If there's an error running the process. See http://nodejs.org/api/child_process.html#child_process_event_error
58-
this._child.on('error', function (e) {
59-
that.emit('error', new PluginError('gulp-spawn-mocha', e));
60-
that.emit('end');
61-
});
62-
// When done...
63-
this._child.on('close', function (code) {
64-
// If code is not zero (falsy)
65-
if (code) {
66-
that.emit('error', new PluginError('gulp-spawn-mocha', 'Mocha exited with code ' + code));
50+
// Parse arguments
51+
let args = parseArgs(ops)
52+
// Using istanbul?
53+
if (ist) {
54+
args.unshift('--', bin)
55+
// The non-standard location of istanbul's bin makes me a wee bit nervous. Find it by inspecting package.json.
56+
bin =
57+
ist.bin ||
58+
join(
59+
require.resolve('istanbul'),
60+
'..',
61+
require('istanbul/package.json').bin.istanbul
62+
)
63+
// If the value for istanbul is literally true, just keep the arguments array. Otherwise, parse istanbul options.
64+
args =
65+
ist === true ? args : parseArgs(_.omit(ist, ['bin'])).concat(args)
66+
args.unshift('cover')
67+
}
68+
// Execute Mocha, stdin and stdout are inherited
69+
this._child = proc.fork(bin, args.concat(this._files), {
70+
cwd,
71+
env,
72+
execPath,
73+
silent: !!output
74+
})
75+
// If there's an error running the process. See http://nodejs.org/api/child_process.html#child_process_event_error
76+
this._child.on('error', (e) => {
77+
that.emit('error', new PluginError('gulp-spawn-mocha', e))
78+
that.emit('end')
79+
})
80+
// When done...
81+
this._child.on('close', (code) => {
82+
// If code is not zero (falsy)
83+
if (code) {
84+
that.emit(
85+
'error',
86+
new PluginError(
87+
'gulp-spawn-mocha',
88+
`Mocha exited with code ${code}`
89+
)
90+
)
91+
}
92+
that.emit('end')
93+
})
94+
// Output to a file
95+
if (output) {
96+
let s = _.isString(output) ? fs.createWriteStream(output) : output
97+
that._child.stdout.pipe(s)
98+
that._child.stderr.pipe(s)
6799
}
68-
that.emit('end');
69-
});
70-
// Output to a file
71-
if (output) {
72-
var s = _.isString(output) ? fs.createWriteStream(output) : output;
73-
that._child.stdout.pipe(s);
74-
that._child.stderr.pipe(s);
75100
}
76-
});
101+
)
77102

78103
// Attach files array to stream
79-
stream._files = [];
104+
stream._files = []
80105
// Return stream
81-
return stream;
82-
};
106+
return stream
107+
}
83108

84109
/**
85110
* Parses the arugments from a configuration object for passing to a mocha
86111
* executable.
87112
* @param {Object} obj The object to parse from.
88113
* @return {Array} An array of parsed arguments.
89114
*/
90-
function parseArgs(obj) {
91-
var args = [];
92-
_.each(obj, function (val, key) {
115+
function parseArgs (obj) {
116+
let args = []
117+
_.each(obj, (val, key) => {
93118
if (_.isArray(val)) {
94-
_.each(val, function (val) {
95-
addArg(args, key, val);
96-
});
119+
_.each(val, (val) => {
120+
addArg(args, key, val)
121+
})
97122
} else {
98-
addArg(args, key, val);
123+
addArg(args, key, val)
99124
}
100-
});
101-
return args;
125+
})
126+
return args
102127
}
103128

104129
/**
@@ -108,19 +133,19 @@ function parseArgs(obj) {
108133
* @param {String} val Value of the argument. Returns without doing anything
109134
* if falsy and not zero.
110135
*/
111-
function addArg(args, name, val) {
136+
function addArg (args, name, val) {
112137
if (!val && val !== 0) {
113-
return;
138+
return
114139
}
115-
var arg = name.length > 1 ? '--' + _.kebabCase(name) : '-' + name;
140+
let arg = name.length > 1 ? `--${_.kebabCase(name)}` : `-${name}`
116141
// --max-old-space-size argument requires an `=`
117142
if (arg === '--max-old-space-size') {
118-
args.push(arg + '=' + val);
119-
return;
143+
args.push(`${arg}=${val}`)
144+
return
120145
} else {
121-
args.push(arg);
146+
args.push(arg)
122147
}
123148
if (_.isString(val) || _.isNumber(val)) {
124-
args.push(val);
149+
args.push(val)
125150
}
126151
}

0 commit comments

Comments
 (0)