Skip to content

Commit

Permalink
[lint] enforce consistent semicolon usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 24, 2019
1 parent c6c4ace commit a5006ce
Show file tree
Hide file tree
Showing 36 changed files with 126 additions and 125 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"root": true,
"rules": {
"indent": ["error", 4],
"space-before-function-paren": [2, {
"semi": ["error", "always"],
"space-before-function-paren": ["error", {
"anonymous": "always",
"named": "never",
}],
Expand Down
2 changes: 1 addition & 1 deletion example/stream/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var test = require('../../');
var path = require('path');

test.createStream({ objectMode: true }).on('data', function (row) {
console.log(JSON.stringify(row))
console.log(JSON.stringify(row));
});

process.argv.slice(2).forEach(function (file) {
Expand Down
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ exports = module.exports = (function () {
return getHarness().onFailure.apply(this, arguments);
};

lazyLoad.getHarness = getHarness
lazyLoad.getHarness = getHarness;

return lazyLoad
return lazyLoad;

function getHarness(opts) {
if (!opts) opts = {};
Expand All @@ -65,19 +65,19 @@ function createExitHarness(conf) {
var stream = harness.createStream({ objectMode: conf.objectMode });
var es = stream.pipe(conf.stream || createDefaultStream());
if (canEmitExit) {
es.on('error', function (err) { harness._exitCode = 1 });
es.on('error', function (err) { harness._exitCode = 1; });
}

var ended = false;
stream.on('end', function () { ended = true });
stream.on('end', function () { ended = true; });

if (conf.exit === false) return harness;
if (!canEmitExit || !canExit) return harness;

process.on('exit', function (code) {
// let the process exit cleanly.
if (code !== 0) {
return
return;
}

if (!ended) {
Expand Down Expand Up @@ -106,7 +106,7 @@ function createHarness(conf_) {
if (!conf_) conf_ = {};
var results = createResult();
if (conf_.autoclose !== false) {
results.once('done', function () { results.close() });
results.once('done', function () { results.close(); });
}

var test = function (name, conf, cb) {
Expand All @@ -118,7 +118,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);

Expand Down Expand Up @@ -151,7 +151,7 @@ function createHarness(conf_) {
};
test._exitCode = 0;

test.close = function () { results.close() };
test.close = function () { results.close(); };

return test;
}
6 changes: 3 additions & 3 deletions lib/default_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ module.exports = function () {
function flush() {
if (fs.writeSync && /^win/.test(process.platform)) {
try { fs.writeSync(1, line + '\n'); }
catch (e) { stream.emit('error', e) }
catch (e) { stream.emit('error', e); }
} else {
try { console.log(line) }
catch (e) { stream.emit('error', e) }
try { console.log(line); }
catch (e) { stream.emit('error', e); }
}
line = '';
}
Expand Down
12 changes: 6 additions & 6 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Results.prototype.createStream = function (opts) {
output.queue({ type: 'end', test: id });
});
});
self.on('done', function () { output.queue(null) });
self.on('done', function () { output.queue(null); });
} else {
output = resumer();
output.queue('TAP version 13\n');
Expand Down Expand Up @@ -95,7 +95,7 @@ Results.prototype.only = function (t) {

Results.prototype._watch = function (t) {
var self = this;
var write = function (s) { self._stream.queue(s) };
var write = function (s) { self._stream.queue(s); };
t.once('prerun', function () {
write('# ' + t.name + '\n');
});
Expand All @@ -108,21 +108,21 @@ Results.prototype._watch = function (t) {
write(encodeResult(res, self.count + 1));
self.count ++;

if (res.ok || res.todo) self.pass ++
if (res.ok || res.todo) self.pass ++;
else {
self.fail ++;
self.emit('fail');
}
});

t.on('test', function (st) { self._watch(st) });
t.on('test', function (st) { self._watch(st); });
};

Results.prototype.close = function () {
var self = this;
if (self.closed) self._stream.emit('error', new Error('ALREADY CLOSED'));
self.closed = true;
var write = function (s) { self._stream.queue(s) };
var write = function (s) { self._stream.queue(s); };

write('\n1..' + self.count + '\n');
write('# tests ' + self.count + '\n');
Expand Down Expand Up @@ -192,7 +192,7 @@ function getNextTest(results) {
if (results._only === t) {
return t;
}
} while (results.tests.length !== 0)
} while (results.tests.length !== 0);
}

function invalidYaml(str) {
Expand Down
10 changes: 5 additions & 5 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Test.prototype.test = function (name, opts, cb) {
this.emit('test', t);
t.on('prerun', function () {
self.assertCount++;
})
});

if (!self._pendingAsserts()) {
nextTick(function () {
Expand Down Expand Up @@ -142,7 +142,7 @@ Test.prototype.timeoutAfter = function (ms) {
this.once('end', function () {
safeClearTimeout(timeout);
});
}
};

Test.prototype.end = function (err) {
var self = this;
Expand All @@ -161,7 +161,7 @@ Test.prototype._end = function (err) {
var self = this;
if (this._progeny.length) {
var t = this._progeny.shift();
t.on('end', function () { self._end() });
t.on('end', function () { self._end(); });
t.run();
return;
}
Expand Down Expand Up @@ -267,7 +267,7 @@ Test.prototype._assert = function assert(ok, opts) {
/((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/
*/
var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/
var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/;
var m = re.exec(err[i]);

if (!m) {
Expand All @@ -283,7 +283,7 @@ Test.prototype._assert = function assert(ok, opts) {

// Function call description may not (just) be a function name.
// Try to extract function name by looking at first "word" only.
res.functionName = callDescription.split(/\s+/)[0]
res.functionName = callDescription.split(/\s+/)[0];
res.file = filePath;
res.line = Number(m[3]);
if (m[4]) res.column = Number(m[4]);
Expand Down
4 changes: 2 additions & 2 deletions test/add-subtest-async.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var test = require('../')
var test = require('../');

test('parent', function (t) {
t.pass('parent');
Expand All @@ -8,4 +8,4 @@ test('parent', function (t) {
st.end();
});
}, 100);
})
});
2 changes: 1 addition & 1 deletion test/anonymous-fn/test-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function (testCase) {
testCase(t);
tearDown();
};
}
};

function setUp() {
// ... example ...
Expand Down
4 changes: 2 additions & 2 deletions test/circular-things.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ tap.test('circular test', function (assert) {
var circular = {};
circular.circular = circular;
t.equal(circular, {});
})
})
});
});
8 changes: 4 additions & 4 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports.getDiag = function (body) {
delete withStack.stack;
delete withStack.at;
return withStack;
}
};

// There are three challenges associated with checking the stack traces included
// in errors:
Expand Down Expand Up @@ -43,7 +43,7 @@ module.exports.stripFullStack = function (output) {
var withoutLineNumbers = withoutPathSep.replace(/:\d+:\d+/g, ':$LINE:$COL');
var withoutNestedLineNumbers = withoutLineNumbers.replace(/, \<anonymous\>:\$LINE:\$COL\)$/, ')');
return withoutNestedLineNumbers;
}
};

if (m) {
if (m[1].slice(0, __dirname.length) === __dirname) {
Expand All @@ -52,12 +52,12 @@ module.exports.stripFullStack = function (output) {
return stripped;
}
return stripChangingData(line);
})
});

var deduped = withDuplicates.filter(function (line, ix) {
var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped;
return !hasPrior;
});

return deduped.join('\n');
}
};
4 changes: 2 additions & 2 deletions test/create_multiple_streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ tape.test('createMultipleStreams', function (tt) {
tt.plan(2);

var th = tape.createHarness();
th.createStream()
th.createStream()
th.createStream();
th.createStream();

var testOneComplete = false;

Expand Down
6 changes: 3 additions & 3 deletions test/deep-equal-failure.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tap.test('deep equal failure', function (assert) {
t.plan(1);
t.equal({a: 1}, {b: 2});
});
})
});

