Skip to content

Commit 5c1d63f

Browse files
author
spalger
committed
move to explicitly imported lodash functions
1 parent 81c7498 commit 5c1d63f

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

src/fileIgnored.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var fs = require('fs');
2-
var _ = require('lodash');
2+
var memoize = require('lodash/memoize');
33
var Minimatch = require('minimatch').Minimatch;
44
var resolve = require('path').resolve;
55
var dirname = require('path').dirname;
@@ -39,7 +39,7 @@ module.exports = (function () {
3939
};
4040
}
4141

42-
var minimatch = _.memoize(function (pattern) {
42+
var minimatch = memoize(function (pattern) {
4343
return new Minimatch(pattern, { nocase: true });
4444
});
4545

src/lint.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ var PluginError = require('gulp-util').PluginError;
33
var RcLoader = require('rcloader');
44
var jshintcli = require('jshint/src/cli');
55
var minimatch = require('minimatch');
6-
var _ = require('lodash');
6+
7+
var assign = require('lodash/assign');
8+
var forEach = require('lodash/forEach');
9+
var isString = require('lodash/isString');
10+
var isFunction = require('lodash/isFunction');
711

812
module.exports = function createLintFunction(userOpts) {
913
userOpts = userOpts || {};
@@ -15,15 +19,15 @@ module.exports = function createLintFunction(userOpts) {
1519
var jshint = require('jshint').JSHINT;
1620

1721
if (userOpts.linter) {
18-
if (_.isString(userOpts.linter)) {
22+
if (isString(userOpts.linter)) {
1923
// require throws an error if the component can't be found,
2024
// so we're guaranteed that `require(jshint)` will not be undefined
2125
jshint = require(userOpts.linter).JSHINT;
2226
} else { // should be a function
23-
jshint = userOpts.linter;
24-
}
27+
jshint = userOpts.linter;
28+
}
2529

26-
if (!_.isFunction(jshint)) {
30+
if (!isFunction(jshint)) {
2731
throw new PluginError('gulp-jshint',
2832
'Invalid linter "'+ userOpts.linter + '". Must be a function or requirable package.'
2933
);
@@ -68,23 +72,23 @@ module.exports = function createLintFunction(userOpts) {
6872
}
6973

7074
if (cfg.overrides) {
71-
_.forEach(cfg.overrides, function (options, pattern) {
75+
forEach(cfg.overrides, function (options, pattern) {
7276
if (!minimatch(file.path, pattern, { nocase: true, matchBase: true })) return;
7377

7478
if (options.globals) {
75-
globals = _.assign(globals, options.globals);
79+
globals = assign(globals, options.globals);
7680
delete options.globals;
7781
}
7882

79-
_.assign(cfg, options);
83+
assign(cfg, options);
8084
});
8185

8286
delete cfg.overrides;
8387
}
8488

8589
// get or create file.jshint, we will write all output here
8690
var out = file.jshint || (file.jshint = {});
87-
var str = _.isString(out.extracted) ? out.extracted : file.contents.toString('utf8');
91+
var str = isString(out.extracted) ? out.extracted : file.contents.toString('utf8');
8892

8993
out.success = jshint(str, cfg, globals);
9094
if (!out.success) reportErrors(file, out, cfg);

src/reporters/fail.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var path = require('path');
22
var stream = require('../stream');
33
var PluginError = require('gulp-util').PluginError;
4-
var _ = require('lodash');
4+
var reduce = require('lodash/reduce');
55

66
module.exports = function (opts) {
77
opts = opts || {};
@@ -19,7 +19,7 @@ module.exports = function (opts) {
1919
function through(file) {
2020
// count error, warning and info messages
2121
if (file.jshint && file.jshint.results) {
22-
messages = _.reduce(file.jshint.results, function(result, err) {
22+
messages = reduce(file.jshint.results, function(result, err) {
2323
return {
2424
error: result.error + Number(err.error.code[0] === 'E'),
2525
warning: result.warning + Number(err.error.code[0] === 'W'),

src/reporters/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var PluginError = require('gulp-util').PluginError;
22
var stream = require('../stream');
3-
var _ = require('lodash');
3+
var defaults = require('lodash/defaults');
44

55
exports.failReporter = require('./fail');
66

@@ -43,7 +43,7 @@ exports.reporter = function (reporter, reporterCfg) {
4343
return stream(function (file, cb) {
4444
if (file.jshint && !file.jshint.success && !file.jshint.ignored) {
4545
// merge the reporter config into this files config
46-
var opt = _.defaults({}, reporterCfg, file.jshint.opt);
46+
var opt = defaults({}, reporterCfg, file.jshint.opt);
4747

4848
rpt(file.jshint.results, file.jshint.data, opt);
4949
}

test/util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var _ = require('lodash');
1+
var isString = require('lodash/isString');
22
var jshint = require('../');
33
var gutil = require('gulp-util');
44
var join = require('path').join;
@@ -13,7 +13,7 @@ function File(opts) {
1313
if (!(this instanceof File)) return new File(opts);
1414

1515
opts = opts || {};
16-
if (_.isString(opts)) {
16+
if (isString(opts)) {
1717
opts = { path: opts.replace(/^fixture\//, 'test/fixtures/') };
1818
}
1919

@@ -83,4 +83,4 @@ module.exports = {
8383
Fixture: Fixture,
8484
RcFixture: RcFixture,
8585
lint: lint
86-
};
86+
};

0 commit comments

Comments
 (0)