Skip to content

Commit

Permalink
[eslint] fix indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Sep 18, 2022
1 parent a9ae3c2 commit 2151e06
Show file tree
Hide file tree
Showing 131 changed files with 5,861 additions and 5,862 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Expand Up @@ -13,7 +13,6 @@
"array-bracket-spacing": "off",
"complexity": "off",
"func-style": "warn",
"indent": ["error", 4],
"no-magic-numbers": "off",
"max-lines": "warn",
"max-lines-per-function": "warn",
Expand Down
10 changes: 5 additions & 5 deletions bin/import-or-require.js
Expand Up @@ -6,10 +6,10 @@ const getPackageType = require('get-package-type');

// eslint-disable-next-line consistent-return
module.exports = function importOrRequire(file) {
const ext = extnamePath(file);
const ext = extnamePath(file);

if (ext === '.mjs' || (ext === '.js' && getPackageType.sync(file) === 'module')) {
return import(pathToFileURL(file).href);
}
require(file);
if (ext === '.mjs' || (ext === '.js' && getPackageType.sync(file) === 'module')) {
return import(pathToFileURL(file).href);
}
require(file);
};
98 changes: 49 additions & 49 deletions bin/tape
Expand Up @@ -6,95 +6,95 @@ var parseOpts = require('minimist');
var objectKeys = require('object-keys');

var opts = parseOpts(process.argv.slice(2), {
alias: { r: 'require', i: 'ignore' },
string: ['require', 'ignore'],
boolean: ['only'],
default: { r: [], i: null, only: null }
alias: { r: 'require', i: 'ignore' },
string: ['require', 'ignore'],
boolean: ['only'],
default: { r: [], i: null, only: null }
});

if (typeof opts.only === 'boolean') {
process.env.NODE_TAPE_NO_ONLY_TEST = !opts.only;
process.env.NODE_TAPE_NO_ONLY_TEST = !opts.only;
}

var cwd = process.cwd();

if (typeof opts.require === 'string') {
opts.require = [opts.require];
opts.require = [opts.require];
}

var resolveModule;
opts.require.forEach(function (module) {
var options = { basedir: cwd, extensions: objectKeys(require.extensions) };
if (module) {
if (!resolveModule) { resolveModule = require('resolve').sync; }
// This check ensures we ignore `-r ""`, trailing `-r`, or other silly things the user might (inadvertently) be doing.
require(resolveModule(module, options));
}
var options = { basedir: cwd, extensions: objectKeys(require.extensions) };
if (module) {
if (!resolveModule) { resolveModule = require('resolve').sync; }
// This check ensures we ignore `-r ""`, trailing `-r`, or other silly things the user might (inadvertently) be doing.
require(resolveModule(module, options));
}
});

var resolvePath = require('path').resolve;
var requireResolve = require.resolve;

var matcher;
if (typeof opts.ignore === 'string') {
var readFileSync = require('fs').readFileSync;
try {
var ignoreStr = readFileSync(resolvePath(cwd, opts.ignore || '.gitignore'), 'utf-8');
} catch (e) {
console.error(e.message);
process.exit(2);
}
var ignore = require('dotignore');
matcher = ignore.createMatcher(ignoreStr);
var readFileSync = require('fs').readFileSync;
try {
var ignoreStr = readFileSync(resolvePath(cwd, opts.ignore || '.gitignore'), 'utf-8');
} catch (e) {
console.error(e.message);
process.exit(2);
}
var ignore = require('dotignore');
matcher = ignore.createMatcher(ignoreStr);
}

var glob = require('glob');

