Skip to content

Commit

Permalink
chore(format): use a consistent format
Browse files Browse the repository at this point in the history
Utilize the `xo` module to enforce a consistent JavaScript code format
throughout the module code and unit tests.
  • Loading branch information
terinjokes committed Oct 26, 2015
1 parent 03c672a commit 735e04d
Show file tree
Hide file tree
Showing 12 changed files with 403 additions and 419 deletions.
18 changes: 0 additions & 18 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -2,6 +2,6 @@
var uglify = require('uglify-js');
var minifier = require('./minifier');

module.exports = function(opts) {
module.exports = function (opts) {
return minifier(opts, uglify);
};
6 changes: 3 additions & 3 deletions minifier.js
Expand Up @@ -50,7 +50,7 @@ function createError(file, err) {
});
}

var msg = err.message || err.msg || /* istanbul ignore next */ 'unspecified error';
var msg = err.message || err.msg || 'unspecified error';

return new PluginError(pluginName, file.path + ': ' + msg, {
fileName: file.path,
Expand All @@ -60,7 +60,7 @@ function createError(file, err) {
});
}

module.exports = function(opts, uglify) {
module.exports = function (opts, uglify) {
function minify(file, encoding, callback) {
var options = setup(opts || {});

Expand All @@ -76,7 +76,7 @@ module.exports = function(opts, uglify) {
options.outSourceMap = file.relative;
}

var mangled = trycatch(function() {
var mangled = trycatch(function () {
var m = uglify.minify(String(file.contents), options);
m.code = new Buffer(m.code.replace(reSourceMapComment, ''));
return m;
Expand Down
8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -21,7 +21,8 @@
"gulp-sourcemaps": "^1.0.0",
"istanbul": "^0.4.0",
"tape": "^4.0.0",
"vinyl": "^1.0.0"
"vinyl": "^1.0.0",
"xo": "^0.10.0"
},
"homepage": "https://github.com/terinjokes/gulp-uglify/",
"keywords": [
Expand All @@ -30,8 +31,11 @@
"license": "MIT",
"main": "index.js",
"repository": "https://github.com/terinjokes/gulp-uglify.git",
"xo": {
"space": true
},
"scripts": {
"test": "istanbul cover ./node_modules/tape/bin/tape test/*.js",
"test": "xo && istanbul cover ./node_modules/tape/bin/tape test/*.js",
"coverage": "cat ./coverage/lcov.info | coveralls"
}
}
169 changes: 84 additions & 85 deletions test/comments.js
@@ -1,101 +1,100 @@
'use strict';
var test = require('tape'),
Vinyl = require('vinyl'),
gulpUglify = require('../');


test('should preserve all comments', function(t) {
t.plan(3);

var testFile1 = new Vinyl({
cwd: "/home/terin/broken-promises/",
base: "/home/terin/broken-promises/test",
path: "/home/terin/broken-promises/test/test1.js",
contents: new Buffer('/* comment one *//*! comment two *//* comment three */')
});

var stream = gulpUglify({ preserveComments: 'all' });

stream.on('data', function(newFile) {
var contents = newFile.contents.toString();
t.ok(/one/.test(contents), 'has comment one');
t.ok(/two/.test(contents), 'has comment two');
t.ok(/three/.test(contents), 'has comment three');
});

stream.write(testFile1);
stream.end();
var test = require('tape');
var Vinyl = require('vinyl');
var gulpUglify = require('../');

test('should preserve all comments', function (t) {
t.plan(3);

var testFile1 = new Vinyl({
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test1.js',
contents: new Buffer('/* comment one *//*! comment two *//* comment three */')
});

var stream = gulpUglify({preserveComments: 'all'});

stream.on('data', function (newFile) {
var contents = newFile.contents.toString();
t.ok(/one/.test(contents), 'has comment one');
t.ok(/two/.test(contents), 'has comment two');
t.ok(/three/.test(contents), 'has comment three');
});

stream.write(testFile1);
stream.end();
});

test('should preserve some comments', function(t) {
t.plan(3);
test('should preserve some comments', function (t) {
t.plan(3);

var testFile1 = new Vinyl({
cwd: "/home/terin/broken-promises/",
base: "/home/terin/broken-promises/test",
path: "/home/terin/broken-promises/test/test1.js",
contents: new Buffer('/* comment one *//*! comment two *//* comment three */')
});
var testFile1 = new Vinyl({
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test1.js',
contents: new Buffer('/* comment one *//*! comment two *//* comment three */')
});

var stream = gulpUglify({ preserveComments: 'some' });
var stream = gulpUglify({preserveComments: 'some'});

stream.on('data', function(newFile) {
var contents = newFile.contents.toString();
t.false(/one/.test(contents), 'does not have comment one');
t.ok(/two/.test(contents), 'has comment two');
t.false(/three/.test(contents), 'does not have comment three');
});
stream.on('data', function (newFile) {
var contents = newFile.contents.toString();
t.false(/one/.test(contents), 'does not have comment one');
t.ok(/two/.test(contents), 'has comment two');
t.false(/three/.test(contents), 'does not have comment three');
});

stream.write(testFile1);
stream.end();
stream.write(testFile1);
stream.end();
});

test('should preserve license comments', function(t) {
t.plan(3);
test('should preserve license comments', function (t) {
t.plan(3);

var testFile1 = new Vinyl({
cwd: "/home/terin/broken-promises/",
base: "/home/terin/broken-promises/test",
path: "/home/terin/broken-promises/test/test1.js",
contents: new Buffer('"use strict";\nfunction foobar(){}\n/* comment one */\n/* comment two MIT */\nfunction itsatrap(){}\n/* comment three */')
});
var testFile1 = new Vinyl({
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test1.js',
contents: new Buffer('"use strict";\nfunction foobar(){}\n/* comment one */\n/* comment two MIT */\nfunction itsatrap(){}\n/* comment three */')
});

var stream = gulpUglify({ preserveComments: 'license' });
var stream = gulpUglify({preserveComments: 'license'});

stream.on('data', function(newFile) {
var contents = newFile.contents.toString();
t.false(/one/.test(contents), 'does not have comment one');
t.ok(/two/.test(contents), 'has comment two');
t.false(/three/.test(contents), 'does not have comment three');
});
stream.on('data', function (newFile) {
var contents = newFile.contents.toString();
t.false(/one/.test(contents), 'does not have comment one');
t.ok(/two/.test(contents), 'has comment two');
t.false(/three/.test(contents), 'does not have comment three');
});

stream.write(testFile1);
stream.end();
stream.write(testFile1);
stream.end();
});

test('should preserve comments that fn returns true for', function(t) {
t.plan(3);

var testFile1 = new Vinyl({
cwd: "/home/terin/broken-promises/",
base: "/home/terin/broken-promises/test",
path: "/home/terin/broken-promises/test/test1.js",
contents: new Buffer('/* comment one *//*! comment two *//* comment three */')
});

var stream = gulpUglify({
preserveComments: function(node, comment) {
return /three/.test(comment.value);
}
});

stream.on('data', function(newFile) {
var contents = newFile.contents.toString();
t.false(/one/.test(contents), 'does not have comment one');
t.false(/two/.test(contents), 'does not have comment two');
t.true(/three/.test(contents), 'has comment three');
});

stream.write(testFile1);
stream.end();
test('should preserve comments that fn returns true for', function (t) {
t.plan(3);

var testFile1 = new Vinyl({
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test1.js',
contents: new Buffer('/* comment one *//*! comment two *//* comment three */')
});

var stream = gulpUglify({
preserveComments: function (node, comment) {
return /three/.test(comment.value);
}
});

stream.on('data', function (newFile) {
var contents = newFile.contents.toString();
t.false(/one/.test(contents), 'does not have comment one');
t.false(/two/.test(contents), 'does not have comment two');
t.true(/three/.test(contents), 'has comment three');
});

stream.write(testFile1);
stream.end();
});
94 changes: 47 additions & 47 deletions test/err.js
@@ -1,68 +1,68 @@
'use strict';
var test = require('tape'),
Vinyl = require('vinyl'),
gulpUglify = require('../');
var test = require('tape');
var Vinyl = require('vinyl');
var gulpUglify = require('../');

var testContentsInput = 'function errorFunction(error)\n{';
var testOkContentsInput = '"use strict"; (function(console, first, second) { console.log(first + second) }(5, 10))';

var testFile1 = new Vinyl({
cwd: "/home/terin/broken-promises/",
base: "/home/terin/broken-promises/test",
path: "/home/terin/broken-promises/test/test1.js",
contents: new Buffer(testContentsInput)
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test1.js',
contents: new Buffer(testContentsInput)
});

var testFile2 = new Vinyl({
cwd: "/home/terin/broken-promises/",
base: "/home/terin/broken-promises/test",
path: "/home/terin/broken-promises/test/test2.js",
contents: new Buffer(testOkContentsInput)
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test2.js',
contents: new Buffer(testOkContentsInput)
});

test('should report files in error', function(t) {
t.plan(6);
test('should report files in error', function (t) {
t.plan(6);

var stream = gulpUglify();
var stream = gulpUglify();

stream.on('data', function() {
t.fail('we shouldn\'t have gotten here');
});
stream.on('data', function () {
t.fail('we shouldn\'t have gotten here');
});

stream.on('error', function(e) {
t.ok(e instanceof Error, 'argument should be of type error');
t.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
t.equal(e.fileName, testFile1.path, 'error reports correct file name');
t.equal(e.lineNumber, 2, 'error reports correct line number');
t.ok(e.stack, 'error has a stack');
t.false(e.showStack, 'error is configured to not print the stack');
});
stream.on('error', function (e) {
t.ok(e instanceof Error, 'argument should be of type error');
t.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
t.equal(e.fileName, testFile1.path, 'error reports correct file name');
t.equal(e.lineNumber, 2, 'error reports correct line number');
t.ok(e.stack, 'error has a stack');
t.false(e.showStack, 'error is configured to not print the stack');
});

stream.write(testFile1);
stream.end();
stream.write(testFile1);
stream.end();
});

test('shouldn\'t blow up when given output options', function(t) {
t.plan(5);
test('shouldn\'t blow up when given output options', function (t) {
t.plan(5);

var stream = gulpUglify({
output: {
exportAll: true
}
});
var stream = gulpUglify({
output: {
exportAll: true
}
});

stream.on('data', function() {
t.fail('We shouldn\'t have gotten here');
});
stream.on('data', function () {
t.fail('We shouldn\'t have gotten here');
});

stream.on('error', function(e) {
t.ok(e instanceof Error, 'argument should be of type error');
t.equals(e.message, testFile2.path + ': `exportAll` is not a supported option');
t.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
t.equal(e.fileName, testFile2.path, 'error reports correct file name');
t.false(e.showStack, 'error is configured to not print the stack');
});
stream.on('error', function (e) {
t.ok(e instanceof Error, 'argument should be of type error');
t.equals(e.message, testFile2.path + ': `exportAll` is not a supported option');
t.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
t.equal(e.fileName, testFile2.path, 'error reports correct file name');
t.false(e.showStack, 'error is configured to not print the stack');
});

stream.write(testFile2);
stream.end();
stream.write(testFile2);
stream.end();
});

0 comments on commit 735e04d

Please sign in to comment.