Skip to content

Commit b1f3f11

Browse files
Added logger and --quiet and --debug flags to CLI.
1 parent acae4c9 commit b1f3f11

27 files changed

Lines changed: 582 additions & 102 deletions

.pre-commit-hooks.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
- id: snippet-fmt
22
name: Format snippet files
3-
entry: snippet-fmt
3+
entry: snippet-fmt --quiet
44
language: node
55
files: \.snippet$
66

77
- id: talon-fmt
88
name: Format Talon files
9-
entry: talon-fmt
9+
entry: talon-fmt --quiet
1010
language: node
1111
files: \.(talon|talon-list)$
1212

1313
- id: tree-sitter-fmt
1414
name: Format Tree-sitter query files
15-
entry: tree-sitter-fmt
15+
entry: tree-sitter-fmt --quiet
1616
language: node
1717
files: \.scm$

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ All binaries support these options:
1818
| ----------- | -------------------------------- |
1919
| `--help` | Show help |
2020
| `--version` | Show version |
21+
| `--quiet` | Suppress non-error output |
2122
| `--check` | Check formatting without writing |
23+
| `--debug` | Print debug output |
24+
25+
Use `--debug` when diagnosing parser or formatter support for new syntax.
2226

2327
## Formatting options
2428

out/cli/cli.d.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
import type { Readable } from "node:stream";
2-
import type { CLI } from "../types.js";
2+
import type { CLI, Logger } from "../types.js";
33
export declare function main(cli: CLI): Promise<void>;
4-
export declare function formatFiles(cli: CLI, check: boolean, filePaths: string[]): Promise<number>;
5-
export declare function formatFile(cli: CLI, check: boolean, filePath: string): Promise<boolean>;
6-
export declare function mainFormatStdin(cli: CLI, stdin: Readable, check: boolean): Promise<number>;
4+
interface FormatFilesArgs {
5+
cli: CLI;
6+
logger: Logger;
7+
check: boolean;
8+
debug: boolean;
9+
filePaths: string[];
10+
}
11+
export declare function formatFiles({ cli, logger, check, debug, filePaths, }: FormatFilesArgs): Promise<number>;
12+
interface FormatFileArgs {
13+
cli: CLI;
14+
logger: Logger;
15+
check: boolean;
16+
debug: boolean;
17+
filePath: string;
18+
}
19+
export declare function formatFile({ cli, logger, check, debug, filePath, }: FormatFileArgs): Promise<boolean>;
20+
interface MainFormatStdinArgs {
21+
cli: CLI;
22+
logger: Logger;
23+
stdin: Readable;
24+
check: boolean;
25+
debug: boolean;
26+
}
27+
export declare function mainFormatStdin({ cli, logger, stdin, check, debug, }: MainFormatStdinArgs): Promise<number>;
28+
export {};

out/lib.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/snippetFormatter.js

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/talon/talonFormatter.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import type { FormatterOptions, SyntaxNode } from "../types.js";
22
type Options = FormatterOptions<"endOfLine" | "indentTabs" | "indentSize" | "maxLineLength" | "columnWidth" | "insertFinalNewline" | "preserveMultiline">;
3-
export declare function talonFormatter(node: SyntaxNode, options?: Options): string;
3+
export declare function talonFormatter(node: SyntaxNode, options?: Options, debug?: boolean): string;
44
export {};

out/talonFormatter.js

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/treeSitterFormatter.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import type { FormatterOptions, SyntaxNode } from "./types.js";
22
type Options = FormatterOptions<"endOfLine" | "indentTabs" | "indentSize" | "insertFinalNewline">;
3-
export declare function treeSitterFormatter(node: SyntaxNode, options?: Options): string;
3+
export declare function treeSitterFormatter(node: SyntaxNode, options?: Options, debug?: boolean): string;
44
export {};

out/treeSitterFormatter.js

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/types.d.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { KnownProps } from "editorconfig";
2-
export declare const KNOWN_ARGUMENTS: readonly ["--help", "--version", "--check"];
2+
export declare const KNOWN_ARGUMENTS: readonly ["--help", "--version", "--quiet", "--check", "--debug"];
33
export type KnownArgument = (typeof KNOWN_ARGUMENTS)[number];
44
export interface CLI {
55
binName: "snippet-fmt" | "talon-fmt" | "tree-sitter-fmt";
66
fileEndings: readonly string[];
77
getStdinFileEnding(text: string): string;
8-
format(text: string, options: Options, filePath: string): Promise<string>;
8+
format(text: string, options: Options, filePath: string, debug: boolean): Promise<string>;
99
}
1010
export type EndOfLine = "lf" | "crlf";
1111
export interface Options {
@@ -23,6 +23,21 @@ export interface ParsedArgs {
2323
help: boolean;
2424
version: boolean;
2525
check: boolean;
26+
quiet: boolean;
27+
debug: boolean;
28+
}
29+
export interface LoggerEntry {
30+
level: "log" | "warn" | "error";
31+
message: string;
32+
}
33+
export interface Logger {
34+
log(message: string): void;
35+
warn(message: string): void;
36+
error(message: string): void;
37+
getEntries(): readonly LoggerEntry[];
38+
}
39+
export interface DebugLogger {
40+
debug(message: string): void;
2641
}
2742
export interface EditorConfigOptions extends KnownProps {
2843
max_line_length?: number | "unset";

0 commit comments

Comments
 (0)