diff --git a/.eslintrc b/.eslintrc index bb86a337..0403f3b8 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,79 +4,27 @@ "browser": true, "node": true, }, + "extends": "@ljharb", "globals": { "Promise": false, }, "rules": { - "brace-style": ["error", "1tbs", { - "allowSingleLine": true, - }], - "comma-dangle": ["error", "never"], - "comma-spacing": [2, { - "before": false, - "after": true, - }], - "consistent-return": "error", - "curly": ["error", "all"], - "function-paren-newline": ["error", "multiline"], - "function-call-argument-newline": ["error", "consistent"], + "array-bracket-spacing": "off", + "complexity": "off", + "eqeqeq": ["error", "always", { "null": "ignore" }], + "func-style": "warn", "indent": ["error", 4], - "key-spacing": "error", - "quotes": ["error", "single", { - "avoidEscape": true, - }], - "semi": ["error", "always"], - "space-before-function-paren": ["error", { - "anonymous": "always", - "named": "never", - }], - "no-extra-parens": ["error", "all", { - "conditionalAssign": false, - "nestedBinaryExpressions": false, - "returnAssign": false, - "ignoreJSX": "all", - "enforceForArrowConditionals": false, - "enforceForSequenceExpressions": true, - "enforceForNewInMemberExpressions": false, - }], - "no-extra-semi": "error", - "no-shadow": ["error", { - "builtinGlobals": false, - "hoist": "functions", - "allow": [] - }], - "no-undef": "error", - "no-unused-vars": ["error", { - "vars": "all", - "args": "after-used" - }], - "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"], + "no-magic-numbers": "off", + "max-lines": "warn", + "max-lines-per-function": "warn", + "max-statements": "warn", + "max-statements-per-line": [2, { "max": 2 }], + "multiline-comment-style": "off", + "no-negated-condition": "off", + "no-use-before-define": "warn", + "no-underscore-dangle": "warn", "operator-linebreak": ["error", "before"], - "semi-style": ["error", "last"], - "space-in-parens": ["error", "never"], - "space-infix-ops": "error", - "space-unary-ops": ["error", { - "words": false, - "nonwords": false, - }], - "strict": "error", - "wrap-iife": ["error", "outside", { - "functionPrototypeMethods": true, - }], - "wrap-regex": "error", + "sort-keys": "warn", }, "ignorePatterns": [ "syntax-error.*" ], "overrides": [ @@ -84,12 +32,50 @@ "files": ["*.mjs", "test/import/package_type/*.js"], "extends": "@ljharb/eslint-config/esm", }, + { + "files": ["bin/**"], + "rules": { + "global-require": "off", + "no-process-exit": "off", + "quote-props": ["error", "as-needed", { + "keywords": false, + }], + }, + }, { "files": ["bin/import-or-require.js"], "parserOptions": { "ecmaVersion": 2020, }, }, + { + "files": ["index.js"], + "rules": { + "no-param-reassign": "warn", + }, + }, + { + "files": ["lib/results.js"], + "rules": { + "no-cond-assign": "warn", + "no-param-reassign": "warn", + "no-plusplus": "warn", + }, + }, + { + "files": ["lib/test.js"], + "rules": { + "eqeqeq": "warn", + "func-name-matching": "off", + "max-params": "off", + "no-continue": "off", + "no-invalid-this": "off", + "no-param-reassign": "warn", + "no-plusplus": "warn", + "no-multi-assign": "off", + "no-restricted-syntax": "off", + }, + }, { "files": ["test/async-await/*"], "parserOptions": { @@ -101,6 +87,37 @@ "globals": { "g": false, }, + "rules": { + "no-new-func": "off", + }, + }, + { + "files": ["example/**"], + "rules": { + "array-bracket-newline": "off", + "global-require": "off", + "no-console": "off", + }, + }, + { + "files": ["test/**"], + "rules": { + "dot-notation": [2, { + "allowKeywords": true, + "allowPattern": "throws" + }], + "id-length": "off", + "max-len": "off", + "max-lines-per-function": "off", + "no-plusplus": "off", + "no-throw-literal": "off", + }, + }, + { + "files": ["test/*/**"], + "rules": { + "camelcase": "off", + }, }, ], } diff --git a/index.js b/index.js index 386e16b6..04abc529 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,7 @@ module.exports = (function () { var wait = false; var harness; var lazyLoad = function () { + // eslint-disable-next-line no-invalid-this return getHarness().apply(this, arguments); }; @@ -89,14 +90,15 @@ 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; } - t._exit(); + if (!only || t === only) { + t._exit(); + } } } harness.close(); process.removeAllListeners('exit'); // necessary for node v0.6 - process.exit(code || harness._exitCode); + process.exit(code || harness._exitCode); // eslint-disable-line no-process-exit }); return harness; diff --git a/lib/default_stream.js b/lib/default_stream.js index 4647d93b..9e6372ec 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -30,7 +30,7 @@ module.exports = function () { } } else { try { - console.log(line); + console.log(line); // eslint-disable-line no-console } catch (e) { stream.emit('error', e); } diff --git a/lib/results.js b/lib/results.js index fc8b42e3..89ae72fc 100644 --- a/lib/results.js +++ b/lib/results.js @@ -39,7 +39,8 @@ function Results() { Results.prototype.createStream = function (opts) { if (!opts) { opts = {}; } var self = this; - var output, testId = 0; + var output; + var testId = 0; if (opts.objectMode) { output = through(); self.on('_push', function ontest(t, extra) { diff --git a/lib/test.js b/lib/test.js index abdc2e10..117a8e98 100644 --- a/lib/test.js +++ b/lib/test.js @@ -101,6 +101,7 @@ function Test(name_, opts_, cb_) { } } +// eslint-disable-next-line consistent-return Test.prototype.run = function run() { this.emit('prerun'); if (!this._cb || this._skip) { @@ -131,6 +132,7 @@ Test.prototype.run = function run() { } self.end(); }); + // eslint-disable-next-line consistent-return return; } @@ -232,6 +234,7 @@ Test.prototype._end = function _end(err) { } if (res && typeof res.then === 'function') { res.then(next, function (_err) { + // TODO: wth? err = err || _err; }); } else { diff --git a/test/async-await.js b/test/async-await.js index b34a0499..8a6a3ebc 100644 --- a/test/async-await.js +++ b/test/async-await.js @@ -9,7 +9,7 @@ var nodeVersion = process.versions.node; var majorVersion = nodeVersion.split('.')[0]; if (Number(majorVersion) < 8) { - process.exit(0); + process.exit(0); // eslint-disable-line no-process-exit } tap.test('async1', function (t) { diff --git a/test/async-await/async-error.js b/test/async-await/async-error.js index 35fc27a2..ae02da57 100644 --- a/test/async-await/async-error.js +++ b/test/async-await/async-error.js @@ -5,5 +5,6 @@ var test = require('../../'); test('async-error', async function myTest(t) { t.ok(true, 'before throw'); throw new Error('oopsie'); + /* eslint no-unreachable: 0 */ t.ok(true, 'after throw'); }); diff --git a/test/async-await/sync-error.js b/test/async-await/sync-error.js index 989f4f7f..f2d825cc 100644 --- a/test/async-await/sync-error.js +++ b/test/async-await/sync-error.js @@ -5,6 +5,7 @@ var test = require('../../'); test('sync-error', function myTest(t) { t.ok(true, 'before throw'); throw new Error('oopsie'); + /* eslint no-unreachable: 0 */ t.ok(true, 'after throw'); t.end(); }); diff --git a/test/deep-equal-failure.js b/test/deep-equal-failure.js index 80216ff1..dfdff536 100644 --- a/test/deep-equal-failure.js +++ b/test/deep-equal-failure.js @@ -50,8 +50,6 @@ tap.test('deep equal failure', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -59,7 +57,10 @@ tap.test('deep equal failure', function (assert) { diag: { operator: 'equal', expected: '{ b: 2 }', - actual: '{ a: 1 }' + actual: '{ a: 1 }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); @@ -111,8 +112,6 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -120,7 +119,10 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { diag: { operator: 'equal', expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); @@ -172,8 +174,6 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -181,7 +181,10 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { diag: { operator: 'equal', expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); diff --git a/test/import.js b/test/import.js index e2581e75..f4072326 100644 --- a/test/import.js +++ b/test/import.js @@ -189,9 +189,7 @@ tap.test('errors importing test files', function (t) { }); function tape(args, options) { - options = assign({ cwd: __dirname }, options); - var bin = __dirname + '/../bin/tape'; - return spawn('node', [bin].concat(args.split(' ')), options); + return spawn('node', [bin].concat(args.split(' ')), assign({ cwd: __dirname }, options)); } diff --git a/test/max_listeners/source.js b/test/max_listeners/source.js index e801853e..137f8a1c 100644 --- a/test/max_listeners/source.js +++ b/test/max_listeners/source.js @@ -3,5 +3,8 @@ 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(); + }); } diff --git a/test/not-deep-equal-failure.js b/test/not-deep-equal-failure.js index c90453dc..d02ab0ef 100644 --- a/test/not-deep-equal-failure.js +++ b/test/not-deep-equal-failure.js @@ -50,8 +50,6 @@ tap.test('deep equal failure', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -59,7 +57,10 @@ tap.test('deep equal failure', function (assert) { diag: { operator: 'notDeepEqual', expected: '{ b: 2 }', - actual: '{ b: 2 }' + actual: '{ b: 2 }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); @@ -111,8 +112,6 @@ tap.test('not deep equal failure, depth 6, with option', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -120,7 +119,10 @@ tap.test('not deep equal failure, depth 6, with option', function (assert) { diag: { operator: 'notDeepEqual', expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); @@ -172,8 +174,6 @@ tap.test('not deep equal failure, depth 6, without option', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -181,7 +181,10 @@ tap.test('not deep equal failure, depth 6, without option', function (assert) { diag: { operator: 'notDeepEqual', expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); diff --git a/test/not-equal-failure.js b/test/not-equal-failure.js index 4cf11f02..87a66453 100644 --- a/test/not-equal-failure.js +++ b/test/not-equal-failure.js @@ -48,8 +48,6 @@ tap.test('not equal failure', function (assert) { })); parser.once('assert', function (data) { - delete data.diag.stack; - delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -57,7 +55,10 @@ tap.test('not equal failure', function (assert) { diag: { operator: 'notEqual', expected: '2', - actual: '2' + actual: '2', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at } }); }); diff --git a/test/onFailure.js b/test/onFailure.js index 8420a822..5eb05142 100644 --- a/test/onFailure.js +++ b/test/onFailure.js @@ -3,8 +3,7 @@ var tap = require('tap'); var tape = require('../').createHarness(); -//Because this test passing depends on a failure, -//we must direct the failing output of the inner test +// 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, diff --git a/test/stackTrace.js b/test/stackTrace.js index e517077a..99afa1bf 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -15,14 +15,14 @@ tap.test('preserves stack trace with newlines', function (tt) { var stackTrace = 'foo\n bar'; parser.once('assert', function (data) { - delete data.diag.at; tt.deepEqual(data, { ok: false, id: 1, name: 'Error: Preserve stack', diag: { stack: stackTrace, - operator: 'error' + operator: 'error', + at: data.diag.at // we don't care about this one } }); }); @@ -292,8 +292,7 @@ function getDiag(body) { return line.slice(2); }).join('\n'); - // Get rid of 'at' variable (which has a line number / path of its own that's - // difficult to check). + // Get rid of 'at' variable (which has a line number / path of its own that's difficult to check). var withStack = yaml.safeLoad(diag); delete withStack.at; return withStack;