Skip to content

Commit

Permalink
move to explicitly imported lodash functions
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed May 9, 2016
1 parent 81c7498 commit 5c1d63f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/fileIgnored.js
@@ -1,5 +1,5 @@
var fs = require('fs');
var _ = require('lodash');
var memoize = require('lodash/memoize');
var Minimatch = require('minimatch').Minimatch;
var resolve = require('path').resolve;
var dirname = require('path').dirname;
Expand Down Expand Up @@ -39,7 +39,7 @@ module.exports = (function () {
};
}

var minimatch = _.memoize(function (pattern) {
var minimatch = memoize(function (pattern) {
return new Minimatch(pattern, { nocase: true });
});

Expand Down
22 changes: 13 additions & 9 deletions src/lint.js
Expand Up @@ -3,7 +3,11 @@ var PluginError = require('gulp-util').PluginError;
var RcLoader = require('rcloader');
var jshintcli = require('jshint/src/cli');
var minimatch = require('minimatch');
var _ = require('lodash');

var assign = require('lodash/assign');
var forEach = require('lodash/forEach');
var isString = require('lodash/isString');
var isFunction = require('lodash/isFunction');

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

if (userOpts.linter) {
if (_.isString(userOpts.linter)) {
if (isString(userOpts.linter)) {
// require throws an error if the component can't be found,
// so we're guaranteed that `require(jshint)` will not be undefined
jshint = require(userOpts.linter).JSHINT;
} else { // should be a function
jshint = userOpts.linter;
}
jshint = userOpts.linter;
}

if (!_.isFunction(jshint)) {
if (!isFunction(jshint)) {
throw new PluginError('gulp-jshint',
'Invalid linter "'+ userOpts.linter + '". Must be a function or requirable package.'
);
Expand Down Expand Up @@ -68,23 +72,23 @@ module.exports = function createLintFunction(userOpts) {
}

if (cfg.overrides) {
_.forEach(cfg.overrides, function (options, pattern) {
forEach(cfg.overrides, function (options, pattern) {
if (!minimatch(file.path, pattern, { nocase: true, matchBase: true })) return;

if (options.globals) {
globals = _.assign(globals, options.globals);
globals = assign(globals, options.globals);
delete options.globals;
}

_.assign(cfg, options);
assign(cfg, options);
});

delete cfg.overrides;
}

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

out.success = jshint(str, cfg, globals);
if (!out.success) reportErrors(file, out, cfg);
Expand Down
4 changes: 2 additions & 2 deletions src/reporters/fail.js
@@ -1,7 +1,7 @@
var path = require('path');
var stream = require('../stream');
var PluginError = require('gulp-util').PluginError;
var _ = require('lodash');
var reduce = require('lodash/reduce');

module.exports = function (opts) {
opts = opts || {};
Expand All @@ -19,7 +19,7 @@ module.exports = function (opts) {
function through(file) {
// count error, warning and info messages
if (file.jshint && file.jshint.results) {
messages = _.reduce(file.jshint.results, function(result, err) {
messages = reduce(file.jshint.results, function(result, err) {
return {
error: result.error + Number(err.error.code[0] === 'E'),
warning: result.warning + Number(err.error.code[0] === 'W'),
Expand Down
4 changes: 2 additions & 2 deletions src/reporters/index.js
@@ -1,6 +1,6 @@
var PluginError = require('gulp-util').PluginError;
var stream = require('../stream');
var _ = require('lodash');
var defaults = require('lodash/defaults');

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

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

rpt(file.jshint.results, file.jshint.data, opt);
}
Expand Down
6 changes: 3 additions & 3 deletions test/util.js
@@ -1,4 +1,4 @@
var _ = require('lodash');
var isString = require('lodash/isString');
var jshint = require('../');
var gutil = require('gulp-util');
var join = require('path').join;
Expand All @@ -13,7 +13,7 @@ function File(opts) {
if (!(this instanceof File)) return new File(opts);

opts = opts || {};
if (_.isString(opts)) {
if (isString(opts)) {
opts = { path: opts.replace(/^fixture\//, 'test/fixtures/') };
}

Expand Down Expand Up @@ -83,4 +83,4 @@ module.exports = {
Fixture: Fixture,
RcFixture: RcFixture,
lint: lint
};
};

0 comments on commit 5c1d63f

Please sign in to comment.