tap.test('deep equal failure, depth 6, with option', function (assert) {
var test = tape.createHarness({ exit : false });
Expand Down Expand Up @@ -127,7 +127,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {
t.plan(1);
t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } });
});
})
});

tap.test('deep equal failure, depth 6, without option', function (assert) {
var test = tape.createHarness({ exit : false });
Expand Down Expand Up @@ -188,4 +188,4 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
t.plan(1);
t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } });
});
})
});
2 changes: 1 addition & 1 deletion test/double_end.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test(function (t) {
// This code is unfortunately by necessity highly coupled to node
// versions, and may require tweaking with future versions of the timers
// library.
function doEnd() { throw new Error() };
function doEnd() { throw new Error(); };
var to = setTimeout(doEnd, 5000);
clearTimeout(to);
to._onTimeout = doEnd;
Expand Down
32 changes: 16 additions & 16 deletions test/end-as-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var tape = require("../");
var concat = require('concat-stream');

tap.test("tape assert.end as callback", function (tt) {
var test = tape.createHarness({ exit: false })
var test = tape.createHarness({ exit: false });

test.createStream().pipe(concat(function (rows) {
tt.equal(rows.toString('utf8'), [
Expand All @@ -23,38 +23,38 @@ tap.test("tape assert.end as callback", function (tt) {
'# pass 4',
'# fail 1'
].join('\n') + '\n');
tt.end()
tt.end();
}));

test("do a task and write", function (assert) {
fakeAsyncTask("foo", function (err, value) {
assert.ifError(err)
assert.equal(value, "taskfoo")
assert.ifError(err);
assert.equal(value, "taskfoo");

fakeAsyncWrite("bar", assert.end)
})
})
fakeAsyncWrite("bar", assert.end);
});
});

test("do a task and write fail", function (assert) {
fakeAsyncTask("bar", function (err, value) {
assert.ifError(err)
assert.equal(value, "taskbar")
assert.ifError(err);
assert.equal(value, "taskbar");

fakeAsyncWriteFail("baz", assert.end)
})
})
})
fakeAsyncWriteFail("baz", assert.end);
});
});
});

