diff --git a/.eslintrc b/.eslintrc index cd66dba1..7c161435 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,6 +13,7 @@ "before": false, "after": true, }], + "curly": ["error", "all"], "indent": ["error", 4], "key-spacing": "error", "quotes": ["error", "single", { @@ -26,6 +27,19 @@ "no-extra-semi": "error", "no-undef": "error", "no-useless-escape": "error", + "object-curly-newline": ["error", { + "ObjectExpression": { + "multiline": true, + "consistent": true, + "minProperties": 3, + }, + "ObjectPattern": { + "multiline": true, + "consistent": true, + "minProperties": 3, + }, + }], + "object-curly-spacing": ["error", "always"], "operator-linebreak": ["error", "before"], "semi-style": ["error", "last"], "space-infix-ops": "error", diff --git a/index.js b/index.js index be759e87..10200482 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ module.exports = (function () { lazyLoad.run = function () { var run = getHarness().run; - if (run) run(); + if (run) { run(); } }; lazyLoad.only = function () { @@ -55,9 +55,9 @@ module.exports = (function () { return lazyLoad; function getHarness(opts) { - if (!opts) opts = {}; + if (!opts) { opts = {}; } opts.autoclose = !canEmitExit; - if (!harness) harness = createExitHarness(opts, wait); + if (!harness) { harness = createExitHarness(opts, wait); } return harness; } }()); @@ -76,8 +76,8 @@ function createExitHarness(conf, wait) { run(); } - if (config.exit === false) return harness; - if (!canEmitExit || !canExit) return harness; + if (config.exit === false) { return harness; } + if (!canEmitExit || !canExit) { return harness; } process.on('exit', function (code) { // let the process exit cleanly. @@ -89,7 +89,7 @@ function createExitHarness(conf, wait) { var only = harness._results._only; for (var i = 0; i < harness._tests.length; i++) { var t = harness._tests[i]; - if (only && t !== only) continue; + if (only && t !== only) { continue; } t._exit(); } } @@ -102,7 +102,7 @@ function createExitHarness(conf, wait) { return harness; function run() { - if (running) return; + if (running) { return; } running = true; var stream = harness.createStream({ objectMode: config.objectMode }); var es = stream.pipe(config.stream || createDefaultStream()); @@ -133,7 +133,7 @@ function createHarness(conf_) { inspectCode(st_); }); st.on('result', function (r) { - if (!r.todo && !r.ok && typeof r !== 'string') test._exitCode = 1; + if (!r.todo && !r.ok && typeof r !== 'string') { test._exitCode = 1; } }); }(t)); @@ -158,7 +158,7 @@ function createHarness(conf_) { var only = false; test.only = function () { - if (only) throw new Error('there can only be one only test'); + if (only) { throw new Error('there can only be one only test'); } only = true; var t = test.apply(null, arguments); results.only(t); diff --git a/lib/default_stream.js b/lib/default_stream.js index 03dcba0a..75458a9d 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -13,8 +13,8 @@ module.exports = function () { var c = typeof buf === 'string' ? buf.charAt(i) : String.fromCharCode(buf[i]); - if (c === '\n') flush(); - else line += c; + if (c === '\n') { flush(); } + else { line += c; } } } diff --git a/lib/results.js b/lib/results.js index 35b6569d..eac95bb8 100644 --- a/lib/results.js +++ b/lib/results.js @@ -25,7 +25,7 @@ function coalesceWhiteSpaces(str) { } function Results() { - if (!(this instanceof Results)) return new Results; + if (!(this instanceof Results)) { return new Results(); } this.count = 0; this.fail = 0; this.pass = 0; @@ -37,13 +37,13 @@ function Results() { } Results.prototype.createStream = function (opts) { - if (!opts) opts = {}; + if (!opts) { opts = {}; } var self = this; var output, testId = 0; if (opts.objectMode) { output = through(); self.on('_push', function ontest(t, extra) { - if (!extra) extra = {}; + if (!extra) { extra = {}; } var id = testId++; t.once('prerun', function () { var row = { @@ -85,7 +85,9 @@ Results.prototype.createStream = function (opts) { var t; while (t = getNextTest(self)) { t.run(); - if (!t.ended) return t.once('end', function () { nextTick(next); }); + if (!t.ended) { + return t.once('end', function () { nextTick(next); }); + } } self.emit('done'); }); @@ -110,8 +112,11 @@ Results.prototype._watch = function (t) { var write = function (s) { self._stream.queue(s); }; t.once('prerun', function () { var premsg = ''; - if (t._skip) premsg = 'SKIP '; - else if (t._todo) premsg = 'TODO '; + if (t._skip) { + premsg = 'SKIP '; + } else if (t._todo) { + premsg = 'TODO '; + } write('# ' + premsg + coalesceWhiteSpaces(t.name) + '\n'); }); @@ -123,8 +128,9 @@ Results.prototype._watch = function (t) { write(encodeResult(res, self.count + 1)); self.count++; - if (res.ok || res.todo) self.pass++; - else { + if (res.ok || res.todo) { + self.pass++; + } else { self.fail++; self.emit('fail'); } @@ -135,16 +141,19 @@ Results.prototype._watch = function (t) { Results.prototype.close = function () { var self = this; - if (self.closed) self._stream.emit('error', new Error('ALREADY CLOSED')); + if (self.closed) { self._stream.emit('error', new Error('ALREADY CLOSED')); } self.closed = true; var write = function (s) { self._stream.queue(s); }; write('\n1..' + self.count + '\n'); write('# tests ' + self.count + '\n'); write('# pass ' + (self.pass + self.todo) + '\n'); - if (self.todo) write('# todo ' + self.todo + '\n'); - if (self.fail) write('# fail ' + self.fail + '\n'); - else write('\n# ok\n'); + if (self.todo) { write('# todo ' + self.todo + '\n'); } + if (self.fail) { + write('# fail ' + self.fail + '\n'); + } else { + write('\n# ok\n'); + } self._stream.queue(null); }; @@ -161,7 +170,7 @@ function encodeResult(res, count) { } output += '\n'; - if (res.ok) return output; + if (res.ok) { return output; } var outer = ' '; var inner = outer + ' '; @@ -169,8 +178,8 @@ function encodeResult(res, count) { output += inner + 'operator: ' + res.operator + '\n'; if (has(res, 'expected') || has(res, 'actual')) { - var ex = inspect(res.expected, {depth: res.objectPrintDepth}); - var ac = inspect(res.actual, {depth: res.objectPrintDepth}); + var ex = inspect(res.expected, { depth: res.objectPrintDepth }); + var ac = inspect(res.actual, { depth: res.objectPrintDepth }); if (Math.max(ex.length, ac.length) > 65 || invalidYaml(ex) || invalidYaml(ac)) { output += inner + 'expected: |-\n' + inner + ' ' + ex + '\n'; @@ -206,7 +215,7 @@ function getNextTest(results) { do { var t = $shift(results.tests); - if (!t) continue; + if (!t) { continue; } if (results._only === t) { return t; } diff --git a/lib/test.js b/lib/test.js index bf27b818..37a85348 100644 --- a/lib/test.js +++ b/lib/test.js @@ -49,7 +49,11 @@ var getTestArgs = function (name_, opts_, cb_) { cb = arg; } } - return { name: name, opts: opts, cb: cb }; + return { + name: name, + opts: opts, + cb: cb + }; }; function Test(name_, opts_, cb_) { @@ -167,7 +171,7 @@ Test.prototype.plan = function plan(n) { }; Test.prototype.timeoutAfter = function timeoutAfter(ms) { - if (!ms) throw new Error('timeoutAfter requires a timespan'); + if (!ms) { throw new Error('timeoutAfter requires a timespan'); } var self = this; var timeout = safeSetTimeout(function () { self.fail(self.name + ' timed out after ' + ms + 'ms'); @@ -201,7 +205,9 @@ Test.prototype.teardown = function teardown(fn) { Test.prototype._end = function _end(err) { var self = this; - if (!this._cb && !this._todo && !this._skip) this.fail('# TODO ' + this.name); + if (!this._cb && !this._todo && !this._skip) { + this.fail('# TODO ' + this.name); + } if (this._progeny.length) { var t = $shift(this._progeny); @@ -234,7 +240,7 @@ Test.prototype._end = function _end(err) { next(); function completeEnd() { - if (!self.ended) self.emit('end'); + if (!self.ended) { self.emit('end'); } var pendingAsserts = self._pendingAsserts(); if (!self._planError && self._plan !== undefined && pendingAsserts) { self._planError = true; @@ -363,7 +369,7 @@ Test.prototype._assert = function assert(ok, opts) { res.functionName = $split(callDescription, /\s+/)[0]; res.file = filePath; res.line = Number(m[3]); - if (m[4]) res.column = Number(m[4]); + if (m[4]) { res.column = Number(m[4]); } res.at = callDescription + ' (' + filePath + ')'; break; diff --git a/test/comment.js b/test/comment.js index 378db5a8..c63395ac 100644 --- a/test/comment.js +++ b/test/comment.js @@ -132,7 +132,7 @@ tap.test('non-string types', function (assert) { t.comment(42); t.comment(6.66); t.comment({}); - t.comment({'answer': 42}); + t.comment({ answer: 42 }); function ConstructorFunction() {} t.comment(new ConstructorFunction()); t.comment(ConstructorFunction); diff --git a/test/deep-equal-failure.js b/test/deep-equal-failure.js index d5f1bc74..80216ff1 100644 --- a/test/deep-equal-failure.js +++ b/test/deep-equal-failure.js @@ -66,7 +66,7 @@ tap.test('deep equal failure', function (assert) { test('deep equal', function (t) { t.plan(1); - t.equal({a: 1}, {b: 2}); + t.equal({ a: 1 }, { b: 2 }); }); }); @@ -125,7 +125,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { }); }); - test('deep equal', {objectPrintDepth: 6}, function (t) { + test('deep equal', { objectPrintDepth: 6 }, function (t) { t.plan(1); t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }); }); diff --git a/test/ignore_from_gitignore.js b/test/ignore_from_gitignore.js index d95260b8..cda47b84 100644 --- a/test/ignore_from_gitignore.js +++ b/test/ignore_from_gitignore.js @@ -38,7 +38,7 @@ tap.test('Should pass with ignoring', { skip: process.platform === 'win32' }, fu ]); }; - var ps = spawn(tapeBin, ['**/*.js', '-i', '.ignore'], {cwd: path.join(__dirname, 'ignore')}); + var ps = spawn(tapeBin, ['**/*.js', '-i', '.ignore'], { cwd: path.join(__dirname, 'ignore') }); ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { tt.equal(code, 0); // code 0 @@ -95,7 +95,7 @@ tap.test('Should pass', { skip: process.platform === 'win32' }, function (tt) { ]); }; - var ps = spawn(tapeBin, ['**/*.js'], {cwd: path.join(__dirname, 'ignore')}); + var ps = spawn(tapeBin, ['**/*.js'], { cwd: path.join(__dirname, 'ignore') }); ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { tt.equal(code, 1); @@ -113,7 +113,7 @@ tap.test('Should fail when ignore file does not exist', { skip: process.platform tt.ok(/^ENOENT[:,] no such file or directory,? (?:open )?'\$TEST\/ignore\/.gitignore'\n$/m.test(stripFullStack(rows.toString('utf8')).join('\n'))); }; - var ps = spawn(tapeBin, ['**/*.js', '-i'], {cwd: path.join(__dirname, 'ignore')}); + var ps = spawn(tapeBin, ['**/*.js', '-i'], { cwd: path.join(__dirname, 'ignore') }); ps.stdout.pipe(concat(testStdout)); ps.stderr.pipe(concat(testStderr)); ps.on('exit', function (code) { diff --git a/test/not-deep-equal-failure.js b/test/not-deep-equal-failure.js index dadfa535..c90453dc 100644 --- a/test/not-deep-equal-failure.js +++ b/test/not-deep-equal-failure.js @@ -66,7 +66,7 @@ tap.test('deep equal failure', function (assert) { test('not deep equal', function (t) { t.plan(1); - t.notDeepEqual({b: 2}, {b: 2}); + t.notDeepEqual({ b: 2 }, { b: 2 }); }); }); @@ -125,7 +125,7 @@ tap.test('not deep equal failure, depth 6, with option', function (assert) { }); }); - test('not deep equal', {objectPrintDepth: 6}, function (t) { + test('not deep equal', { objectPrintDepth: 6 }, function (t) { t.plan(1); t.notDeepEqual({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }); }); diff --git a/test/objectMode.js b/test/objectMode.js index 3a7cf379..0145a691 100644 --- a/test/objectMode.js +++ b/test/objectMode.js @@ -14,7 +14,7 @@ tap.test('object results', function (assert) { }; printer.end = function (obj) { - if (obj) objects.push(obj); + if (obj) { objects.push(obj); } var todos = 0; var skips = 0; @@ -53,17 +53,17 @@ tap.test('object results', function (assert) { tape('parent', function (t1) { t1.equal(true, true); - t1.test('child1', {skip: true}, function (t2) { + t1.test('child1', { skip: true }, function (t2) { t2.equal(true, true); t2.equal(true, false); t2.end(); }); - t1.test('child2', {todo: true}, function (t3) { + t1.test('child2', { todo: true }, function (t3) { t3.equal(true, false); t3.equal(true, true); t3.end(); }); - t1.test('child3', {todo: true}); + t1.test('child3', { todo: true }); t1.equal(true, true); t1.equal(true, true); t1.end(); diff --git a/test/onFailure.js b/test/onFailure.js index 7ae77df6..8420a822 100644 --- a/test/onFailure.js +++ b/test/onFailure.js @@ -6,7 +6,12 @@ var tape = require('../').createHarness(); //Because this test passing depends on a failure, //we must direct the failing output of the inner test var noop = function () {}; -var mockSink = {on: noop, removeListener: noop, emit: noop, end: noop}; +var mockSink = { + on: noop, + removeListener: noop, + emit: noop, + end: noop +}; tape.createStream().pipe(mockSink); tap.test('on failure', { timeout: 1000 }, function (tt) { diff --git a/test/onFinish.js b/test/onFinish.js index ba7597c4..db3b7609 100644 --- a/test/onFinish.js +++ b/test/onFinish.js @@ -3,7 +3,7 @@ var tap = require('tap'); var tape = require('../'); -tap.test('on finish', {timeout: 1000}, function (tt) { +tap.test('on finish', { timeout: 1000 }, function (tt) { tt.plan(1); tape.onFinish(function () { tt.pass('tape ended'); diff --git a/test/throws.js b/test/throws.js index 70d90cef..c0cb895d 100644 --- a/test/throws.js +++ b/test/throws.js @@ -24,7 +24,11 @@ var getter = function () { return 'message'; }; var messageGetterError = Object.defineProperty( { custom: 'error' }, 'message', - { configurable: true, enumerable: true, get: getter } + { + configurable: true, + enumerable: true, + get: getter + } ); var thrower = function () { throw messageGetterError; };