Skip to content

Commit 18e1118

Browse files
committed
Set false to semi
1 parent 02fde71 commit 18e1118

File tree

8 files changed

+69
-69
lines changed

8 files changed

+69
-69
lines changed

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"printWidth": 80,
33
"tabWidth": 2,
44
"useTabs": false,
5-
"semi": true,
5+
"semi": false,
66
"singleQuote": true,
77
"trailingComma": "none",
88
"bracketSpacing": true,

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ module.exports = {
77
transform: {
88
'^.+\\.(ts|tsx)$': 'ts-jest'
99
}
10-
};
10+
}

src/cli.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import { Writable } from 'stream';
2-
import countChars from './count';
1+
import { Writable } from 'stream'
2+
import countChars from './count'
33

44
type Opts = {
5-
filenames: string[];
6-
stdout: Writable;
7-
stderr: Writable;
8-
};
5+
filenames: string[]
6+
stdout: Writable
7+
stderr: Writable
8+
}
99
const cli = async ({ filenames, stdout, stderr }: Opts): Promise<number> => {
1010
try {
11-
const len = filenames.length;
11+
const len = filenames.length
1212
for (let i = 0; i < len; i++) {
13-
const filename = filenames[i];
14-
const count = await countChars(filename);
15-
stdout.write(`${filename}: ${count} chars\n`);
13+
const filename = filenames[i]
14+
const count = await countChars(filename)
15+
stdout.write(`${filename}: ${count} chars\n`)
1616
}
1717
} catch (err: any) {
18-
stderr.write(err.toString());
19-
stderr.write('\n');
20-
return 1;
18+
stderr.write(err.toString())
19+
stderr.write('\n')
20+
return 1
2121
}
22-
return 0;
23-
};
22+
return 0
23+
}
2424

25-
export default cli;
25+
export default cli

src/count.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import * as fs from 'fs';
1+
import * as fs from 'fs'
22

33
const countChars = async (fileName: string): Promise<number> => {
44
return new Promise((resolve, reject) => {
55
fs.readFile(fileName, (err, data) => {
66
if (err) {
7-
reject(err);
8-
return;
7+
reject(err)
8+
return
99
}
10-
resolve(data.toString('utf-8').length);
11-
});
12-
});
13-
};
14-
export default countChars;
10+
resolve(data.toString('utf-8').length)
11+
})
12+
})
13+
}
14+
export default countChars

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import countChars from './count';
2-
export { countChars };
1+
import countChars from './count'
2+
export { countChars }

src/main.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#!/usr/bin/env node
2-
import yargs from 'yargs';
3-
import { hideBin } from 'yargs/helpers';
4-
import cli from './cli';
2+
import yargs from 'yargs'
3+
import { hideBin } from 'yargs/helpers'
4+
import cli from './cli'
55

6-
(async () => {
6+
;(async () => {
77
const argv = await yargs(hideBin(process.argv))
88
.scriptName('count')
99
.usage('$0 [FILE]...')
1010
.example('$0 foo.ts bar.ts', 'count chars in files')
1111
.demand(1)
12-
.help().argv;
12+
.help().argv
1313

1414
process.exit(
1515
await cli({
1616
filenames: argv._ as string[],
1717
stdout: process.stdout,
1818
stderr: process.stderr
1919
})
20-
);
21-
})();
20+
)
21+
})()

test/cli.spec.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
import { PassThrough } from 'stream';
2-
import cli from '../src/cli';
1+
import { PassThrough } from 'stream'
2+
import cli from '../src/cli'
33

44
describe('cli()', () => {
55
it('should return stdout with exitcode=0', async () => {
6-
const stdout = new PassThrough();
7-
const stderr = new PassThrough();
8-
const outData = jest.fn();
9-
stdout.on('data', outData);
10-
const errData = jest.fn();
11-
stderr.on('data', errData);
6+
const stdout = new PassThrough()
7+
const stderr = new PassThrough()
8+
const outData = jest.fn()
9+
stdout.on('data', outData)
10+
const errData = jest.fn()
11+
stderr.on('data', errData)
1212
expect(
1313
await cli({
1414
filenames: ['test/assets/test1.txt', 'test/assets/test2.txt'],
1515
stdout,
1616
stderr
1717
})
18-
).toEqual(0);
19-
expect(outData.mock.calls.length).toEqual(2);
18+
).toEqual(0)
19+
expect(outData.mock.calls.length).toEqual(2)
2020
expect(outData.mock.calls[0][0].toString('utf8')).toEqual(
2121
'test/assets/test1.txt: 15 chars\n'
22-
);
22+
)
2323
expect(outData.mock.calls[1][0].toString('utf8')).toEqual(
2424
'test/assets/test2.txt: 17 chars\n'
25-
);
26-
expect(errData.mock.calls.length).toEqual(0);
27-
});
25+
)
26+
expect(errData.mock.calls.length).toEqual(0)
27+
})
2828
it('should return stderr with exitcode=1', async () => {
29-
const stdout = new PassThrough();
30-
const stderr = new PassThrough();
31-
const outData = jest.fn();
32-
stdout.on('data', outData);
33-
const errData = jest.fn();
34-
stderr.on('data', errData);
29+
const stdout = new PassThrough()
30+
const stderr = new PassThrough()
31+
const outData = jest.fn()
32+
stdout.on('data', outData)
33+
const errData = jest.fn()
34+
stderr.on('data', errData)
3535
expect(
3636
await cli({
3737
filenames: ['test/assets/test1.txt', 'test/assets/fail.txt'],
3838
stdout,
3939
stderr
4040
})
41-
).toEqual(1);
42-
expect(outData.mock.calls.length).toEqual(1);
41+
).toEqual(1)
42+
expect(outData.mock.calls.length).toEqual(1)
4343
expect(outData.mock.calls[0][0].toString('utf8')).toEqual(
4444
'test/assets/test1.txt: 15 chars\n'
45-
);
46-
expect(errData.mock.calls.length).toEqual(2);
45+
)
46+
expect(errData.mock.calls.length).toEqual(2)
4747
expect(errData.mock.calls[0][0].toString('utf8')).toEqual(
4848
"Error: ENOENT: no such file or directory, open 'test/assets/fail.txt'"
49-
);
50-
expect(errData.mock.calls[1][0].toString('utf8')).toEqual('\n');
51-
});
52-
});
49+
)
50+
expect(errData.mock.calls[1][0].toString('utf8')).toEqual('\n')
51+
})
52+
})

test/count.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import countChars from '../src/count';
1+
import countChars from '../src/count'
22

33
describe('countChars()', () => {
44
it('should return count of content', async () => {
5-
expect(await countChars('test/assets/test1.txt')).toEqual(15);
6-
});
5+
expect(await countChars('test/assets/test1.txt')).toEqual(15)
6+
})
77
it('should reject when file not found', async () => {
8-
await expect(countChars('test/assets/fail.txt')).rejects.toThrow('ENOENT:');
9-
});
10-
});
8+
await expect(countChars('test/assets/fail.txt')).rejects.toThrow('ENOENT:')
9+
})
10+
})

0 commit comments

Comments
 (0)