Skip to content

Commit

Permalink
Build: Add eslint and jscs presets & update code
Browse files Browse the repository at this point in the history
  • Loading branch information
pdehaan authored and phated committed Nov 28, 2017
1 parent bdbe46d commit c51a906
Show file tree
Hide file tree
Showing 23 changed files with 375 additions and 358 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "gulp"
}
3 changes: 3 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preset": "gulp"
}
19 changes: 0 additions & 19 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
module.exports = {
src: require('./lib/src'),
dest: require('./lib/dest'),
symlink: require('./lib/symlink')
symlink: require('./lib/symlink'),
};
23 changes: 11 additions & 12 deletions lib/dest/writeContents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ var writeBuffer = require('./writeBuffer');
var writeSymbolicLink = require('./writeSymbolicLink');

function writeContents(writePath, file, cb) {
// if directory then mkdirp it
// If directory then mkdirp it
if (file.isDirectory()) {
return writeDir(writePath, file, written);
}

// stream it to disk yo
// Stream it to disk yo
if (file.isStream()) {
return writeStream(writePath, file, written);
}

// write it as a symlink
// Write it as a symlink
if (file.symlink) {
return writeSymbolicLink(writePath, file, written);
}

// write it like normal
// Write it like normal
if (file.isBuffer()) {
return writeBuffer(writePath, file, written);
}

// if no contents then do nothing
// If no contents then do nothing
if (file.isNull()) {
return complete();
}
Expand Down Expand Up @@ -60,17 +60,16 @@ function writeContents(writePath, file, cb) {
}

function isErrorFatal(err) {
var isFatal = true;
if (!err) {
return false;
}

// Handle scenario for file overwrite failures.
else if (err.code === 'EEXIST' && file.flag === 'wx') {
return false; // "These aren't the droids you're looking for"
isFatal = false;
} else if (err.code === 'EEXIST' && file.flag === 'wx') {
// Handle scenario for file overwrite failures.
isFatal = false; // "These aren't the droids you're looking for"
}

// Otherwise, this is a fatal error
return true;
return isFatal;
}
}

Expand Down
3 changes: 1 addition & 2 deletions lib/dest/writeContents/writeBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ function writeBuffer(writePath, file, cb) {
futimes(fd, stat, complete);
});

// cleanup
// Cleanup
function complete(err1) {
fs.close(fd, function(err2) {
cb(err1 || err2);
});
}
});

}