function fakeAsyncTask(name, cb) {
cb(null, "task" + name)
cb(null, "task" + name);
}

function fakeAsyncWrite(name, cb) {
cb(null)
cb(null);
}

function fakeAsyncWriteFail(name, cb) {
cb(new Error("fail"))
cb(new Error("fail"));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tap.test('exit ok', function (t) {
'', // yes, these double-blank-lines at the end are required.
'' // if you can figure out how to remove them, please do!
].join('\n'));
}
};

var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'ok.js')]);
ps.stdout.pipe(concat(tc));
Expand Down
8 changes: 4 additions & 4 deletions test/exposed-harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ var tap = require('tap');

tap.test('main harness object is exposed', function (assert) {

assert.equal(typeof tape.getHarness, 'function', 'tape.getHarness is a function')
assert.equal(typeof tape.getHarness, 'function', 'tape.getHarness is a function');

assert.equal(tape.getHarness()._results.pass, 0)
assert.equal(tape.getHarness()._results.pass, 0);

assert.end()
assert.end();

})
});
2 changes: 1 addition & 1 deletion test/many.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ var test = require('../');
test('many tests', function (t) {
t.plan(100);
for (var i = 0; i < 100; i++) {
setTimeout(function () { t.pass() }, Math.random() * 50);
setTimeout(function () { t.pass(); }, Math.random() * 50);
}
});
2 changes: 1 addition & 1 deletion test/max_listeners/source.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var test = require('../../');

for (var i = 0; i < 11; i ++) {
test(function (t) { t.ok(true, 'true is truthy'); t.end() });
test(function (t) { t.ok(true, 'true is truthy'); t.end(); });
}

0 comments on commit a5006ce

Please sign in to comment.