Skip to content

Commit

Permalink
Enhance code formatting (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
paescuj authored Aug 11, 2022
1 parent 0c3c6e8 commit f275bd2
Show file tree
Hide file tree
Showing 41 changed files with 1,433 additions and 100 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
"parserOptions": {
"ecmaVersion": 8
},
"plugins": ["@typescript-eslint", "prettier"],
"plugins": ["@typescript-eslint", "simple-import-sort", "import", "prettier"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",
"curly": "error",
"eqeqeq": ["error", "always", { "null": "ignore" }],
"no-var": "error",
Expand Down
3 changes: 1 addition & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"singleQuote": true,
"arrowParens": "avoid"
"singleQuote": true
}
52 changes: 26 additions & 26 deletions bin/concurrently.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as readline from 'readline';
import { escapeRegExp } from 'lodash';
import * as Rx from 'rxjs';
import { map } from 'rxjs/operators';
import { spawn } from 'child_process';
import { subscribeSpyTo } from '@hirez_io/observer-spy';
import stringArgv from 'string-argv';
import { spawn } from 'child_process';
import { build } from 'esbuild';
import fs from 'fs';
import { escapeRegExp } from 'lodash';
import os from 'os';
import path from 'path';
import * as readline from 'readline';
import * as Rx from 'rxjs';
import { map } from 'rxjs/operators';
import stringArgv from 'string-argv';

const isWindows = process.platform === 'win32';
const createKillMessage = (prefix: string) =>
Expand Down Expand Up @@ -59,12 +59,12 @@ const run = (args: string) => {
output: null,
});

