Skip to content

Commit

Permalink
[eslint] enable curly, object-curly-spacing, object-curly-newline
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 24, 2021
1 parent 1af8f52 commit e9b75e1
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 47 deletions.
14 changes: 14 additions & 0 deletions .eslintrc
Expand Up @@ -13,6 +13,7 @@
"before": false,
"after": true,
}],
"curly": ["error", "all"],
"indent": ["error", 4],
"key-spacing": "error",
"quotes": ["error", "single", {
Expand All @@ -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",
Expand Down
18 changes: 9 additions & 9 deletions index.js
Expand Up @@ -25,7 +25,7 @@ module.exports = (function () {
lazyLoad.run = function () {
var run = getHarness().run;

if (run) run();
if (run) { run(); }
};

lazyLoad.only = function () {
Expand Down Expand Up @@ -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;
}
}());
Expand All @@ -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.
Expand All @@ -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();
}
}
Expand All @@ -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());
Expand Down Expand Up @@ -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));

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/default_stream.js
Expand Up @@ -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; }
}
}

Expand Down
41 changes: 25 additions & 16 deletions lib/results.js
Expand Up @@ -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;
Expand All @@ -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 = {
Expand Down Expand Up @@ -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');
});
Expand All @@ -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');
});

Expand All @@ -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');
}
Expand All @@ -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);
};
Expand All @@ -161,16 +170,16 @@ function encodeResult(res, count) {
}

output += '\n';
if (res.ok) return output;
if (res.ok) { return output; }

var outer = ' ';
var inner = outer + ' ';
output += outer + '---\n';
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';
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 11 additions & 5 deletions lib/test.js
Expand Up @@ -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_) {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/comment.js
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/deep-equal-failure.js
Expand Up @@ -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 });
});
});

Expand Down Expand Up @@ -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 } } } } } });
});
Expand Down
6 changes: 3 additions & 3 deletions test/ignore_from_gitignore.js
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/not-deep-equal-failure.js
Expand Up @@ -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 });
});
});

Expand Down Expand Up @@ -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 } } } } } });
});
Expand Down
8 changes: 4 additions & 4 deletions test/objectMode.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion test/onFailure.js
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/onFinish.js
Expand Up @@ -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');
Expand Down

0 comments on commit e9b75e1

Please sign in to comment.