Fix functions coding style (#296)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by Sindre Sorhus · parent ab83d8d · Browse files · 2 files·+52 added−52 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+52 added−52 removed
- tests:+10 added−10 removed
- other:+42 added−42 removed
Provenance
- Commit
0d4a97a- Tree
44e917d- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
ab83d8d
2 files changed+52 added−52 removed
modified:test/test.js+10 added-10 removed
485 unmodified lines486 const {signal} = await t.throwsAsync(execa('exit', [2]), {message: getExitRegExp('2')});487 t.is(signal, undefined);488 });489 490-async function testExitCode(t, num) {490+const testExitCode = async (t, num) => {491 const {exitCode} = await t.throwsAsync(execa('exit', [`${num}`]), {message: getExitRegExp(num)});492 t.is(exitCode, num);493-}493+};494 495 test('error.exitCode is 2', testExitCode, 2);496 test('error.exitCode is 3', testExitCode, 3);497 test('error.exitCode is 4', testExitCode, 4);26 unmodified lines524 const {timedOut} = execa.sync('noop');525 t.false(timedOut);526 });527 528-async function errorMessage(t, expected, ...args) {528+const errorMessage = async (t, expected, ...args) => {529 await t.throwsAsync(execa('exit', args), {message: expected});530-}530+};531 532 errorMessage.title = (message, expected) => `error.message matches: ${expected}`;533 534 test(errorMessage, /Command failed with exit code 2.*: exit 2 foo bar/, 2, 'foo', 'bar');535 test(errorMessage, /Command failed with exit code 3.*: exit 3 baz quz/, 3, 'baz', 'quz');536 537-async function command(t, expected, ...args) {537+const command = async (t, expected, ...args) => {538 const {command: failCommand} = await t.throwsAsync(execa('fail', args));539 t.is(failCommand, `fail${expected}`);540 541 const {command} = await execa('noop', args);542 t.is(command, `noop${expected}`);543-}543+};544 545 command.title = (message, expected) => `command is: ${JSON.stringify(expected)}`;546 547 test(command, ' foo bar', 'foo', 'bar');548 test(command, ' baz quz', 'baz', 'quz');549 test(command, '');550 551 // When child process exits before parent process552-async function spawnAndExit(t, cleanup, detached) {552+const spawnAndExit = async (t, cleanup, detached) => {553 await t.notThrowsAsync(execa('sub-process-exit', [cleanup, detached]));554-}554+};555 556 test('spawnAndExit', spawnAndExit, false, false);557 test('spawnAndExit cleanup', spawnAndExit, true, false);558 test('spawnAndExit detached', spawnAndExit, false, true);559 test('spawnAndExit cleanup detached', spawnAndExit, true, true);560 561 // When parent process exits before child process562-async function spawnAndKill(t, signal, cleanup, detached, isKilled) {562+const spawnAndKill = async (t, signal, cleanup, detached, isKilled) => {563 const subprocess = execa('sub-process', [cleanup, detached], {stdio: ['ignore', 'ignore', 'ignore', 'ipc']});564 565 const pid = await pEvent(subprocess, 'message');566 t.true(Number.isInteger(pid));8 unmodified lines575 576 if (!isKilled) {577 process.kill(pid, 'SIGKILL');578 }579-}579+};580 581 // Without `options.cleanup`:582 // - on Windows subprocesses are killed if `options.detached: false`, but not583 // if `options.detached: true`254 unmodified linesmodified:index.js+42 added-42 removed
16 unmodified lines17 const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;18 19 const SPACES_REGEXP = / +/g;20 21-function handleArgs(file, args, options = {}) {21+const handleArgs = (file, args, options = {}) => {22 const parsed = crossSpawn._parse(file, args, options);23 file = parsed.command;24 args = parsed.args;25 options = parsed.options;32 unmodified lines58 args.unshift('/q');59 }60 61 return {file, args, options, parsed};62-}62+};63 64-function handleInput(spawned, input) {64+const handleInput = (spawned, input) => {65 // Checking for stdin is workaround for https://github.com/nodejs/node/issues/2685266 // TODO: Remove `|| spawned.stdin === undefined` once we drop support for Node.js <=12.2.067 if (input === undefined || spawned.stdin === undefined) {68 return;3 unmodified lines72 input.pipe(spawned.stdin);73 } else {74 spawned.stdin.end(input);75 }76-}76+};77 78-function handleOutput(options, value, error) {78+const handleOutput = (options, value, error) => {79 if (typeof value !== 'string' && !Buffer.isBuffer(value)) {80 // When `execa.sync()` errors, we normalize it to '' to mimic `execa()`81 return error === undefined ? undefined : '';82 }2 unmodified lines85 return stripFinalNewline(value);86 }87 88 return value;89-}89+};90 91-function makeAllStream(spawned) {91+const makeAllStream = spawned => {92 if (!spawned.stdout && !spawned.stderr) {93 return;94 }95 7 unmodified lines103 mixed.add(spawned.stderr);104 }105 106 return mixed;107-}107+};108 109-async function getBufferedData(stream, streamPromise) {109+const getBufferedData = async (stream, streamPromise) => {110 if (!stream) {111 return;112 }113 3 unmodified lines117 return await streamPromise;118 } catch (error) {119 return error.bufferedData;120 }121-}121+};122 123-function getStreamPromise(stream, {encoding, buffer, maxBuffer}) {123+const getStreamPromise = (stream, {encoding, buffer, maxBuffer}) => {124 if (!stream) {125 return;126 }127 10 unmodified lines138 return getStream(stream, {encoding, maxBuffer});139 }140 141 return getStream.buffer(stream, {maxBuffer});142-}142+};143 144-async function getPromiseResult({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) {144+const getPromiseResult = async ({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) => {145 const stdoutPromise = getStreamPromise(stdout, {encoding, buffer, maxBuffer});146 const stderrPromise = getStreamPromise(stderr, {encoding, buffer, maxBuffer});147 const allPromise = getStreamPromise(all, {encoding, buffer, maxBuffer: maxBuffer * 2});148 6 unmodified lines155 getBufferedData(stderr, stderrPromise),156 getBufferedData(all, allPromise)157 ]);158 }159-}159+};160 161-function makeError(result, options) {161+const makeError = (result, options) => {162 const {stdout, stderr, signal} = result;163 let {error} = result;164 const {code, command, timedOut, isCanceled, killed, parsed: {options: {timeout}}} = options;165 31 unmodified lines197 // it to `undefined`198 error.signal = signal || undefined;199 200 return error;201-}201+};202 203-function getCode({error = {}}, code) {203+const getCode = ({error = {}}, code) => {204 if (error.code) {205 return [error.code, os.constants.errno[error.code]];206 }207 1 unmodified line209 return [util.getSystemErrorName(-code), code];210 }211 212 return [];213-}213+};214 215-function getErrorPrefix({timedOut, timeout, signal, exitCodeName, exitCode, isCanceled}) {215+const getErrorPrefix = ({timedOut, timeout, signal, exitCodeName, exitCode, isCanceled}) => {216 if (timedOut) {217 return `timed out after ${timeout} milliseconds`;218 }219 9 unmodified lines229 return `failed with exit code ${exitCode} (${exitCodeName})`;230 }231 232 return 'failed';233-}233+};234 235-function joinCommand(file, args = []) {235+const joinCommand = (file, args = []) => {236 if (!Array.isArray(args)) {237 return file;238 }239 240 return [file, ...args].join(' ');241-}241+};242 243-function mergePromiseProperty(spawned, getPromise, property) {243+const mergePromiseProperty = (spawned, getPromise, property) => {244 Object.defineProperty(spawned, property, {245 value(...args) {246 return getPromise()[property](...args);247 },248 writable: true,249 enumerable: false,250 configurable: true251 });252-}252+};253 254 // The return value is a mixin of `childProcess` and `Promise`255-function mergePromise(spawned, getPromise) {255+const mergePromise = (spawned, getPromise) => {256 mergePromiseProperty(spawned, getPromise, 'then');257 mergePromiseProperty(spawned, getPromise, 'catch');258 259 // TODO: Remove the `if`-guard when targeting Node.js 101 unmodified line261 mergePromiseProperty(spawned, getPromise, 'finally');262 }263 264 return spawned;265-}265+};266 267-function spawnedKill(kill, signal = 'SIGTERM', options = {}) {267+const spawnedKill = (kill, signal = 'SIGTERM', options = {}) => {268 const killResult = kill(signal);269 setKillTimeout(kill, signal, options, killResult);270 return killResult;271-}271+};272 273-function setKillTimeout(kill, signal, options, killResult) {273+const setKillTimeout = (kill, signal, options, killResult) => {274 if (!shouldForceKill(signal, options, killResult)) {275 return;276 }277 278 const timeout = getForceKillAfterTimeout(options);279 setTimeout(() => {280 kill('SIGKILL');281 }, timeout).unref();282-}282+};283 284-function shouldForceKill(signal, {forceKillAfterTimeout}, killResult) {284+const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => {285 return isSigterm(signal) && forceKillAfterTimeout !== false && killResult;286-}286+};287 288-function isSigterm(signal) {288+const isSigterm = signal => {289 return signal === os.constants.signals.SIGTERM ||290 (typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');291-}291+};292 293-function getForceKillAfterTimeout({forceKillAfterTimeout = true}) {293+const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => {294 if (forceKillAfterTimeout === true) {295 return DEFAULT_FORCE_KILL_TIMEOUT;296 }297 1 unmodified line299 throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`);300 }301 302 return forceKillAfterTimeout;303-}303+};304 305-function handleSpawned(spawned, context) {305+const handleSpawned = (spawned, context) => {306 return new Promise((resolve, reject) => {307 spawned.on('exit', (code, signal) => {308 if (context.timedOut) {309 reject(Object.assign(new Error('Timed out'), {code, signal}));12 unmodified lines322 reject(error);323 });324 }325 });326-}326+};327 328 const setupTimeout = (spawned, {timeout, killSignal}, context) => {329 if (timeout > 0) {330 context.timeoutId = setTimeout(() => {160 unmodified lines491 };492 };493 494 // Allow spaces to be escaped by a backslash if not meant as a delimiter495-function handleEscaping(tokens, token, index) {495+const handleEscaping = (tokens, token, index) => {496 if (index === 0) {497 return [token];498 }499 3 unmodified lines503 return [...tokens.slice(0, -1), `${previousToken.slice(0, -1)} ${token}`];504 }505 506 return [...tokens, token];507-}507+};508 509-function parseCommand(command) {509+const parseCommand = command => {510 return command511 .trim()512 .split(SPACES_REGEXP)513 .reduce(handleEscaping, []);514-}514+};515 516 module.exports.command = (command, options) => {517 const [file, ...args] = parseCommand(command);518 return execa(file, args, options);33 unmodified lines