const log = new Rx.Observable<string>(observer => {
stdout.on('line', line => {
const log = new Rx.Observable<string>((observer) => {
stdout.on('line', (line) => {
observer.next(line);
});

stderr.on('line', line => {
stderr.on('line', (line) => {
observer.next(line);
});

Expand Down Expand Up @@ -109,7 +109,7 @@ it('has help command', async () => {
});

describe('has version command', () => {
it.each(['--version', '-V', '-v'])('%s', async arg => {
it.each(['--version', '-V', '-v'])('%s', async (arg) => {
const exit = await run(arg).exit;

expect(exit.code).toBe(0);
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('exiting conditions', () => {
});

describe('is of success when --success=last and last command to exit succeeds', () => {
it.each(['--success=last', '-s last'])('%s', async arg => {
it.each(['--success=last', '-s last'])('%s', async (arg) => {
const exit = await run(`${arg} "exit 1" "node fixtures/sleep.mjs 0.5 && echo foo"`)
.exit;

Expand All @@ -162,7 +162,7 @@ describe('exiting conditions', () => {
it('is of success when a SIGINT is sent', async () => {
const child = run('"node fixtures/read-echo.js"');
// Wait for command to have started before sending SIGINT
child.log.subscribe(line => {
child.log.subscribe((line) => {
if (/READING/.test(line)) {
process.kill(child.pid, 'SIGINT');
}
Expand All @@ -177,7 +177,7 @@ describe('exiting conditions', () => {
});

describe('does not log any extra output', () => {
it.each(['--raw', '-r'])('%s', async arg => {
it.each(['--raw', '-r'])('%s', async (arg) => {
const lines = await run(`${arg} "echo foo" "echo bar"`).getLogLines();

expect(lines).toHaveLength(2);
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('--group', () => {

describe('--names', () => {
describe('prefixes with names', () => {
it.each(['--names', '-n'])('%s', async arg => {
it.each(['--names', '-n'])('%s', async (arg) => {
const lines = await run(`${arg} foo,bar "echo foo" "echo bar"`).getLogLines();

expect(lines).toContainEqual(expect.stringContaining('[foo] foo'));
Expand All @@ -238,7 +238,7 @@ describe('--names', () => {
});

describe('specifies custom prefix', () => {
it.each(['--prefix', '-p'])('%s', async arg => {
it.each(['--prefix', '-p'])('%s', async (arg) => {
const lines = await run(`${arg} command "echo foo" "echo bar"`).getLogLines();

expect(lines).toContainEqual(expect.stringContaining('[echo foo] foo'));
Expand All @@ -247,7 +247,7 @@ describe('specifies custom prefix', () => {
});

describe('specifies custom prefix length', () => {
it.each(['--prefix command --prefix-length 5', '-p command -l 5'])('%s', async arg => {
it.each(['--prefix command --prefix-length 5', '-p command -l 5'])('%s', async (arg) => {
const lines = await run(`${arg} "echo foo" "echo bar"`).getLogLines();

expect(lines).toContainEqual(expect.stringContaining('[ec..o] foo'));
Expand All @@ -269,7 +269,7 @@ describe('--restart-tries', () => {

describe('--kill-others', () => {
describe('kills on success', () => {
it.each(['--kill-others', '-k'])('%s', async arg => {
it.each(['--kill-others', '-k'])('%s', async (arg) => {
const lines = await run(`${arg} "node fixtures/sleep.mjs 10" "exit 0"`).getLogLines();

expect(lines).toContainEqual(expect.stringContaining('[1] exit 0 exited with code 0'));
Expand Down Expand Up @@ -322,9 +322,9 @@ describe('--kill-others-on-fail', () => {

describe('--handle-input', () => {
describe('forwards input to first process by default', () => {
it.each(['--handle-input', '-i'])('%s', async arg => {
it.each(['--handle-input', '-i'])('%s', async (arg) => {
const child = run(`${arg} "node fixtures/read-echo.js"`);
child.log.subscribe(line => {
child.log.subscribe((line) => {
if (/READING/.test(line)) {
child.stdin.write('stop\n');
}
Expand All @@ -344,7 +344,7 @@ describe('--handle-input', () => {
const child = run(
'-ki --default-input-target 1 "node fixtures/read-echo.js" "node fixtures/read-echo.js"'
);
child.log.subscribe(line => {
child.log.subscribe((line) => {
if (/\[1\] READING/.test(line)) {
child.stdin.write('stop\n');
}
Expand All @@ -361,7 +361,7 @@ describe('--handle-input', () => {

it('forwards input to specified process', async () => {
const child = run('-ki "node fixtures/read-echo.js" "node fixtures/read-echo.js"');
child.log.subscribe(line => {
child.log.subscribe((line) => {
if (/\[1\] READING/.test(line)) {
child.stdin.write('1:stop\n');
}
Expand Down Expand Up @@ -409,8 +409,8 @@ expect.extend({
const escapedCommand = escapeRegExp(command);

if (
!lines.some(line => line.match(processStartedMessageRegex(index, escapedCommand))) ||
!lines.some(line => line.match(processStoppedMessageRegex(index, escapedCommand)))
!lines.some((line) => line.match(processStartedMessageRegex(index, escapedCommand))) ||
!lines.some((line) => line.match(processStoppedMessageRegex(index, escapedCommand)))
) {
return {
message: () => 'Expected lines to have process start and stop messages',
Expand All @@ -429,9 +429,9 @@ expect.extend({
const tableBottomBorderRegex = /[]+/g;

if (
!lines.some(line => line.match(tableTopBorderRegex)) ||
!lines.some(line => line.match(tableHeaderRowRegex)) ||
!lines.some(line => line.match(tableBottomBorderRegex))
!lines.some((line) => line.match(tableTopBorderRegex)) ||
!lines.some((line) => line.match(tableHeaderRowRegex)) ||
!lines.some((line) => line.match(tableBottomBorderRegex))
) {
return {
message: () => 'Expected lines to have timings table',
Expand Down
3 changes: 2 additions & 1 deletion bin/concurrently.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env node
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

import * as defaults from '../src/defaults';
import concurrently from '../src/index';
import { epilogue } from './epilogue';

// Clean-up arguments (yargs expects only the arguments after the program name)
const cleanArgs = hideBin(process.argv);
// Find argument separator (double dash)
const argsSepIdx = cleanArgs.findIndex(arg => arg === '--');
const argsSepIdx = cleanArgs.findIndex((arg) => arg === '--');
// Arguments before separator
const argsBeforeSep = argsSepIdx >= 0 ? cleanArgs.slice(0, argsSepIdx) : cleanArgs;
// Arguments after separator
Expand Down
2 changes: 1 addition & 1 deletion bin/epilogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const examplesString = examples
` - ${description}`,
example
.split('\n')
.map(line => ` ${line}`)
.map((line) => ` ${line}`)
.join('\n'),
].join('\n\n')
)
Expand Down
2 changes: 1 addition & 1 deletion bin/fixtures/read-echo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
process.stdin.on('data', chunk => {
process.stdin.on('data', (chunk) => {
const line = chunk.toString().trim();
console.log(line);

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

// eslint-disable-next-line @typescript-eslint/no-var-requires
const concurrently = require('./dist/src/index.js');

module.exports = exports = concurrently.default;
Object.assign(exports, concurrently);
Loading

0 comments on commit f275bd2

Please sign in to comment.