Skip to content

Commit

Permalink
[eslint] fully enable @ljharb eslint config
Browse files Browse the repository at this point in the history
It’s time.
  • Loading branch information
ljharb committed Jul 24, 2021
1 parent fb4e3cf commit ae8b5c0
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 104 deletions.
151 changes: 84 additions & 67 deletions .eslintrc
Expand Up @@ -4,92 +4,78 @@
"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": [
{
"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": {
Expand All @@ -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",
},
},
],
}
8 changes: 5 additions & 3 deletions index.js
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/default_stream.js
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/results.js
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions lib/test.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -131,6 +132,7 @@ Test.prototype.run = function run() {
}
self.end();
});
// eslint-disable-next-line consistent-return
return;
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/async-await.js
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions test/async-await/async-error.js
Expand Up @@ -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');
});
1 change: 1 addition & 0 deletions test/async-await/sync-error.js
Expand Up @@ -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();
});
21 changes: 12 additions & 9 deletions test/deep-equal-failure.js
Expand Up @@ -50,16 +50,17 @@ 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,
name: 'should be strictly equal',
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
}
});
});
Expand Down Expand Up @@ -111,16 +112,17 @@ 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,
name: 'should be strictly equal',
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
}
});
});
Expand Down Expand Up @@ -172,16 +174,17 @@ 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,
name: 'should be strictly equal',
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
}
});
});
Expand Down
4 changes: 1 addition & 3 deletions test/import.js
Expand Up @@ -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));
}
5 changes: 4 additions & 1 deletion test/max_listeners/source.js
Expand Up @@ -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();
});
}

0 comments on commit ae8b5c0

Please sign in to comment.