Skip to content

Commit 970b8a5

Browse files
Remove default value for check argument
1 parent 46d20a0 commit 970b8a5

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
out
3+
.tmp-test

src/cli/cli.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async function mainUnsafe(cli: CLI): Promise<number> {
4242
// If no file patterns are provided, check if there's input from stdin.
4343
// If stdin TTY it's an interactive terminal, so we shouldn't read from it.
4444
if (!process.stdin.isTTY) {
45-
return mainFormatStdin(cli, args.check);
45+
return mainFormatStdin(cli, process.stdin, args.check);
4646
}
4747

4848
throw new Error(
@@ -53,7 +53,7 @@ async function mainUnsafe(cli: CLI): Promise<number> {
5353
async function mainFormatFiles(
5454
cli: CLI,
5555
filePatterns: string[],
56-
check: boolean = false,
56+
check: boolean,
5757
): Promise<number> {
5858
if (check) {
5959
console.log("Checking formatting...");
@@ -85,7 +85,7 @@ async function mainFormatFiles(
8585
export async function formatFiles(
8686
cli: CLI,
8787
filePatterns: string[],
88-
check: boolean = false,
88+
check: boolean,
8989
): Promise<number> {
9090
let changedFileCount = 0;
9191

@@ -101,7 +101,7 @@ export async function formatFiles(
101101
export async function formatFile(
102102
cli: CLI,
103103
fileName: string,
104-
check: boolean = false,
104+
check: boolean,
105105
): Promise<boolean> {
106106
try {
107107
const content = await fs.readFile(fileName, "utf8");
@@ -135,8 +135,8 @@ export async function formatFile(
135135

136136
export async function mainFormatStdin(
137137
cli: CLI,
138+
stdin: Readable,
138139
check: boolean,
139-
stdin: Readable = process.stdin,
140140
): Promise<number> {
141141
const input = await getStdin({ stdin });
142142
const formatted = await cli.format(input, "stdin");

src/test/cli.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ suite("CLI", () => {
1818
const cli = createCLI((text) => `${text} updated`);
1919

2020
try {
21-
const didChange = await formatFile(cli, fileName);
21+
const didChange = await formatFile(cli, fileName, false);
2222
const actual = await fs.readFile(fileName, "utf8");
2323

2424
assert.equal(didChange, true);
@@ -59,10 +59,11 @@ suite("CLI", () => {
5959
await fs.writeFile(unchangedFileName, "unchanged", "utf8");
6060
await fs.writeFile(changedFileName, "changed", "utf8");
6161

62-
const changedFileCount = await formatFiles(cli, [
63-
unchangedFileName,
64-
changedFileName,
65-
]);
62+
const changedFileCount = await formatFiles(
63+
cli,
64+
[unchangedFileName, changedFileName],
65+
false,
66+
);
6667
const unchangedContent = await fs.readFile(
6768
unchangedFileName,
6869
"utf8",
@@ -81,7 +82,7 @@ suite("CLI", () => {
8182
const fileName = path.join(os.tmpdir(), "talonfmt-missing.txt");
8283
const cli = createCLI((text) => `${text} updated`);
8384

84-
const didChange = await formatFile(cli, fileName);
85+
const didChange = await formatFile(cli, fileName, false);
8586

8687
assert.equal(didChange, false);
8788
});
@@ -98,7 +99,7 @@ suite("CLI", () => {
9899

99100
try {
100101
await assert.rejects(
101-
formatFile(cli, fileName),
102+
formatFile(cli, fileName, false),
102103
/Failed to format '.*example\.txt': boom/,
103104
);
104105
} finally {
@@ -203,7 +204,7 @@ async function readAndFormatStdin(
203204
): Promise<number> {
204205
const stdin = new PassThrough();
205206
Object.defineProperty(stdin, "isTTY", { value: false });
206-
const result = mainFormatStdin(cli, check, stdin);
207+
const result = mainFormatStdin(cli, stdin, check);
207208
stdin.end(input);
208209
return result;
209210
}

0 commit comments

Comments
 (0)