var files = opts._.reduce(function (result, arg) {
if (glob.hasMagic(arg)) {
// If glob does not match, `files` will be an empty array.
// Note: `glob.sync` may throw an error and crash the node process.
var globFiles = glob.sync(arg);

if (!Array.isArray(globFiles)) {
throw new TypeError('unknown error: glob.sync("' + arg + '") did not return an array or throw. Please report this.');
}

return result.concat(globFiles);
}
return result.concat(arg);
if (glob.hasMagic(arg)) {
// If glob does not match, `files` will be an empty array.
// Note: `glob.sync` may throw an error and crash the node process.
var globFiles = glob.sync(arg);

if (!Array.isArray(globFiles)) {
throw new TypeError('unknown error: glob.sync("' + arg + '") did not return an array or throw. Please report this.');
}

return result.concat(globFiles);
}
return result.concat(arg);
}, []).filter(function (file) {
return !matcher || !matcher.shouldIgnore(file);
return !matcher || !matcher.shouldIgnore(file);
}).map(function (file) {
return requireResolve(resolvePath(cwd, file));
return requireResolve(resolvePath(cwd, file));
});

var hasImport = require('has-dynamic-import');

hasImport().then(function (hasSupport) {
// the nextTick callback gets called outside the promise chain, avoiding
// promises and unhandled rejections when only loading commonjs files
process.nextTick(importFiles, hasSupport);
// the nextTick callback gets called outside the promise chain, avoiding
// promises and unhandled rejections when only loading commonjs files
process.nextTick(importFiles, hasSupport);
});

var tape = require('../');

function importFiles(hasSupport) {
if (!hasSupport) {
return files.forEach(function (x) { require(x); });
}
if (!hasSupport) {
return files.forEach(function (x) { require(x); });
}

var importOrRequire = require('./import-or-require');
var importOrRequire = require('./import-or-require');

tape.wait();
tape.wait();

var filesPromise = files.reduce(function (promise, file) {
return promise ? promise.then(function () {
return importOrRequire(file);
}) : importOrRequire(file);
}, null);
var filesPromise = files.reduce(function (promise, file) {
return promise ? promise.then(function () {
return importOrRequire(file);
}) : importOrRequire(file);
}, null);

return filesPromise ? filesPromise.then(function () { tape.run(); }) : tape.run();
return filesPromise ? filesPromise.then(function () { tape.run(); }) : tape.run();
}

// vim: ft=javascript
52 changes: 26 additions & 26 deletions example/array.js
Expand Up @@ -4,34 +4,34 @@ var falafel = require('falafel');
var test = require('../');

test('array', function (t) {
t.plan(5);
t.plan(5);

var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';
var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';

var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});

var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[ 1, 2, [3, 4]], [5, 6]]
];
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[ 1, 2, [3, 4]], [5, 6]]
];

Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
}
);
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
}
);
});
52 changes: 26 additions & 26 deletions example/fail.js
Expand Up @@ -4,34 +4,34 @@ var falafel = require('falafel');
var test = require('../');

test('array', function (t) {
t.plan(5);
t.plan(5);

var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';
var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';

var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});

var arrays = [
[ 3, 4 ],
[ 1, 2, [ 3, 4 ] ],
[ 5, 6 ],
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]
];
var arrays = [
[ 3, 4 ],
[ 1, 2, [ 3, 4 ] ],
[ 5, 6 ],
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]
];

Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]);
}
);
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]);
}
);
});
86 changes: 43 additions & 43 deletions example/nested.js
Expand Up @@ -4,50 +4,50 @@ var falafel = require('falafel');
var test = require('../');

test('nested array test', function (t) {
t.plan(6);

var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([ xs, ys ]);
} + ')()';

var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});

t.test('inside test', function (q) {
q.plan(2);
q.ok(true, 'inside ok');

setTimeout(function () {
q.ok(true, 'inside delayed');
}, 3000);
});

var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];

Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
t.plan(6);

var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([ xs, ys ]);
} + ')()';

var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});

t.test('inside test', function (q) {
q.plan(2);
q.ok(true, 'inside ok');

setTimeout(function () {
q.ok(true, 'inside delayed');
}, 3000);
});

var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];

Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
});

test('another', function (t) {
t.plan(1);
setTimeout(function () {
t.ok(true);
}, 100);
t.plan(1);
setTimeout(function () {
t.ok(true);
}, 100);
});

0 comments on commit 2151e06

Please sign in to comment.