module.exports = writeBuffer;
10 changes: 5 additions & 5 deletions lib/dest/writeContents/writeStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ function writeStream(writePath, file, cb) {
var outStream;
var outFD;

fs.open(writePath, 'w', file.stat.mode, function (err, fd) {
fs.open(writePath, 'w', file.stat.mode, function(err, fd) {
if (err) {
cb(err);
}

outFD = fd;
outStream = fs.createWriteStream(null, {fd: fd});
outStream = fs.createWriteStream(null, { fd: fd });

file.contents.once('error', complete);
file.contents.once('end', readStreamEnd);
Expand All @@ -26,7 +26,7 @@ function writeStream(writePath, file, cb) {
// Streams are piped with end disabled, this prevents the
// WriteStream from closing the file descriptor after all
// data is written.
file.contents.pipe(outStream, {end: false});
file.contents.pipe(outStream, { end: false });
});

function readStreamEnd() {
Expand All @@ -35,7 +35,7 @@ function writeStream(writePath, file, cb) {
return complete(error);
}

futimes(outFD, stat, function (error) {
futimes(outFD, stat, function(error) {
if (error) {
return complete(error);
}
Expand All @@ -46,7 +46,7 @@ function writeStream(writePath, file, cb) {
});
}

// cleanup
// Cleanup
function complete(err) {
file.contents.removeListener('error', complete);
file.contents.removeListener('end', readStreamEnd);
Expand Down
2 changes: 1 addition & 1 deletion lib/dest/writeContents/writeSymbolicLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var fs = require('graceful-fs');

function writeSymbolicLink(writePath, file, cb) {
fs.symlink(file.symlink, writePath, function (err) {
fs.symlink(file.symlink, writePath, function(err) {
if (err && err.code !== 'EEXIST') {
return cb(err);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/filterSince.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function(d) {
if (!isValid) {
throw new Error('expected since option to be a date or a number');
}
return filter.obj(function(file){
return filter.obj(function(file) {
return file.stat && file.stat.mtime > d;
});
};
};
8 changes: 4 additions & 4 deletions lib/prepareWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function prepareWrite(outFolder, file, opt, cb) {
cwd: process.cwd(),
mode: (file.stat ? file.stat.mode : null),
dirMode: null,
overwrite: true
overwrite: true,
}, opt);
var overwrite = booleanOrFunc(options.overwrite, file);
options.flag = (overwrite ? 'w' : 'wx');
Expand All @@ -45,16 +45,16 @@ function prepareWrite(outFolder, file, opt, cb) {
var writePath = path.resolve(basePath, file.relative);
var writeFolder = path.dirname(writePath);

// wire up new properties
// Wire up new properties
file.stat = (file.stat || new fs.Stats());
file.stat.mode = options.mode;
file.flag = options.flag;
file.cwd = cwd;
file.base = basePath;
file.path = writePath;

// mkdirp the folder the file is going in
mkdirp(writeFolder, options.dirMode, function(err){
// Mkdirp the folder the file is going in
mkdirp(writeFolder, options.dirMode, function(err) {
if (err) {
return cb(err);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ var Writable = require('readable-stream/writable');
function sink(stream) {
var sinkStream = new Writable({
objectMode: true,
write: function(file, enc, cb) { cb(); }
write: function(file, enc, cb) {
cb();
},
});

return function() {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/getContents/bufferFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function bufferFile(file, opt, cb) {
return cb(err);
}

if (opt.stripBOM){
if (opt.stripBOM) {
file.contents = stripBom(data);
} else {
file.contents = data;
Expand Down
8 changes: 4 additions & 4 deletions lib/src/getContents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ var streamFile = require('./streamFile');

function getContents(opt) {
return through2.obj(opt, function(file, enc, cb) {
// don't fail to read a directory
// Don't fail to read a directory
if (file.isDirectory()) {
return readDir(file, opt, cb);
}

// process symbolic links included with `followSymlinks` option
// Process symbolic links included with `followSymlinks` option
if (file.stat && file.stat.isSymbolicLink()) {
return readSymbolicLink(file, opt, cb);
}

// read and pass full contents
// Read and pass full contents
if (opt.buffer !== false) {
return bufferFile(file, opt, cb);
}

// dont buffer anything - just pass streams
// Don't buffer anything - just pass streams
return streamFile(file, opt, cb);
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/getContents/readDir.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

function readDir(file, opt, cb) {
// do nothing for now
// Do nothing for now
cb(null, file);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/getContents/readSymbolicLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
var fs = require('graceful-fs');

function readLink(file, opt, cb) {
fs.readlink(file.path, function (err, target) {
fs.readlink(file.path, function(err, target) {
if (err) {
return cb(err);
}

// store the link target path
// Store the link target path
file.symlink = target;

return cb(null, file);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function src(glob, opt) {
stripBOM: true,
sourcemaps: false,
passthrough: false,
followSymlinks: true
followSymlinks: true,
}, opt);

var inputPass;
Expand Down Expand Up @@ -55,7 +55,7 @@ function src(glob, opt) {
}
if (options.sourcemaps === true) {
outputStream = outputStream
.pipe(sourcemaps.init({loadMaps: true}));
.pipe(sourcemaps.init({ loadMaps: true }));
}
globStream.on('error', outputStream.emit.bind(outputStream, 'error'));
return outputStream;
Expand Down
8 changes: 4 additions & 4 deletions lib/src/resolveSymlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ var path = require('path');

function resolveSymlinks(options) {

// a stat property is exposed on file objects as a (wanted) side effect
// A stat property is exposed on file objects as a (wanted) side effect
function resolveFile(globFile, enc, cb) {
fs.lstat(globFile.path, function (err, stat) {
fs.lstat(globFile.path, function(err, stat) {
if (err) {
return cb(err);
}
Expand All @@ -19,15 +19,15 @@ function resolveSymlinks(options) {
return cb(null, globFile);
}

fs.realpath(globFile.path, function (err, filePath) {
fs.realpath(globFile.path, function(err, filePath) {
if (err) {
return cb(err);
}

globFile.base = path.dirname(filePath);
globFile.path = filePath;

// recurse to get real file stat
// Recurse to get real file stat
resolveFile(globFile, enc, cb);
});
});
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@
"devDependencies": {
"buffer-equal": "^0.0.1",
"del": "^2.2.0",
"eslint": "^1.10.3",
"eslint-config-gulp": "^2.0.0",
"istanbul": "^0.3.0",
"istanbul-coveralls": "^1.0.1",
"jshint": "^2.4.1",
"jscs": "^2.4.0",
"jscs-preset-gulp": "^1.0.0",
"mocha": "^2.0.0",
"mocha-lcov-reporter": "^1.0.0",
"rimraf": "^2.2.5",
"should": "^7.0.0",
"sinon": "^1.10.3"
},
"scripts": {
"test": "jshint lib && mocha",
"lint": "eslint . && jscs index.js lib/ test/",
"test": "npm run lint && mocha",
"coveralls": "istanbul cover _mocha && istanbul-coveralls"
},
"engines": {
Expand Down
3 changes: 3 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "gulp/test"
}
Loading

0 comments on commit c51a906

Please sign in to comment.